| Index: components/cronet/android/cronet_url_request_context_adapter.cc
|
| diff --git a/components/cronet/android/url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
|
| similarity index 63%
|
| copy from components/cronet/android/url_request_context_adapter.cc
|
| copy to components/cronet/android/cronet_url_request_context_adapter.cc
|
| index 026e39d0b1524e30d1fb4f8fc5cd31232514cd14..40283c56680bbe21785263457ce59344210611c6 100644
|
| --- a/components/cronet/android/url_request_context_adapter.cc
|
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/cronet/android/url_request_context_adapter.h"
|
| +#include "components/cronet/android/cronet_url_request_context_adapter.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/files/file_util.h"
|
| @@ -18,6 +18,7 @@
|
| #include "net/proxy/proxy_service.h"
|
| #include "net/ssl/ssl_config_service_defaults.h"
|
| #include "net/url_request/static_http_user_agent_settings.h"
|
| +#include "net/url_request/url_request_context.h"
|
| #include "net/url_request/url_request_context_builder.h"
|
| #include "net/url_request/url_request_context_storage.h"
|
| #include "net/url_request/url_request_job_factory_impl.h"
|
| @@ -33,75 +34,75 @@ class BasicNetworkDelegate : public net::NetworkDelegate {
|
| // net::NetworkDelegate implementation.
|
| virtual int OnBeforeURLRequest(net::URLRequest* request,
|
| const net::CompletionCallback& callback,
|
| - GURL* new_url) override {
|
| + GURL* new_url) OVERRIDE {
|
| return net::OK;
|
| }
|
|
|
| virtual int OnBeforeSendHeaders(net::URLRequest* request,
|
| const net::CompletionCallback& callback,
|
| - net::HttpRequestHeaders* headers) override {
|
| + net::HttpRequestHeaders* headers) OVERRIDE {
|
| return net::OK;
|
| }
|
|
|
| virtual void OnSendHeaders(net::URLRequest* request,
|
| - const net::HttpRequestHeaders& headers) override {}
|
| + const net::HttpRequestHeaders& headers) OVERRIDE {}
|
|
|
| virtual int OnHeadersReceived(
|
| net::URLRequest* request,
|
| const net::CompletionCallback& callback,
|
| const net::HttpResponseHeaders* original_response_headers,
|
| scoped_refptr<net::HttpResponseHeaders>* _response_headers,
|
| - GURL* allowed_unsafe_redirect_url) override {
|
| + GURL* allowed_unsafe_redirect_url) OVERRIDE {
|
| return net::OK;
|
| }
|
|
|
| virtual void OnBeforeRedirect(net::URLRequest* request,
|
| - const GURL& new_location) override {}
|
| + const GURL& new_location) OVERRIDE {}
|
|
|
| - virtual void OnResponseStarted(net::URLRequest* request) override {}
|
| + virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {}
|
|
|
| virtual void OnRawBytesRead(const net::URLRequest& request,
|
| - int bytes_read) override {}
|
| + int bytes_read) OVERRIDE {}
|
|
|
| - virtual void OnCompleted(net::URLRequest* request, bool started) override {}
|
| + virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE {}
|
|
|
| - virtual void OnURLRequestDestroyed(net::URLRequest* request) override {}
|
| + virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE {}
|
|
|
| virtual void OnPACScriptError(int line_number,
|
| - const base::string16& error) override {}
|
| + const base::string16& error) OVERRIDE {}
|
|
|
| virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired(
|
| net::URLRequest* request,
|
| const net::AuthChallengeInfo& auth_info,
|
| const AuthCallback& callback,
|
| - net::AuthCredentials* credentials) override {
|
| + net::AuthCredentials* credentials) OVERRIDE {
|
| return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
| }
|
|
|
| virtual bool OnCanGetCookies(const net::URLRequest& request,
|
| - const net::CookieList& cookie_list) override {
|
| + const net::CookieList& cookie_list) OVERRIDE {
|
| return false;
|
| }
|
|
|
| virtual bool OnCanSetCookie(const net::URLRequest& request,
|
| const std::string& cookie_line,
|
| - net::CookieOptions* options) override {
|
| + net::CookieOptions* options) OVERRIDE {
|
| return false;
|
| }
|
|
|
| virtual bool OnCanAccessFile(const net::URLRequest& request,
|
| - const base::FilePath& path) const override {
|
| + const base::FilePath& path) const OVERRIDE {
|
| return false;
|
| }
|
|
|
| virtual bool OnCanThrottleRequest(
|
| - const net::URLRequest& request) const override {
|
| + const net::URLRequest& request) const OVERRIDE {
|
| return false;
|
| }
|
|
|
| virtual int OnBeforeSocketStreamConnect(
|
| net::SocketStream* stream,
|
| - const net::CompletionCallback& callback) override {
|
| + const net::CompletionCallback& callback) OVERRIDE {
|
| return net::OK;
|
| }
|
|
|
| @@ -112,14 +113,12 @@ class BasicNetworkDelegate : public net::NetworkDelegate {
|
|
|
| namespace cronet {
|
|
|
| -URLRequestContextAdapter::URLRequestContextAdapter(
|
| - URLRequestContextAdapterDelegate* delegate,
|
| - std::string user_agent) {
|
| +CronetURLRequestContextAdapter::CronetURLRequestContextAdapter(
|
| + CronetURLRequestContextAdapterDelegate* delegate) {
|
| delegate_ = delegate;
|
| - user_agent_ = user_agent;
|
| }
|
|
|
| -void URLRequestContextAdapter::Initialize(
|
| +void CronetURLRequestContextAdapter::Initialize(
|
| scoped_ptr<URLRequestContextConfig> config) {
|
| network_thread_ = new base::Thread("network");
|
| base::Thread::Options options;
|
| @@ -128,14 +127,13 @@ void URLRequestContextAdapter::Initialize(
|
|
|
| GetNetworkTaskRunner()->PostTask(
|
| FROM_HERE,
|
| - base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext,
|
| + base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
|
| this,
|
| Passed(&config)));
|
| }
|
|
|
| -void URLRequestContextAdapter::InitializeURLRequestContext(
|
| +void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
|
| scoped_ptr<URLRequestContextConfig> config) {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| // TODO(mmenke): Add method to have the builder enable SPDY.
|
| net::URLRequestContextBuilder context_builder;
|
| context_builder.set_network_delegate(new BasicNetworkDelegate());
|
| @@ -159,8 +157,7 @@ void URLRequestContextAdapter::InitializeURLRequestContext(
|
|
|
| if (quic_hint.port <= std::numeric_limits<uint16>::min() ||
|
| quic_hint.port > std::numeric_limits<uint16>::max()) {
|
| - LOG(ERROR) << "Invalid QUIC hint port: "
|
| - << quic_hint.port;
|
| + LOG(ERROR) << "Invalid QUIC hint port: " << quic_hint.port;
|
| continue;
|
| }
|
|
|
| @@ -179,60 +176,23 @@ void URLRequestContextAdapter::InitializeURLRequestContext(
|
| net::AlternateProtocol::QUIC,
|
| 1.0f);
|
| }
|
| - is_context_initialized_ = true;
|
| - while (!tasks_waiting_for_context_.empty()) {
|
| - tasks_waiting_for_context_.front().Run();
|
| - tasks_waiting_for_context_.pop();
|
| - }
|
| - }
|
| -
|
| - if (VLOG_IS_ON(2)) {
|
| - net_log_observer_.reset(new NetLogObserver());
|
| - context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(),
|
| - net::NetLog::LOG_ALL_BUT_BYTES);
|
| }
|
| + user_agent_ = config->user_agent;
|
|
|
| delegate_->OnContextInitialized(this);
|
| }
|
|
|
| -void URLRequestContextAdapter::PostTaskToNetworkThread(
|
| - const tracked_objects::Location& posted_from,
|
| - const RunAfterContextInitTask& callback) {
|
| - GetNetworkTaskRunner()->PostTask(
|
| - posted_from,
|
| - base::Bind(
|
| - &URLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread,
|
| - this,
|
| - callback));
|
| -}
|
| -
|
| -void URLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread(
|
| - const RunAfterContextInitTask& callback) {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| - if (is_context_initialized_) {
|
| - callback.Run();
|
| - return;
|
| - }
|
| - tasks_waiting_for_context_.push(callback);
|
| -}
|
| -
|
| -URLRequestContextAdapter::~URLRequestContextAdapter() {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| - if (net_log_observer_) {
|
| - context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get());
|
| - net_log_observer_.reset();
|
| - }
|
| - StopNetLogHelper();
|
| +CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
|
| + StopNetLog();
|
| // TODO(mef): Ensure that |network_thread_| is destroyed properly.
|
| }
|
|
|
| -const std::string& URLRequestContextAdapter::GetUserAgent(
|
| +const std::string& CronetURLRequestContextAdapter::GetUserAgent(
|
| const GURL& url) const {
|
| return user_agent_;
|
| }
|
|
|
| -net::URLRequestContext* URLRequestContextAdapter::GetURLRequestContext() {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| +net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() {
|
| if (!context_) {
|
| LOG(ERROR) << "URLRequestContext is not set up";
|
| }
|
| @@ -240,25 +200,29 @@ net::URLRequestContext* URLRequestContextAdapter::GetURLRequestContext() {
|
| }
|
|
|
| scoped_refptr<base::SingleThreadTaskRunner>
|
| -URLRequestContextAdapter::GetNetworkTaskRunner() const {
|
| +CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
|
| return network_thread_->message_loop_proxy();
|
| }
|
|
|
| -void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) {
|
| - PostTaskToNetworkThread(
|
| +void CronetURLRequestContextAdapter::StartNetLogToFile(
|
| + const std::string& file_name) {
|
| + GetNetworkTaskRunner()->PostTask(
|
| FROM_HERE,
|
| base::Bind(
|
| - &URLRequestContextAdapter::StartNetLogToFileHelper, this, file_name));
|
| + &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread,
|
| + this,
|
| + file_name));
|
| }
|
|
|
| -void URLRequestContextAdapter::StopNetLog() {
|
| - PostTaskToNetworkThread(
|
| - FROM_HERE, base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this));
|
| +void CronetURLRequestContextAdapter::StopNetLog() {
|
| + GetNetworkTaskRunner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread,
|
| + this));
|
| }
|
|
|
| -void URLRequestContextAdapter::StartNetLogToFileHelper(
|
| +void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread(
|
| const std::string& file_name) {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| // Do nothing if already logging to a file.
|
| if (net_log_logger_)
|
| return;
|
| @@ -273,17 +237,11 @@ void URLRequestContextAdapter::StartNetLogToFileHelper(
|
| net_log_logger_->StartObserving(context_->net_log());
|
| }
|
|
|
| -void URLRequestContextAdapter::StopNetLogHelper() {
|
| - DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
|
| +void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() {
|
| if (net_log_logger_) {
|
| net_log_logger_->StopObserving();
|
| net_log_logger_.reset();
|
| }
|
| }
|
|
|
| -void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
|
| - VLOG(2) << "Net log entry: type=" << entry.type()
|
| - << ", source=" << entry.source().type << ", phase=" << entry.phase();
|
| -}
|
| -
|
| } // namespace cronet
|
|
|