Formatting C++ code using ClangFormat.

This commit is contained in:
ali.ibrahim 2016-10-14 11:50:47 +02:00
parent 9cc8bfae1c
commit 4347ce4a53
6 changed files with 93 additions and 150 deletions

View file

@ -15,9 +15,7 @@ Net::Net(v8::Isolate* isolate) {
Init(isolate); Init(isolate);
} }
Net::~Net() { Net::~Net() {}
}
// static // static
v8::Local<v8::Value> Net::Create(v8::Isolate* isolate) { v8::Local<v8::Value> Net::Create(v8::Isolate* isolate) {
@ -38,25 +36,24 @@ v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
return URLRequest::GetConstructor(isolate)->GetFunction(); return URLRequest::GetConstructor(isolate)->GetFunction();
} }
void Net::RequestGarbageCollectionForTesting() { void Net::RequestGarbageCollectionForTesting() {
isolate()->RequestGarbageCollectionForTesting( isolate()->RequestGarbageCollectionForTesting(
v8::Isolate::GarbageCollectionType::kFullGarbageCollection); v8::Isolate::GarbageCollectionType::kFullGarbageCollection);
} }
} // namespace api } // namespace api
} // namespace atom } // namespace atom
namespace { namespace {
using atom::api::Net; using atom::api::Net;
using atom::api::URLRequest; using atom::api::URLRequest;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused, void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context, void* priv) { v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New)); URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New));

View file

@ -19,6 +19,7 @@ class Net : public mate::EventEmitter<Net> {
v8::Local<v8::FunctionTemplate> prototype); v8::Local<v8::FunctionTemplate> prototype);
v8::Local<v8::Value> URLRequest(v8::Isolate* isolate); v8::Local<v8::Value> URLRequest(v8::Isolate* isolate);
protected: protected:
explicit Net(v8::Isolate* isolate); explicit Net(v8::Isolate* isolate);
~Net() override; ~Net() override;
@ -32,5 +33,4 @@ class Net : public mate::EventEmitter<Net> {
} // namespace atom } // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_NET_H_ #endif // ATOM_BROWSER_API_ATOM_API_NET_H_

View file

@ -2,9 +2,9 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "atom/browser/api/atom_api_url_request.h"
#include <string> #include <string>
#include "atom/browser/api/atom_api_session.h" #include "atom/browser/api/atom_api_session.h"
#include "atom/browser/api/atom_api_url_request.h"
#include "atom/browser/net/atom_url_request.h" #include "atom/browser/net/atom_url_request.h"
#include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/net_converter.h" #include "atom/common/native_mate_converters/net_converter.h"
@ -12,8 +12,6 @@
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
namespace mate { namespace mate {
template <> template <>
@ -21,13 +19,11 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
static v8::Local<v8::Value> ToV8( static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate, v8::Isolate* isolate,
scoped_refptr<const net::IOBufferWithSize> buffer) { scoped_refptr<const net::IOBufferWithSize> buffer) {
return node::Buffer::Copy(isolate, return node::Buffer::Copy(isolate, buffer->data(), buffer->size())
buffer->data(), .ToLocalChecked();
buffer->size()).ToLocalChecked();
} }
static bool FromV8( static bool FromV8(v8::Isolate* isolate,
v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
scoped_refptr<const net::IOBufferWithSize>* out) { scoped_refptr<const net::IOBufferWithSize>* out) {
auto size = node::Buffer::Length(val); auto size = node::Buffer::Length(val);
@ -65,16 +61,14 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
namespace atom { namespace atom {
namespace api { namespace api {
template <typename Flags> template <typename Flags>
URLRequest::StateBase<Flags>::StateBase(Flags initialState) URLRequest::StateBase<Flags>::StateBase(Flags initialState)
: state_(initialState) { : state_(initialState) {}
}
template <typename Flags> template <typename Flags>
void URLRequest::StateBase<Flags>::SetFlag(Flags flag) { void URLRequest::StateBase<Flags>::SetFlag(Flags flag) {
state_ = static_cast<Flags>(static_cast<int>(state_) | state_ =
static_cast<int>(flag)); static_cast<Flags>(static_cast<int>(state_) | static_cast<int>(flag));
} }
template <typename Flags> template <typename Flags>
@ -88,8 +82,7 @@ bool URLRequest::StateBase<Flags>::IsFlagSet(Flags flag) const {
} }
URLRequest::RequestState::RequestState() URLRequest::RequestState::RequestState()
: StateBase(RequestStateFlags::kNotStarted) { : StateBase(RequestStateFlags::kNotStarted) {}
}
bool URLRequest::RequestState::NotStarted() const { bool URLRequest::RequestState::NotStarted() const {
return *this == RequestStateFlags::kNotStarted; return *this == RequestStateFlags::kNotStarted;
@ -116,8 +109,7 @@ bool URLRequest::RequestState::Closed() const {
} }
URLRequest::ResponseState::ResponseState() URLRequest::ResponseState::ResponseState()
: StateBase(ResponseStateFlags::kNotStarted) { : StateBase(ResponseStateFlags::kNotStarted) {}
}
bool URLRequest::ResponseState::NotStarted() const { bool URLRequest::ResponseState::NotStarted() const {
return *this == ResponseStateFlags::kNotStarted; return *this == ResponseStateFlags::kNotStarted;
@ -131,7 +123,6 @@ bool URLRequest::ResponseState::Ended() const {
return IsFlagSet(ResponseStateFlags::kEnded); return IsFlagSet(ResponseStateFlags::kEnded);
} }
bool URLRequest::ResponseState::Failed() const { bool URLRequest::ResponseState::Failed() const {
return IsFlagSet(ResponseStateFlags::kFailed); return IsFlagSet(ResponseStateFlags::kFailed);
} }
@ -141,8 +132,7 @@ URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
InitWith(isolate, wrapper); InitWith(isolate, wrapper);
} }
URLRequest::~URLRequest() { URLRequest::~URLRequest() {}
}
// static // static
mate::WrappableBase* URLRequest::New(mate::Arguments* args) { mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
@ -161,8 +151,8 @@ mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
auto browser_context = session->browser_context(); auto browser_context = session->browser_context();
auto api_url_request = new URLRequest(args->isolate(), args->GetThis()); auto api_url_request = new URLRequest(args->isolate(), args->GetThis());
auto weak_ptr = api_url_request->weak_ptr_factory_.GetWeakPtr(); auto weak_ptr = api_url_request->weak_ptr_factory_.GetWeakPtr();
auto atom_url_request = AtomURLRequest::Create(browser_context, method, url, auto atom_url_request =
weak_ptr); AtomURLRequest::Create(browser_context, method, url, weak_ptr);
api_url_request->atom_request_ = atom_url_request; api_url_request->atom_request_ = atom_url_request;
@ -203,13 +193,10 @@ bool URLRequest::Canceled() const {
return request_state_.Canceled(); return request_state_.Canceled();
} }
bool URLRequest::Write( bool URLRequest::Write(scoped_refptr<const net::IOBufferWithSize> buffer,
scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) { bool is_last) {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Failed() ||
request_state_.Failed() || request_state_.Finished() || request_state_.Closed()) {
request_state_.Finished() ||
request_state_.Closed()) {
return false; return false;
} }
@ -231,10 +218,8 @@ bool URLRequest::Write(
return false; return false;
} }
void URLRequest::Cancel() { void URLRequest::Cancel() {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Closed()) {
request_state_.Closed()) {
// Cancel only once. // Cancel only once.
return; return;
} }
@ -304,8 +289,7 @@ void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
void URLRequest::OnAuthenticationRequired( void URLRequest::OnAuthenticationRequired(
scoped_refptr<const net::AuthChallengeInfo> auth_info) { scoped_refptr<const net::AuthChallengeInfo> auth_info) {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Closed()) {
request_state_.Closed()) {
return; return;
} }
@ -315,16 +299,13 @@ void URLRequest::OnAuthenticationRequired(
} }
EmitRequestEvent( EmitRequestEvent(
false, false, "login", auth_info.get(),
"login",
auth_info.get(),
base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_)); base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_));
} }
void URLRequest::OnResponseStarted( void URLRequest::OnResponseStarted(
scoped_refptr<net::HttpResponseHeaders> response_headers) { scoped_refptr<net::HttpResponseHeaders> response_headers) {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Failed() ||
request_state_.Failed() ||
request_state_.Closed()) { request_state_.Closed()) {
// Don't emit any event after request cancel. // Don't emit any event after request cancel.
return; return;
@ -336,10 +317,8 @@ void URLRequest::OnResponseStarted(
void URLRequest::OnResponseData( void URLRequest::OnResponseData(
scoped_refptr<const net::IOBufferWithSize> buffer) { scoped_refptr<const net::IOBufferWithSize> buffer) {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Closed() ||
request_state_.Closed() || request_state_.Failed() || response_state_.Failed()) {
request_state_.Failed() ||
response_state_.Failed()) {
// In case we received an unexpected event from Chromium net, // In case we received an unexpected event from Chromium net,
// don't emit any data event after request cancel/error/close. // don't emit any data event after request cancel/error/close.
return; return;
@ -351,10 +330,8 @@ void URLRequest::OnResponseData(
} }
void URLRequest::OnResponseCompleted() { void URLRequest::OnResponseCompleted() {
if (request_state_.Canceled() || if (request_state_.Canceled() || request_state_.Closed() ||
request_state_.Closed() || request_state_.Failed() || response_state_.Failed()) {
request_state_.Failed() ||
response_state_.Failed()) {
// In case we received an unexpected event from Chromium net, // In case we received an unexpected event from Chromium net,
// don't emit any data event after request cancel/error/close. // don't emit any data event after request cancel/error/close.
return; return;
@ -378,7 +355,6 @@ void URLRequest::OnResponseError(const std::string& error) {
Close(); Close();
} }
int URLRequest::StatusCode() const { int URLRequest::StatusCode() const {
if (response_headers_) { if (response_headers_) {
return response_headers_->response_code(); return response_headers_->response_code();
@ -394,8 +370,7 @@ std::string URLRequest::StatusMessage() const {
return result; return result;
} }
scoped_refptr<net::HttpResponseHeaders> scoped_refptr<net::HttpResponseHeaders> URLRequest::RawResponseHeaders() const {
URLRequest::RawResponseHeaders() const {
return response_headers_; return response_headers_;
} }

View file

@ -175,7 +175,6 @@ class URLRequest : public mate::EventEmitter<URLRequest> {
void RemoveExtraHeader(const std::string& name); void RemoveExtraHeader(const std::string& name);
void SetChunkedUpload(bool is_chunked_upload); void SetChunkedUpload(bool is_chunked_upload);
bool CanReadHeaders() const;
int StatusCode() const; int StatusCode() const;
std::string StatusMessage() const; std::string StatusMessage() const;
scoped_refptr<net::HttpResponseHeaders> RawResponseHeaders() const; scoped_refptr<net::HttpResponseHeaders> RawResponseHeaders() const;

View file

@ -3,17 +3,16 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "atom/browser/net/atom_url_request.h"
#include <string> #include <string>
#include "atom/browser/api/atom_api_url_request.h" #include "atom/browser/api/atom_api_url_request.h"
#include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_context.h"
#include "atom/browser/net/atom_url_request.h"
#include "base/callback.h" #include "base/callback.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/elements_upload_data_stream.h" #include "net/base/elements_upload_data_stream.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/upload_bytes_element_reader.h" #include "net/base/upload_bytes_element_reader.h"
namespace { namespace {
const int kBufferSize = 4096; const int kBufferSize = 4096;
} // namespace } // namespace
@ -27,11 +26,9 @@ class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader {
explicit UploadOwnedIOBufferElementReader( explicit UploadOwnedIOBufferElementReader(
scoped_refptr<const net::IOBufferWithSize> buffer) scoped_refptr<const net::IOBufferWithSize> buffer)
: net::UploadBytesElementReader(buffer->data(), buffer->size()), : net::UploadBytesElementReader(buffer->data(), buffer->size()),
buffer_(buffer) { buffer_(buffer) {}
}
~UploadOwnedIOBufferElementReader() override { ~UploadOwnedIOBufferElementReader() override {}
}
static UploadOwnedIOBufferElementReader* CreateWithBuffer( static UploadOwnedIOBufferElementReader* CreateWithBuffer(
scoped_refptr<const net::IOBufferWithSize> buffer) { scoped_refptr<const net::IOBufferWithSize> buffer) {
@ -49,11 +46,9 @@ class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader {
AtomURLRequest::AtomURLRequest(base::WeakPtr<api::URLRequest> delegate) AtomURLRequest::AtomURLRequest(base::WeakPtr<api::URLRequest> delegate)
: delegate_(delegate), : delegate_(delegate),
is_chunked_upload_(false), is_chunked_upload_(false),
response_read_buffer_(new net::IOBuffer(kBufferSize)) { response_read_buffer_(new net::IOBuffer(kBufferSize)) {}
}
AtomURLRequest::~AtomURLRequest() { AtomURLRequest::~AtomURLRequest() {}
}
scoped_refptr<AtomURLRequest> AtomURLRequest::Create( scoped_refptr<AtomURLRequest> AtomURLRequest::Create(
AtomBrowserContext* browser_context, AtomBrowserContext* browser_context,
@ -71,8 +66,7 @@ scoped_refptr<AtomURLRequest> AtomURLRequest::Create(
auto request_context_getter = browser_context->url_request_context_getter(); auto request_context_getter = browser_context->url_request_context_getter();
scoped_refptr<AtomURLRequest> atom_url_request(new AtomURLRequest(delegate)); scoped_refptr<AtomURLRequest> atom_url_request(new AtomURLRequest(delegate));
if (content::BrowserThread::PostTask( if (content::BrowserThread::PostTask(
content::BrowserThread::IO, content::BrowserThread::IO, FROM_HERE,
FROM_HERE,
base::Bind(&AtomURLRequest::DoInitialize, atom_url_request, base::Bind(&AtomURLRequest::DoInitialize, atom_url_request,
request_context_getter, method, url))) { request_context_getter, method, url))) {
return atom_url_request; return atom_url_request;
@ -90,15 +84,13 @@ void AtomURLRequest::DoInitialize(
auto context = request_context_getter->GetURLRequestContext(); auto context = request_context_getter->GetURLRequestContext();
DCHECK(context); DCHECK(context);
request_ = context->CreateRequest(GURL(url), request_ = context->CreateRequest(
net::RequestPriority::DEFAULT_PRIORITY, GURL(url), net::RequestPriority::DEFAULT_PRIORITY, this);
this);
request_->set_method(method); request_->set_method(method);
} }
bool AtomURLRequest::Write( bool AtomURLRequest::Write(scoped_refptr<const net::IOBufferWithSize> buffer,
scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) { bool is_last) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return content::BrowserThread::PostTask( return content::BrowserThread::PostTask(
@ -117,9 +109,7 @@ void AtomURLRequest::SetChunkedUpload(bool is_chunked_upload) {
void AtomURLRequest::Cancel() const { void AtomURLRequest::Cancel() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&AtomURLRequest::DoCancel, this)); base::Bind(&AtomURLRequest::DoCancel, this));
} }
@ -127,16 +117,14 @@ void AtomURLRequest::SetExtraHeader(const std::string& name,
const std::string& value) const { const std::string& value) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, content::BrowserThread::IO, FROM_HERE,
FROM_HERE,
base::Bind(&AtomURLRequest::DoSetExtraHeader, this, name, value)); base::Bind(&AtomURLRequest::DoSetExtraHeader, this, name, value));
} }
void AtomURLRequest::RemoveExtraHeader(const std::string& name) const { void AtomURLRequest::RemoveExtraHeader(const std::string& name) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::IO, content::BrowserThread::IO, FROM_HERE,
FROM_HERE,
base::Bind(&AtomURLRequest::DoRemoveExtraHeader, this, name)); base::Bind(&AtomURLRequest::DoRemoveExtraHeader, this, name));
} }
@ -174,14 +162,11 @@ void AtomURLRequest::DoWriteBuffer(
if (buffer) if (buffer)
// Non-empty buffer. // Non-empty buffer.
chunked_stream_writer_->AppendData(buffer->data(), chunked_stream_writer_->AppendData(buffer->data(), buffer->size(),
buffer->size(),
is_last); is_last);
else if (is_last) else if (is_last)
// Empty buffer and last chunk, i.e. request.end(). // Empty buffer and last chunk, i.e. request.end().
chunked_stream_writer_->AppendData(nullptr, chunked_stream_writer_->AppendData(nullptr, 0, true);
0,
true);
if (first_call) { if (first_call) {
request_->Start(); request_->Start();
@ -190,8 +175,8 @@ void AtomURLRequest::DoWriteBuffer(
if (buffer) { if (buffer) {
// Handling potential empty buffers. // Handling potential empty buffers.
using internal::UploadOwnedIOBufferElementReader; using internal::UploadOwnedIOBufferElementReader;
auto element_reader = UploadOwnedIOBufferElementReader::CreateWithBuffer( auto element_reader =
std::move(buffer)); UploadOwnedIOBufferElementReader::CreateWithBuffer(std::move(buffer));
upload_element_readers_.push_back( upload_element_readers_.push_back(
std::unique_ptr<net::UploadElementReader>(element_reader)); std::unique_ptr<net::UploadElementReader>(element_reader));
} }
@ -221,8 +206,7 @@ void AtomURLRequest::DoRemoveExtraHeader(const std::string& name) const {
request_->RemoveRequestHeaderByName(name); request_->RemoveRequestHeaderByName(name);
} }
void AtomURLRequest::DoSetAuth( void AtomURLRequest::DoSetAuth(const base::string16& username,
const base::string16& username,
const base::string16& password) const { const base::string16& password) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
request_->SetAuth(net::AuthCredentials(username, password)); request_->SetAuth(net::AuthCredentials(username, password));
@ -233,15 +217,13 @@ void AtomURLRequest::DoCancelAuth() const {
request_->CancelAuth(); request_->CancelAuth();
} }
void AtomURLRequest::OnAuthRequired( void AtomURLRequest::OnAuthRequired(net::URLRequest* request,
net::URLRequest* request,
net::AuthChallengeInfo* auth_info) { net::AuthChallengeInfo* auth_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateAuthenticationRequired, base::Bind(&AtomURLRequest::InformDelegateAuthenticationRequired, this,
this,
scoped_refptr<net::AuthChallengeInfo>(auth_info))); scoped_refptr<net::AuthChallengeInfo>(auth_info)));
} }
@ -256,8 +238,7 @@ void AtomURLRequest::OnResponseStarted(net::URLRequest* request) {
// Success or pending trigger a Read. // Success or pending trigger a Read.
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateResponseStarted, base::Bind(&AtomURLRequest::InformDelegateResponseStarted, this,
this,
response_headers)); response_headers));
ReadResponse(); ReadResponse();
@ -267,8 +248,7 @@ void AtomURLRequest::OnResponseStarted(net::URLRequest* request) {
auto error = net::ErrorToString(status.ToNetError()); auto error = net::ErrorToString(status.ToNetError());
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateRequestErrorOccured, base::Bind(&AtomURLRequest::InformDelegateRequestErrorOccured, this,
this,
std::move(error))); std::move(error)));
} }
// We don't report an error is the request is canceled. // We don't report an error is the request is canceled.
@ -283,9 +263,7 @@ void AtomURLRequest::ReadResponse() {
} }
} }
void AtomURLRequest::OnReadCompleted(net::URLRequest* request, int bytes_read) {
void AtomURLRequest::OnReadCompleted(net::URLRequest* request,
int bytes_read) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
DCHECK_EQ(request, request_.get()); DCHECK_EQ(request, request_.get());
@ -308,16 +286,14 @@ void AtomURLRequest::OnReadCompleted(net::URLRequest* request,
data_transfer_error = true; data_transfer_error = true;
break; break;
} }
} while (request_->Read(response_read_buffer_.get(), } while (
kBufferSize, request_->Read(response_read_buffer_.get(), kBufferSize, &bytes_read));
&bytes_read));
if (response_error) { if (response_error) {
DoCancel(); DoCancel();
auto error = net::ErrorToString(status.ToNetError()); auto error = net::ErrorToString(status.ToNetError());
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, this,
this,
std::move(error))); std::move(error)));
} else if (data_ended) { } else if (data_ended) {
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
@ -328,8 +304,7 @@ void AtomURLRequest::OnReadCompleted(net::URLRequest* request,
DoCancel(); DoCancel();
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, this,
this,
"Failed to transfer data from IO to UI thread.")); "Failed to transfer data from IO to UI thread."));
} }
} }
@ -344,12 +319,10 @@ bool AtomURLRequest::CopyAndPostBuffer(int bytes_read) {
return content::BrowserThread::PostTask( return content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateResponseData, base::Bind(&AtomURLRequest::InformDelegateResponseData, this,
this,
buffer_copy)); buffer_copy));
} }
void AtomURLRequest::InformDelegateAuthenticationRequired( void AtomURLRequest::InformDelegateAuthenticationRequired(
scoped_refptr<net::AuthChallengeInfo> auth_info) const { scoped_refptr<net::AuthChallengeInfo> auth_info) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

View file

@ -30,8 +30,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>,
const std::string& url, const std::string& url,
base::WeakPtr<api::URLRequest> delegate); base::WeakPtr<api::URLRequest> delegate);
bool Write(scoped_refptr<const net::IOBufferWithSize> buffer, bool Write(scoped_refptr<const net::IOBufferWithSize> buffer, bool is_last);
bool is_last);
void SetChunkedUpload(bool is_chunked_upload); void SetChunkedUpload(bool is_chunked_upload);
void Cancel() const; void Cancel() const;
void SetExtraHeader(const std::string& name, const std::string& value) const; void SetExtraHeader(const std::string& name, const std::string& value) const;