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 ~BasicNetworkDelegate() override {} | 36 ~BasicNetworkDelegate() override {} |
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 void URLRequestContextAdapter::Initialize( | 124 void URLRequestContextAdapter::Initialize( |
131 scoped_ptr<URLRequestContextConfig> config) { | 125 scoped_ptr<URLRequestContextConfig> config) { |
132 network_thread_ = new base::Thread("network"); | 126 network_thread_ = new base::Thread("network"); |
133 base::Thread::Options options; | 127 base::Thread::Options options; |
134 options.message_loop_type = base::MessageLoop::TYPE_IO; | 128 options.message_loop_type = base::MessageLoop::TYPE_IO; |
135 network_thread_->StartWithOptions(options); | 129 network_thread_->StartWithOptions(options); |
136 config_ = config.Pass(); | 130 config_ = config.Pass(); |
137 } | 131 } |
138 | 132 |
139 void URLRequestContextAdapter::InitRequestContextOnMainThread() { | 133 void URLRequestContextAdapter::InitRequestContextOnMainThread() { |
140 if (!base::MessageLoop::current()) { | |
141 DCHECK(!g_main_message_loop); | |
142 g_main_message_loop = new base::MessageLoopForUI(); | |
143 base::MessageLoopForUI::current()->Start(); | |
144 } | |
145 DCHECK_EQ(g_main_message_loop, base::MessageLoop::current()); | |
146 if (!g_network_change_notifier) { | |
147 net::NetworkChangeNotifier::SetFactory( | |
148 new net::NetworkChangeNotifierFactoryAndroid()); | |
149 g_network_change_notifier = net::NetworkChangeNotifier::Create(); | |
150 } | |
151 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( | 134 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( |
152 GetNetworkTaskRunner(), NULL)); | 135 GetNetworkTaskRunner(), NULL)); |
153 GetNetworkTaskRunner()->PostTask( | 136 GetNetworkTaskRunner()->PostTask( |
154 FROM_HERE, | 137 FROM_HERE, |
155 base::Bind(&URLRequestContextAdapter::InitRequestContextOnNetworkThread, | 138 base::Bind(&URLRequestContextAdapter::InitRequestContextOnNetworkThread, |
156 this)); | 139 this)); |
157 } | 140 } |
158 | 141 |
159 void URLRequestContextAdapter::InitRequestContextOnNetworkThread() { | 142 void URLRequestContextAdapter::InitRequestContextOnNetworkThread() { |
160 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 143 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 net_log_logger_.reset(); | 296 net_log_logger_.reset(); |
314 } | 297 } |
315 } | 298 } |
316 | 299 |
317 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 300 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
318 VLOG(2) << "Net log entry: type=" << entry.type() | 301 VLOG(2) << "Net log entry: type=" << entry.type() |
319 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 302 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
320 } | 303 } |
321 | 304 |
322 } // namespace cronet | 305 } // namespace cronet |
OLD | NEW |