Fixing cpplint issues.

This commit is contained in:
ali.ibrahim 2016-09-29 11:31:08 +02:00
parent 08947682b0
commit 0588435882
6 changed files with 83 additions and 100 deletions

View file

@ -4,8 +4,8 @@
#include "atom/browser/api/atom_api_net.h" #include "atom/browser/api/atom_api_net.h"
#include "atom/browser/api/atom_api_url_request.h" #include "atom/browser/api/atom_api_url_request.h"
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom { namespace atom {
@ -50,7 +50,6 @@ 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::Value> unused,
v8::Local<v8::Context> context, void* priv) { 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));
@ -58,7 +57,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
mate::Dictionary dict(isolate, exports); mate::Dictionary dict(isolate, exports);
dict.Set("net", Net::Create(isolate)); dict.Set("net", Net::Create(isolate));
dict.Set("Net", Net::GetConstructor(isolate)->GetFunction()); dict.Set("Net", Net::GetConstructor(isolate)->GetFunction());
} }
} // namespace } // namespace

View file

@ -12,20 +12,18 @@ namespace atom {
namespace api { namespace api {
class Net : public mate::EventEmitter<Net> { class Net : public mate::EventEmitter<Net> {
public:
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate); static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
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:
Net(v8::Isolate* isolate); explicit Net(v8::Isolate* isolate);
~Net() override; ~Net() override;
private: private:
DISALLOW_COPY_AND_ASSIGN(Net); DISALLOW_COPY_AND_ASSIGN(Net);
}; };

View file

@ -2,23 +2,17 @@
// 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 "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 "native_mate/dictionary.h"
#include "atom/browser/net/atom_url_request.h" #include "atom/browser/net/atom_url_request.h"
#include "atom/common/node_includes.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"
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/callback.h" #include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace {
const char* const kResponse = "response";
const char* const kData = "data";
const char* const kEnd = "end";
}
namespace mate { namespace mate {
template<> template<>
@ -26,7 +20,6 @@ struct Converter<scoped_refptr<const net::HttpResponseHeaders>> {
static v8::Local<v8::Value> ToV8( static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate, v8::Isolate* isolate,
scoped_refptr<const net::HttpResponseHeaders> val) { scoped_refptr<const net::HttpResponseHeaders> val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (val) { if (val) {
size_t iter = 0; size_t iter = 0;
@ -54,7 +47,6 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
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);
if (size == 0) { if (size == 0) {
@ -65,7 +57,6 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
*out = nullptr; *out = nullptr;
return true; return true;
} }
auto data = node::Buffer::Data(val); auto data = node::Buffer::Data(val);
if (!data) { if (!data) {
// This is an error as size is positif but data is null. // This is an error as size is positif but data is null.
@ -86,9 +77,9 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
} }
}; };
} } // namespace mate
namespace atom {
namespace atom {
namespace api { namespace api {
URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
@ -101,7 +92,6 @@ URLRequest::~URLRequest() {
// static // static
mate::WrappableBase* URLRequest::New(mate::Arguments* args) { mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
v8::Local<v8::Object> options; v8::Local<v8::Object> options;
args->GetNext(&options); args->GetNext(&options);
mate::Dictionary dict(args->isolate(), options); mate::Dictionary dict(args->isolate(), options);
@ -146,15 +136,12 @@ void URLRequest::BuildPrototype(v8::Isolate* isolate,
.SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders) .SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders)
.SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor) .SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor)
.SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor); .SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor);
} }
bool URLRequest::Write( bool URLRequest::Write(
scoped_refptr<const net::IOBufferWithSize> buffer, scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) { bool is_last) {
return atom_request_->Write(buffer, is_last); return atom_request_->Write(buffer, is_last);
} }
@ -202,7 +189,6 @@ void URLRequest::OnResponseData(
if (!buffer || !buffer->data() || !buffer->size()) { if (!buffer || !buffer->data() || !buffer->size()) {
return; return;
} }
EmitResponseEvent("data", buffer); EmitResponseEvent("data", buffer);
} }
@ -261,6 +247,6 @@ void URLRequest::unpin() {
wrapper_.Reset(); wrapper_.Reset();
} }
} // namespace mate } // namespace api
} // namepsace mate } // namespace atom

View file

@ -6,10 +6,11 @@
#define ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_ #define ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_
#include <array> #include <array>
#include <string>
#include "atom/browser/api/trackable_object.h" #include "atom/browser/api/trackable_object.h"
#include "native_mate/handle.h" #include "native_mate/handle.h"
#include "net/url_request/url_request_context.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/url_request/url_request_context.h"
namespace atom { namespace atom {
@ -22,16 +23,17 @@ class URLRequest : public mate::EventEmitter<URLRequest> {
public: public:
static mate::WrappableBase* New(mate::Arguments* args); static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(
v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype); v8::Local<v8::FunctionTemplate> prototype);
protected: protected:
URLRequest(v8::Isolate* isolate, explicit URLRequest(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper); v8::Local<v8::Object> wrapper);
~URLRequest() override; ~URLRequest() override;
private: private:
bool Write(scoped_refptr<const net::IOBufferWithSize> buffer, bool Write(scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last); bool is_last);
void Abort(); void Abort();
@ -71,7 +73,6 @@ private:
v8::Global<v8::Object> wrapper_; v8::Global<v8::Object> wrapper_;
base::WeakPtrFactory<URLRequest> weak_ptr_factory_; base::WeakPtrFactory<URLRequest> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequest); DISALLOW_COPY_AND_ASSIGN(URLRequest);
}; };
@ -107,8 +108,8 @@ void URLRequest::EmitResponseEvent(ArgTypes... args) {
} // namepsace api } // namespace api
} // namepsace atom } // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_ #endif // ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_

View file

@ -3,16 +3,18 @@
// 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 "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/io_buffer.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/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
@ -23,7 +25,7 @@ namespace internal {
class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader { class UploadOwnedIOBufferElementReader : public net::UploadBytesElementReader {
public: public:
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())
@ -39,18 +41,18 @@ public:
return new UploadOwnedIOBufferElementReader(std::move(buffer)); return new UploadOwnedIOBufferElementReader(std::move(buffer));
} }
private: private:
scoped_refptr<const net::IOBuffer> buffer_; scoped_refptr<const net::IOBuffer> buffer_;
DISALLOW_COPY_AND_ASSIGN(UploadOwnedIOBufferElementReader); DISALLOW_COPY_AND_ASSIGN(UploadOwnedIOBufferElementReader);
}; };
} } // namespace internal
AtomURLRequest::AtomURLRequest(base::WeakPtr<api::URLRequest> delegate) AtomURLRequest::AtomURLRequest(base::WeakPtr<api::URLRequest> delegate)
: delegate_(delegate) : delegate_(delegate)
, response_read_buffer_(new net::IOBuffer(kBufferSize)) , response_read_buffer_(new net::IOBuffer(kBufferSize))
, is_chunked_upload_(is_chunked_upload_) { , is_chunked_upload_(false) {
} }
AtomURLRequest::~AtomURLRequest() { AtomURLRequest::~AtomURLRequest() {
@ -82,7 +84,6 @@ scoped_refptr<AtomURLRequest> AtomURLRequest::Create(
atom_url_request->request_->set_method(method); atom_url_request->request_->set_method(method);
return atom_url_request; return atom_url_request;
} }
@ -154,7 +155,6 @@ void AtomURLRequest::DoWriteBuffer(
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (is_chunked_upload_) { if (is_chunked_upload_) {
// Chunked encoding case. // Chunked encoding case.
bool first_call = false; bool first_call = false;
@ -181,9 +181,7 @@ void AtomURLRequest::DoWriteBuffer(
if (first_call) if (first_call)
request_->Start(); request_->Start();
} } else {
else {
if (buffer) { if (buffer) {
// Handling potential empty buffers. // Handling potential empty buffers.
using internal::UploadOwnedIOBufferElementReader; using internal::UploadOwnedIOBufferElementReader;
@ -247,12 +245,13 @@ void AtomURLRequest::OnResponseStarted(net::URLRequest* request) {
base::Bind(&AtomURLRequest::InformDelegateResponseStarted, this)); base::Bind(&AtomURLRequest::InformDelegateResponseStarted, this));
ReadResponse(); ReadResponse();
} } else {
else {
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::InformDelegateErrorOccured, this, std::move(error))); base::Bind(&AtomURLRequest::InformDelegateErrorOccured,
this,
std::move(error)));
} }
} }
@ -284,7 +283,9 @@ void AtomURLRequest::OnReadCompleted(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::InformDelegateErrorOccured, this, std::move(error))); base::Bind(&AtomURLRequest::InformDelegateErrorOccured,
this,
std::move(error)));
break; break;
} }
@ -296,14 +297,12 @@ void AtomURLRequest::OnReadCompleted(net::URLRequest* request,
kBufferSize, kBufferSize,
&bytes_read)); &bytes_read));
if (!status.is_io_pending() if (!status.is_io_pending()
/* TODO || request_type_ == URLFetcher::HEAD*/ ) /* TODO || request_type_ == URLFetcher::HEAD*/ )
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::Bind(&AtomURLRequest::InformDelegateResponseCompleted, this)); base::Bind(&AtomURLRequest::InformDelegateResponseCompleted, this));
} }
bool AtomURLRequest::CopyAndPostBuffer(int bytes_read) { bool AtomURLRequest::CopyAndPostBuffer(int bytes_read) {

View file

@ -6,9 +6,11 @@
#ifndef ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_ #ifndef ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_
#define ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_ #define ATOM_BROWSER_NET_ATOM_URL_REQUEST_H_
#include <string>
#include <vector>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "net/url_request/url_request.h"
#include "net/base/chunked_upload_data_stream.h" #include "net/base/chunked_upload_data_stream.h"
#include "net/url_request/url_request.h"
namespace net { namespace net {
@ -27,7 +29,7 @@ class URLRequest;
class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>, class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>,
public net::URLRequest::Delegate { public net::URLRequest::Delegate {
public: public:
static scoped_refptr<AtomURLRequest> Create( static scoped_refptr<AtomURLRequest> Create(
AtomBrowserContext* browser_context, AtomBrowserContext* browser_context,
const std::string& method, const std::string& method,
@ -44,15 +46,15 @@ public:
const base::string16& password) const; const base::string16& password) const;
scoped_refptr<const net::HttpResponseHeaders> GetResponseHeaders() const; scoped_refptr<const net::HttpResponseHeaders> GetResponseHeaders() const;
protected: protected:
// Overrides of net::URLRequest::Delegate // Overrides of net::URLRequest::Delegate
virtual void OnAuthRequired(net::URLRequest* request, void OnAuthRequired(net::URLRequest* request,
net::AuthChallengeInfo* auth_info) override; net::AuthChallengeInfo* auth_info) override;
virtual void OnResponseStarted(net::URLRequest* request) override; void OnResponseStarted(net::URLRequest* request) override;
virtual void OnReadCompleted(net::URLRequest* request, void OnReadCompleted(net::URLRequest* request,
int bytes_read) override; int bytes_read) override;
private: private:
friend class base::RefCountedThreadSafe<AtomURLRequest>; friend class base::RefCountedThreadSafe<AtomURLRequest>;
void DoWriteBuffer(scoped_refptr<const net::IOBufferWithSize> buffer, void DoWriteBuffer(scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last); bool is_last);
@ -72,7 +74,7 @@ private:
void InformDelegateResponseCompleted() const; void InformDelegateResponseCompleted() const;
void InformDelegateErrorOccured(const std::string& error) const; void InformDelegateErrorOccured(const std::string& error) const;
AtomURLRequest(base::WeakPtr<api::URLRequest> delegate); explicit AtomURLRequest(base::WeakPtr<api::URLRequest> delegate);
virtual ~AtomURLRequest(); virtual ~AtomURLRequest();
base::WeakPtr<api::URLRequest> delegate_; base::WeakPtr<api::URLRequest> delegate_;
@ -81,14 +83,13 @@ private:
bool is_chunked_upload_; bool is_chunked_upload_;
std::unique_ptr<net::ChunkedUploadDataStream> chunked_stream_; std::unique_ptr<net::ChunkedUploadDataStream> chunked_stream_;
std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_stream_writer_; std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_stream_writer_;
std::vector<std::unique_ptr<net::UploadElementReader>>
std::vector<std::unique_ptr<net::UploadElementReader>>upload_element_readers_; upload_element_readers_;
scoped_refptr<net::IOBuffer> response_read_buffer_; scoped_refptr<net::IOBuffer> response_read_buffer_;
scoped_refptr<net::HttpResponseHeaders> response_headers_; scoped_refptr<net::HttpResponseHeaders> response_headers_;
DISALLOW_COPY_AND_ASSIGN(AtomURLRequest); DISALLOW_COPY_AND_ASSIGN(AtomURLRequest);
}; };
} // namespace atom } // namespace atom