| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/cronet/android/url_request_context_adapter.h" | 5 #include "components/cronet/android/url_request_context_adapter.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "net/http/http_server_properties.h" | 23 #include "net/http/http_server_properties.h" |
| 24 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
| 25 #include "net/ssl/ssl_config_service_defaults.h" | 25 #include "net/ssl/ssl_config_service_defaults.h" |
| 26 #include "net/url_request/static_http_user_agent_settings.h" | 26 #include "net/url_request/static_http_user_agent_settings.h" |
| 27 #include "net/url_request/url_request_context_builder.h" | 27 #include "net/url_request/url_request_context_builder.h" |
| 28 #include "net/url_request/url_request_context_storage.h" | 28 #include "net/url_request/url_request_context_storage.h" |
| 29 #include "net/url_request/url_request_job_factory_impl.h" | 29 #include "net/url_request/url_request_job_factory_impl.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // MessageLoop on the main thread, which is where objects that receive Java | |
| 34 // notifications generally live. | |
| 35 base::MessageLoop* g_main_message_loop = nullptr; | |
| 36 | |
| 37 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; | |
| 38 | |
| 39 class BasicNetworkDelegate : public net::NetworkDelegateImpl { | 33 class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
| 40 public: | 34 public: |
| 41 BasicNetworkDelegate() {} | 35 BasicNetworkDelegate() {} |
| 42 virtual ~BasicNetworkDelegate() {} | 36 virtual ~BasicNetworkDelegate() {} |
| 43 | 37 |
| 44 private: | 38 private: |
| 45 // net::NetworkDelegate implementation. | 39 // net::NetworkDelegate implementation. |
| 46 int OnBeforeURLRequest(net::URLRequest* request, | 40 int OnBeforeURLRequest(net::URLRequest* request, |
| 47 const net::CompletionCallback& callback, | 41 const net::CompletionCallback& callback, |
| 48 GURL* new_url) override { | 42 GURL* new_url) override { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void URLRequestContextAdapter::Initialize( | 122 void URLRequestContextAdapter::Initialize( |
| 129 scoped_ptr<URLRequestContextConfig> config) { | 123 scoped_ptr<URLRequestContextConfig> config) { |
| 130 network_thread_ = new base::Thread("network"); | 124 network_thread_ = new base::Thread("network"); |
| 131 base::Thread::Options options; | 125 base::Thread::Options options; |
| 132 options.message_loop_type = base::MessageLoop::TYPE_IO; | 126 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 133 network_thread_->StartWithOptions(options); | 127 network_thread_->StartWithOptions(options); |
| 134 config_ = config.Pass(); | 128 config_ = config.Pass(); |
| 135 } | 129 } |
| 136 | 130 |
| 137 void URLRequestContextAdapter::InitRequestContextOnMainThread() { | 131 void URLRequestContextAdapter::InitRequestContextOnMainThread() { |
| 138 if (!base::MessageLoop::current()) { | |
| 139 DCHECK(!g_main_message_loop); | |
| 140 g_main_message_loop = new base::MessageLoopForUI(); | |
| 141 base::MessageLoopForUI::current()->Start(); | |
| 142 } | |
| 143 DCHECK_EQ(g_main_message_loop, base::MessageLoop::current()); | |
| 144 if (!g_network_change_notifier) { | |
| 145 net::NetworkChangeNotifier::SetFactory( | |
| 146 new net::NetworkChangeNotifierFactoryAndroid()); | |
| 147 g_network_change_notifier = net::NetworkChangeNotifier::Create(); | |
| 148 } | |
| 149 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( | 132 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( |
| 150 GetNetworkTaskRunner(), NULL)); | 133 GetNetworkTaskRunner(), NULL)); |
| 151 GetNetworkTaskRunner()->PostTask( | 134 GetNetworkTaskRunner()->PostTask( |
| 152 FROM_HERE, | 135 FROM_HERE, |
| 153 base::Bind(&URLRequestContextAdapter::InitRequestContextOnNetworkThread, | 136 base::Bind(&URLRequestContextAdapter::InitRequestContextOnNetworkThread, |
| 154 this)); | 137 this)); |
| 155 } | 138 } |
| 156 | 139 |
| 157 void URLRequestContextAdapter::InitRequestContextOnNetworkThread() { | 140 void URLRequestContextAdapter::InitRequestContextOnNetworkThread() { |
| 158 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 141 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 net_log_logger_.reset(); | 293 net_log_logger_.reset(); |
| 311 } | 294 } |
| 312 } | 295 } |
| 313 | 296 |
| 314 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 297 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
| 315 VLOG(2) << "Net log entry: type=" << entry.type() | 298 VLOG(2) << "Net log entry: type=" << entry.type() |
| 316 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 299 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
| 317 } | 300 } |
| 318 | 301 |
| 319 } // namespace cronet | 302 } // namespace cronet |
| OLD | NEW |