Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 726013002: [Cronet] Hook up library loader, system proxy and network change notifier to async api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "components/cronet/url_request_context_config.h" 10 #include "components/cronet/url_request_context_config.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return false; 100 return false;
101 } 101 }
102 102
103 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); 103 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
104 }; 104 };
105 105
106 } // namespace 106 } // namespace
107 107
108 namespace cronet { 108 namespace cronet {
109 109
110 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter() { 110 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter()
111 : is_context_initialized_(false) {
112 network_thread_ = new base::Thread("network");
mmenke 2015/01/08 19:06:16 Should be in an initializer list.
mef 2015/01/08 21:17:02 Done.
113 base::Thread::Options options;
114 options.message_loop_type = base::MessageLoop::TYPE_IO;
115 network_thread_->StartWithOptions(options);
111 } 116 }
112 117
113 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { 118 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
114 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 119 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
115 StopNetLogOnNetworkThread(); 120 StopNetLogOnNetworkThread();
116 } 121 }
117 122
118 void CronetURLRequestContextAdapter::Initialize( 123 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
119 scoped_ptr<URLRequestContextConfig> config, 124 scoped_ptr<URLRequestContextConfig> config,
120 const base::Closure& java_init_network_thread) { 125 const base::Closure& java_init_network_thread) {
121 network_thread_ = new base::Thread("network"); 126 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
122 base::Thread::Options options; 127 GetNetworkTaskRunner(), NULL));
123 options.message_loop_type = base::MessageLoop::TYPE_IO;
124 network_thread_->StartWithOptions(options);
125
126 GetNetworkTaskRunner()->PostTask( 128 GetNetworkTaskRunner()->PostTask(
127 FROM_HERE, 129 FROM_HERE,
128 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, 130 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
129 base::Unretained(this), 131 base::Unretained(this),
130 Passed(&config), 132 Passed(&config),
131 java_init_network_thread)); 133 java_init_network_thread));
132 } 134 }
133 135
134 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 136 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
135 scoped_ptr<URLRequestContextConfig> config, 137 scoped_ptr<URLRequestContextConfig> config,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 quic_hint.port); 184 quic_hint.port);
183 context_->http_server_properties()->SetAlternateProtocol( 185 context_->http_server_properties()->SetAlternateProtocol(
184 quic_hint_host_port_pair, 186 quic_hint_host_port_pair,
185 static_cast<uint16>(quic_hint.alternate_port), 187 static_cast<uint16>(quic_hint.alternate_port),
186 net::AlternateProtocol::QUIC, 188 net::AlternateProtocol::QUIC,
187 1.0f); 189 1.0f);
188 } 190 }
189 } 191 }
190 192
191 java_init_network_thread.Run(); 193 java_init_network_thread.Run();
194
195 is_context_initialized_ = true;
196 while (!tasks_waiting_for_context_.empty()) {
197 tasks_waiting_for_context_.front().Run();
198 tasks_waiting_for_context_.pop();
199 }
192 } 200 }
193 201
194 void CronetURLRequestContextAdapter::Destroy() { 202 void CronetURLRequestContextAdapter::Destroy() {
195 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); 203 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread());
196 // Stick network_thread_ in a local, as |this| may be destroyed from the 204 // Stick network_thread_ in a local, as |this| may be destroyed from the
197 // network thread before delete network_thread is called. 205 // network thread before delete network_thread is called.
198 base::Thread* network_thread = network_thread_; 206 base::Thread* network_thread = network_thread_;
199 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this); 207 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this);
200 // Deleting thread stops it after all tasks are completed. 208 // Deleting thread stops it after all tasks are completed.
201 delete network_thread; 209 delete network_thread;
202 } 210 }
203 211
204 net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() { 212 net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() {
205 if (!context_) { 213 if (!context_) {
206 LOG(ERROR) << "URLRequestContext is not set up"; 214 LOG(ERROR) << "URLRequestContext is not set up";
207 } 215 }
208 return context_.get(); 216 return context_.get();
209 } 217 }
210 218
219 void CronetURLRequestContextAdapter::PostTaskToNetworkThread(
220 const tracked_objects::Location& posted_from,
221 const RunAfterContextInitTask& callback) {
222 GetNetworkTaskRunner()->PostTask(
223 posted_from, base::Bind(&CronetURLRequestContextAdapter::
224 RunTaskAfterContextInitOnNetworkThread,
225 base::Unretained(this), callback));
226 }
227
228 void CronetURLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread(
229 const RunAfterContextInitTask& callback) {
230 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
231 if (is_context_initialized_) {
232 callback.Run();
233 return;
234 }
235 tasks_waiting_for_context_.push(callback);
236 }
237
211 scoped_refptr<base::SingleThreadTaskRunner> 238 scoped_refptr<base::SingleThreadTaskRunner>
212 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { 239 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
213 return network_thread_->task_runner(); 240 return network_thread_->task_runner();
214 } 241 }
215 242
216 void CronetURLRequestContextAdapter::StartNetLogToFile( 243 void CronetURLRequestContextAdapter::StartNetLogToFile(
217 const std::string& file_name) { 244 const std::string& file_name) {
218 GetNetworkTaskRunner()->PostTask( 245 GetNetworkTaskRunner()->PostTask(
219 FROM_HERE, 246 FROM_HERE,
220 base::Bind( 247 base::Bind(
(...skipping 28 matching lines...) Expand all
249 276
250 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { 277 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() {
251 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 278 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
252 if (net_log_logger_) { 279 if (net_log_logger_) {
253 net_log_logger_->StopObserving(); 280 net_log_logger_->StopObserving();
254 net_log_logger_.reset(); 281 net_log_logger_.reset();
255 } 282 }
256 } 283 }
257 284
258 } // namespace cronet 285 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698