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_url_request.h"
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
@ -50,7 +50,6 @@ using atom::api::URLRequest;
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
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);
dict.Set("net", Net::Create(isolate));
dict.Set("Net", Net::GetConstructor(isolate)->GetFunction());
}
} // namespace

View file

@ -12,7 +12,6 @@ namespace atom {
namespace api {
class Net : public mate::EventEmitter<Net> {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
@ -21,11 +20,10 @@ public:
v8::Local<v8::Value> URLRequest(v8::Isolate* isolate);
protected:
Net(v8::Isolate* isolate);
explicit Net(v8::Isolate* isolate);
~Net() override;
private:
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
// 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 "native_mate/dictionary.h"
#include "atom/browser/api/atom_api_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/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 {
template<>
@ -26,7 +20,6 @@ struct Converter<scoped_refptr<const net::HttpResponseHeaders>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
scoped_refptr<const net::HttpResponseHeaders> val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (val) {
size_t iter = 0;
@ -54,7 +47,6 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<const net::IOBufferWithSize>* out) {
auto size = node::Buffer::Length(val);
if (size == 0) {
@ -65,7 +57,6 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
*out = nullptr;
return true;
}
auto data = node::Buffer::Data(val);
if (!data) {
// This is an error as size is positif but data is null.
@ -86,9 +77,9 @@ struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
}
};
}
namespace atom {
} // namespace mate
namespace atom {
namespace api {
URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
@ -101,7 +92,6 @@ URLRequest::~URLRequest() {
// static
mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
v8::Local<v8::Object> options;
args->GetNext(&options);
mate::Dictionary dict(args->isolate(), options);
@ -146,15 +136,12 @@ void URLRequest::BuildPrototype(v8::Isolate* isolate,
.SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders)
.SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor)
.SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor);
}
bool URLRequest::Write(
scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) {
return atom_request_->Write(buffer, is_last);
}
@ -202,7 +189,6 @@ void URLRequest::OnResponseData(
if (!buffer || !buffer->data() || !buffer->size()) {
return;
}
EmitResponseEvent("data", buffer);
}
@ -261,6 +247,6 @@ void URLRequest::unpin() {
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_
#include <array>
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "native_mate/handle.h"
#include "net/url_request/url_request_context.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_context.h"
namespace atom {
@ -22,11 +23,12 @@ class URLRequest : public mate::EventEmitter<URLRequest> {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
static void BuildPrototype(
v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
URLRequest(v8::Isolate* isolate,
explicit URLRequest(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper);
~URLRequest() override;
@ -71,7 +73,6 @@ private:
v8::Global<v8::Object> wrapper_;
base::WeakPtrFactory<URLRequest> weak_ptr_factory_;
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_

View file

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

View file

@ -6,9 +6,11 @@
#ifndef 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 "net/url_request/url_request.h"
#include "net/base/chunked_upload_data_stream.h"
#include "net/url_request/url_request.h"
namespace net {
@ -46,10 +48,10 @@ public:
protected:
// Overrides of net::URLRequest::Delegate
virtual void OnAuthRequired(net::URLRequest* request,
void OnAuthRequired(net::URLRequest* request,
net::AuthChallengeInfo* auth_info) override;
virtual void OnResponseStarted(net::URLRequest* request) override;
virtual void OnReadCompleted(net::URLRequest* request,
void OnResponseStarted(net::URLRequest* request) override;
void OnReadCompleted(net::URLRequest* request,
int bytes_read) override;
private:
@ -72,7 +74,7 @@ private:
void InformDelegateResponseCompleted() const;
void InformDelegateErrorOccured(const std::string& error) const;
AtomURLRequest(base::WeakPtr<api::URLRequest> delegate);
explicit AtomURLRequest(base::WeakPtr<api::URLRequest> delegate);
virtual ~AtomURLRequest();
base::WeakPtr<api::URLRequest> delegate_;
@ -81,9 +83,8 @@ private:
bool is_chunked_upload_;
std::unique_ptr<net::ChunkedUploadDataStream> chunked_stream_;
std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_stream_writer_;
std::vector<std::unique_ptr<net::UploadElementReader>>upload_element_readers_;
std::vector<std::unique_ptr<net::UploadElementReader>>
upload_element_readers_;
scoped_refptr<net::IOBuffer> response_read_buffer_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;