From 4347ce4a53fb957c0d388594097309c7444fe50e Mon Sep 17 00:00:00 2001 From: "ali.ibrahim" Date: Fri, 14 Oct 2016 11:50:47 +0200 Subject: [PATCH] Formatting C++ code using ClangFormat. --- atom/browser/api/atom_api_net.cc | 19 ++-- atom/browser/api/atom_api_net.h | 2 +- atom/browser/api/atom_api_url_request.cc | 119 +++++++++-------------- atom/browser/api/atom_api_url_request.h | 1 - atom/browser/net/atom_url_request.cc | 95 +++++++----------- atom/browser/net/atom_url_request.h | 7 +- 6 files changed, 93 insertions(+), 150 deletions(-) diff --git a/atom/browser/api/atom_api_net.cc b/atom/browser/api/atom_api_net.cc index 2ce7aa3816e8..dac8d9ee1461 100644 --- a/atom/browser/api/atom_api_net.cc +++ b/atom/browser/api/atom_api_net.cc @@ -15,9 +15,7 @@ Net::Net(v8::Isolate* isolate) { Init(isolate); } -Net::~Net() { -} - +Net::~Net() {} // static v8::Local Net::Create(v8::Isolate* isolate) { @@ -29,34 +27,33 @@ void Net::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "Net")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetProperty("URLRequest", &Net::URLRequest) - .SetMethod("_RequestGarbageCollectionForTesting", - &Net::RequestGarbageCollectionForTesting); + .SetProperty("URLRequest", &Net::URLRequest) + .SetMethod("_RequestGarbageCollectionForTesting", + &Net::RequestGarbageCollectionForTesting); } v8::Local Net::URLRequest(v8::Isolate* isolate) { return URLRequest::GetConstructor(isolate)->GetFunction(); } - void Net::RequestGarbageCollectionForTesting() { isolate()->RequestGarbageCollectionForTesting( v8::Isolate::GarbageCollectionType::kFullGarbageCollection); } - } // namespace api } // namespace atom - namespace { using atom::api::Net; using atom::api::URLRequest; -void Initialize(v8::Local exports, v8::Local unused, - v8::Local context, void* priv) { +void Initialize(v8::Local exports, + v8::Local unused, + v8::Local context, + void* priv) { v8::Isolate* isolate = context->GetIsolate(); URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New)); diff --git a/atom/browser/api/atom_api_net.h b/atom/browser/api/atom_api_net.h index 04b882d2599b..0b86931978a3 100644 --- a/atom/browser/api/atom_api_net.h +++ b/atom/browser/api/atom_api_net.h @@ -19,6 +19,7 @@ class Net : public mate::EventEmitter { v8::Local prototype); v8::Local URLRequest(v8::Isolate* isolate); + protected: explicit Net(v8::Isolate* isolate); ~Net() override; @@ -32,5 +33,4 @@ class Net : public mate::EventEmitter { } // namespace atom - #endif // ATOM_BROWSER_API_ATOM_API_NET_H_ diff --git a/atom/browser/api/atom_api_url_request.cc b/atom/browser/api/atom_api_url_request.cc index 4b0ebedb5ad4..393f03ddb480 100644 --- a/atom/browser/api/atom_api_url_request.cc +++ b/atom/browser/api/atom_api_url_request.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. +#include "atom/browser/api/atom_api_url_request.h" #include #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/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/net_converter.h" @@ -12,24 +12,20 @@ #include "atom/common/node_includes.h" #include "native_mate/dictionary.h" - - namespace mate { -template<> +template <> struct Converter> { static v8::Local ToV8( v8::Isolate* isolate, scoped_refptr buffer) { - return node::Buffer::Copy(isolate, - buffer->data(), - buffer->size()).ToLocalChecked(); + return node::Buffer::Copy(isolate, buffer->data(), buffer->size()) + .ToLocalChecked(); } - static bool FromV8( - v8::Isolate* isolate, - v8::Local val, - scoped_refptr* out) { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + scoped_refptr* out) { auto size = node::Buffer::Length(val); if (size == 0) { @@ -65,16 +61,14 @@ struct Converter> { namespace atom { namespace api { - template URLRequest::StateBase::StateBase(Flags initialState) - : state_(initialState) { -} + : state_(initialState) {} template void URLRequest::StateBase::SetFlag(Flags flag) { - state_ = static_cast(static_cast(state_) | - static_cast(flag)); + state_ = + static_cast(static_cast(state_) | static_cast(flag)); } template @@ -88,8 +82,7 @@ bool URLRequest::StateBase::IsFlagSet(Flags flag) const { } URLRequest::RequestState::RequestState() - : StateBase(RequestStateFlags::kNotStarted) { -} + : StateBase(RequestStateFlags::kNotStarted) {} bool URLRequest::RequestState::NotStarted() const { return *this == RequestStateFlags::kNotStarted; @@ -116,8 +109,7 @@ bool URLRequest::RequestState::Closed() const { } URLRequest::ResponseState::ResponseState() - : StateBase(ResponseStateFlags::kNotStarted) { -} + : StateBase(ResponseStateFlags::kNotStarted) {} bool URLRequest::ResponseState::NotStarted() const { return *this == ResponseStateFlags::kNotStarted; @@ -131,7 +123,6 @@ bool URLRequest::ResponseState::Ended() const { return IsFlagSet(ResponseStateFlags::kEnded); } - bool URLRequest::ResponseState::Failed() const { return IsFlagSet(ResponseStateFlags::kFailed); } @@ -141,8 +132,7 @@ URLRequest::URLRequest(v8::Isolate* isolate, v8::Local wrapper) InitWith(isolate, wrapper); } -URLRequest::~URLRequest() { -} +URLRequest::~URLRequest() {} // static 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 api_url_request = new URLRequest(args->isolate(), args->GetThis()); auto weak_ptr = api_url_request->weak_ptr_factory_.GetWeakPtr(); - auto atom_url_request = AtomURLRequest::Create(browser_context, method, url, - weak_ptr); + auto atom_url_request = + AtomURLRequest::Create(browser_context, method, url, weak_ptr); api_url_request->atom_request_ = atom_url_request; @@ -174,21 +164,21 @@ void URLRequest::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "URLRequest")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - // Request API - .MakeDestroyable() - .SetMethod("write", &URLRequest::Write) - .SetMethod("cancel", &URLRequest::Cancel) - .SetMethod("setExtraHeader", &URLRequest::SetExtraHeader) - .SetMethod("removeExtraHeader", &URLRequest::RemoveExtraHeader) - .SetMethod("setChunkedUpload", &URLRequest::SetChunkedUpload) - .SetProperty("notStarted", &URLRequest::NotStarted) - .SetProperty("finished", &URLRequest::Finished) - // Response APi - .SetProperty("statusCode", &URLRequest::StatusCode) - .SetProperty("statusMessage", &URLRequest::StatusMessage) - .SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders) - .SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor) - .SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor); + // Request API + .MakeDestroyable() + .SetMethod("write", &URLRequest::Write) + .SetMethod("cancel", &URLRequest::Cancel) + .SetMethod("setExtraHeader", &URLRequest::SetExtraHeader) + .SetMethod("removeExtraHeader", &URLRequest::RemoveExtraHeader) + .SetMethod("setChunkedUpload", &URLRequest::SetChunkedUpload) + .SetProperty("notStarted", &URLRequest::NotStarted) + .SetProperty("finished", &URLRequest::Finished) + // Response APi + .SetProperty("statusCode", &URLRequest::StatusCode) + .SetProperty("statusMessage", &URLRequest::StatusMessage) + .SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders) + .SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor) + .SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor); } bool URLRequest::NotStarted() const { @@ -203,13 +193,10 @@ bool URLRequest::Canceled() const { return request_state_.Canceled(); } -bool URLRequest::Write( - scoped_refptr buffer, - bool is_last) { - if (request_state_.Canceled() || - request_state_.Failed() || - request_state_.Finished() || - request_state_.Closed()) { +bool URLRequest::Write(scoped_refptr buffer, + bool is_last) { + if (request_state_.Canceled() || request_state_.Failed() || + request_state_.Finished() || request_state_.Closed()) { return false; } @@ -231,10 +218,8 @@ bool URLRequest::Write( return false; } - void URLRequest::Cancel() { - if (request_state_.Canceled() || - request_state_.Closed()) { + if (request_state_.Canceled() || request_state_.Closed()) { // Cancel only once. return; } @@ -303,9 +288,8 @@ void URLRequest::SetChunkedUpload(bool is_chunked_upload) { } void URLRequest::OnAuthenticationRequired( - scoped_refptr auth_info) { - if (request_state_.Canceled() || - request_state_.Closed()) { + scoped_refptr auth_info) { + if (request_state_.Canceled() || request_state_.Closed()) { return; } @@ -315,16 +299,13 @@ void URLRequest::OnAuthenticationRequired( } EmitRequestEvent( - false, - "login", - auth_info.get(), + false, "login", auth_info.get(), base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_)); } void URLRequest::OnResponseStarted( - scoped_refptr response_headers) { - if (request_state_.Canceled() || - request_state_.Failed() || + scoped_refptr response_headers) { + if (request_state_.Canceled() || request_state_.Failed() || request_state_.Closed()) { // Don't emit any event after request cancel. return; @@ -335,11 +316,9 @@ void URLRequest::OnResponseStarted( } void URLRequest::OnResponseData( - scoped_refptr buffer) { - if (request_state_.Canceled() || - request_state_.Closed() || - request_state_.Failed() || - response_state_.Failed()) { + scoped_refptr buffer) { + if (request_state_.Canceled() || request_state_.Closed() || + request_state_.Failed() || response_state_.Failed()) { // In case we received an unexpected event from Chromium net, // don't emit any data event after request cancel/error/close. return; @@ -351,10 +330,8 @@ void URLRequest::OnResponseData( } void URLRequest::OnResponseCompleted() { - if (request_state_.Canceled() || - request_state_.Closed() || - request_state_.Failed() || - response_state_.Failed()) { + if (request_state_.Canceled() || request_state_.Closed() || + request_state_.Failed() || response_state_.Failed()) { // In case we received an unexpected event from Chromium net, // don't emit any data event after request cancel/error/close. return; @@ -378,7 +355,6 @@ void URLRequest::OnResponseError(const std::string& error) { Close(); } - int URLRequest::StatusCode() const { if (response_headers_) { return response_headers_->response_code(); @@ -394,14 +370,13 @@ std::string URLRequest::StatusMessage() const { return result; } -scoped_refptr -URLRequest::RawResponseHeaders() const { +scoped_refptr URLRequest::RawResponseHeaders() const { return response_headers_; } uint32_t URLRequest::ResponseHttpVersionMajor() const { if (response_headers_) { - return response_headers_->GetHttpVersion().major_value(); + return response_headers_->GetHttpVersion().major_value(); } return 0; } diff --git a/atom/browser/api/atom_api_url_request.h b/atom/browser/api/atom_api_url_request.h index 1ccbb3610d27..e7780556bca0 100644 --- a/atom/browser/api/atom_api_url_request.h +++ b/atom/browser/api/atom_api_url_request.h @@ -175,7 +175,6 @@ class URLRequest : public mate::EventEmitter { void RemoveExtraHeader(const std::string& name); void SetChunkedUpload(bool is_chunked_upload); - bool CanReadHeaders() const; int StatusCode() const; std::string StatusMessage() const; scoped_refptr RawResponseHeaders() const; diff --git a/atom/browser/net/atom_url_request.cc b/atom/browser/net/atom_url_request.cc index 2870e6dda595..c0d41b3fb852 100644 --- a/atom/browser/net/atom_url_request.cc +++ b/atom/browser/net/atom_url_request.cc @@ -3,17 +3,16 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. +#include "atom/browser/net/atom_url_request.h" #include #include "atom/browser/api/atom_api_url_request.h" #include "atom/browser/atom_browser_context.h" -#include "atom/browser/net/atom_url_request.h" #include "base/callback.h" #include "content/public/browser/browser_thread.h" #include "net/base/elements_upload_data_stream.h" #include "net/base/io_buffer.h" #include "net/base/upload_bytes_element_reader.h" - namespace { const int kBufferSize = 4096; } // namespace @@ -27,11 +26,9 @@ class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader { explicit UploadOwnedIOBufferElementReader( scoped_refptr buffer) : net::UploadBytesElementReader(buffer->data(), buffer->size()), - buffer_(buffer) { - } + buffer_(buffer) {} - ~UploadOwnedIOBufferElementReader() override { - } + ~UploadOwnedIOBufferElementReader() override {} static UploadOwnedIOBufferElementReader* CreateWithBuffer( scoped_refptr buffer) { @@ -49,11 +46,9 @@ class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader { AtomURLRequest::AtomURLRequest(base::WeakPtr delegate) : delegate_(delegate), 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::Create( AtomBrowserContext* browser_context, @@ -71,10 +66,9 @@ scoped_refptr AtomURLRequest::Create( auto request_context_getter = browser_context->url_request_context_getter(); scoped_refptr atom_url_request(new AtomURLRequest(delegate)); if (content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(&AtomURLRequest::DoInitialize, atom_url_request, - request_context_getter, method, url))) { + content::BrowserThread::IO, FROM_HERE, + base::Bind(&AtomURLRequest::DoInitialize, atom_url_request, + request_context_getter, method, url))) { return atom_url_request; } return nullptr; @@ -90,16 +84,14 @@ void AtomURLRequest::DoInitialize( auto context = request_context_getter->GetURLRequestContext(); DCHECK(context); - request_ = context->CreateRequest(GURL(url), - net::RequestPriority::DEFAULT_PRIORITY, - this); + request_ = context->CreateRequest( + GURL(url), net::RequestPriority::DEFAULT_PRIORITY, this); request_->set_method(method); } -bool AtomURLRequest::Write( - scoped_refptr buffer, - bool is_last) { +bool AtomURLRequest::Write(scoped_refptr buffer, + bool is_last) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); return content::BrowserThread::PostTask( content::BrowserThread::IO, FROM_HERE, @@ -117,26 +109,22 @@ void AtomURLRequest::SetChunkedUpload(bool is_chunked_upload) { void AtomURLRequest::Cancel() const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(&AtomURLRequest::DoCancel, this)); + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, + base::Bind(&AtomURLRequest::DoCancel, this)); } void AtomURLRequest::SetExtraHeader(const std::string& name, const std::string& value) const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, + content::BrowserThread::IO, FROM_HERE, base::Bind(&AtomURLRequest::DoSetExtraHeader, this, name, value)); } void AtomURLRequest::RemoveExtraHeader(const std::string& name) const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, + content::BrowserThread::IO, FROM_HERE, base::Bind(&AtomURLRequest::DoRemoveExtraHeader, this, name)); } @@ -174,14 +162,11 @@ void AtomURLRequest::DoWriteBuffer( if (buffer) // Non-empty buffer. - chunked_stream_writer_->AppendData(buffer->data(), - buffer->size(), + chunked_stream_writer_->AppendData(buffer->data(), buffer->size(), is_last); else if (is_last) // Empty buffer and last chunk, i.e. request.end(). - chunked_stream_writer_->AppendData(nullptr, - 0, - true); + chunked_stream_writer_->AppendData(nullptr, 0, true); if (first_call) { request_->Start(); @@ -190,8 +175,8 @@ void AtomURLRequest::DoWriteBuffer( if (buffer) { // Handling potential empty buffers. using internal::UploadOwnedIOBufferElementReader; - auto element_reader = UploadOwnedIOBufferElementReader::CreateWithBuffer( - std::move(buffer)); + auto element_reader = + UploadOwnedIOBufferElementReader::CreateWithBuffer(std::move(buffer)); upload_element_readers_.push_back( std::unique_ptr(element_reader)); } @@ -221,9 +206,8 @@ void AtomURLRequest::DoRemoveExtraHeader(const std::string& name) const { request_->RemoveRequestHeaderByName(name); } -void AtomURLRequest::DoSetAuth( - const base::string16& username, - const base::string16& password) const { +void AtomURLRequest::DoSetAuth(const base::string16& username, + const base::string16& password) const { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); request_->SetAuth(net::AuthCredentials(username, password)); } @@ -233,15 +217,13 @@ void AtomURLRequest::DoCancelAuth() const { request_->CancelAuth(); } -void AtomURLRequest::OnAuthRequired( - net::URLRequest* request, - net::AuthChallengeInfo* auth_info) { +void AtomURLRequest::OnAuthRequired(net::URLRequest* request, + net::AuthChallengeInfo* auth_info) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateAuthenticationRequired, - this, + base::Bind(&AtomURLRequest::InformDelegateAuthenticationRequired, this, scoped_refptr(auth_info))); } @@ -250,14 +232,13 @@ void AtomURLRequest::OnResponseStarted(net::URLRequest* request) { DCHECK_EQ(request, request_.get()); scoped_refptr response_headers = - request->response_headers(); + request->response_headers(); const auto& status = request_->status(); if (status.is_success()) { // Success or pending trigger a Read. content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateResponseStarted, - this, + base::Bind(&AtomURLRequest::InformDelegateResponseStarted, this, response_headers)); ReadResponse(); @@ -267,8 +248,7 @@ void AtomURLRequest::OnResponseStarted(net::URLRequest* request) { auto error = net::ErrorToString(status.ToNetError()); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateRequestErrorOccured, - this, + base::Bind(&AtomURLRequest::InformDelegateRequestErrorOccured, this, std::move(error))); } // 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_EQ(request, request_.get()); @@ -308,16 +286,14 @@ void AtomURLRequest::OnReadCompleted(net::URLRequest* request, data_transfer_error = true; break; } - } while (request_->Read(response_read_buffer_.get(), - kBufferSize, - &bytes_read)); + } while ( + request_->Read(response_read_buffer_.get(), kBufferSize, &bytes_read)); if (response_error) { DoCancel(); auto error = net::ErrorToString(status.ToNetError()); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, - this, + base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, this, std::move(error))); } else if (data_ended) { content::BrowserThread::PostTask( @@ -328,8 +304,7 @@ void AtomURLRequest::OnReadCompleted(net::URLRequest* request, DoCancel(); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, - this, + base::Bind(&AtomURLRequest::InformDelegateResponseErrorOccured, this, "Failed to transfer data from IO to UI thread.")); } } @@ -344,12 +319,10 @@ bool AtomURLRequest::CopyAndPostBuffer(int bytes_read) { return content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomURLRequest::InformDelegateResponseData, - this, + base::Bind(&AtomURLRequest::InformDelegateResponseData, this, buffer_copy)); } - void AtomURLRequest::InformDelegateAuthenticationRequired( scoped_refptr auth_info) const { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); diff --git a/atom/browser/net/atom_url_request.h b/atom/browser/net/atom_url_request.h index 8d182a7da5dd..1acfd3220472 100644 --- a/atom/browser/net/atom_url_request.h +++ b/atom/browser/net/atom_url_request.h @@ -30,8 +30,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe, const std::string& url, base::WeakPtr delegate); - bool Write(scoped_refptr buffer, - bool is_last); + bool Write(scoped_refptr buffer, bool is_last); void SetChunkedUpload(bool is_chunked_upload); void Cancel() const; void SetExtraHeader(const std::string& name, const std::string& value) const; @@ -50,7 +49,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe, friend class base::RefCountedThreadSafe; explicit AtomURLRequest(base::WeakPtr delegate); - ~AtomURLRequest()override; + ~AtomURLRequest() override; void DoInitialize(scoped_refptr, const std::string& method, @@ -85,7 +84,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe, std::unique_ptr chunked_stream_; std::unique_ptr chunked_stream_writer_; std::vector> - upload_element_readers_; + upload_element_readers_; scoped_refptr response_read_buffer_; DISALLOW_COPY_AND_ASSIGN(AtomURLRequest);