Chromium Code Reviews| 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 70% |
| copy from components/cronet/android/url_request_context_adapter.cc |
| copy to components/cronet/android/cronet_url_request_context_adapter.cc |
| index ffd934459d400c98f35a6299fbefd5653e5b50fd..d06b05e36879a42e1dd7c08d3acf800b030192ff 100644 |
| --- a/components/cronet/android/url_request_context_adapter.cc |
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
| @@ -2,9 +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 <limits> |
| +#include "components/cronet/android/cronet_url_request_context_adapter.h" |
| #include "base/bind.h" |
| #include "base/files/file_util.h" |
| @@ -20,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" |
| @@ -114,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; |
| @@ -130,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()); |
|
xunjieli
2014/10/17 00:31:35
nit: suggest adding DCHECK(GetNetworkTaskRunner()-
mef
2014/10/17 20:19:42
Done.
|
| // TODO(mmenke): Add method to have the builder enable SPDY. |
| net::URLRequestContextBuilder context_builder; |
| context_builder.set_network_delegate(new BasicNetworkDelegate()); |
| @@ -161,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; |
| } |
| @@ -181,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"; |
| } |
| @@ -242,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; |
| @@ -275,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 |