OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ios_chrome_io_thread.h" | 5 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 | 198 |
199 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { | 199 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
200 public: | 200 public: |
201 explicit SystemURLRequestContextGetter(IOSChromeIOThread* io_thread); | 201 explicit SystemURLRequestContextGetter(IOSChromeIOThread* io_thread); |
202 | 202 |
203 // Implementation for net::UrlRequestContextGetter. | 203 // Implementation for net::UrlRequestContextGetter. |
204 net::URLRequestContext* GetURLRequestContext() override; | 204 net::URLRequestContext* GetURLRequestContext() override; |
205 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 205 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
206 const override; | 206 const override; |
207 | 207 |
208 // Tells the getter that the URLRequestContext is about to be shut down. | |
209 void Shutdown(); | |
210 | |
208 protected: | 211 protected: |
209 ~SystemURLRequestContextGetter() override; | 212 ~SystemURLRequestContextGetter() override; |
210 | 213 |
211 private: | 214 private: |
212 IOSChromeIOThread* const | 215 IOSChromeIOThread* const |
213 io_thread_; // Weak pointer, owned by ApplicationContext. | 216 io_thread_; // Weak pointer, owned by ApplicationContext. |
214 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 217 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
218 bool shutting_down_; | |
215 | 219 |
216 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; | 220 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
217 }; | 221 }; |
218 | 222 |
219 SystemURLRequestContextGetter::SystemURLRequestContextGetter( | 223 SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
220 IOSChromeIOThread* io_thread) | 224 IOSChromeIOThread* io_thread) |
221 : io_thread_(io_thread), | 225 : io_thread_(io_thread), |
222 network_task_runner_( | 226 network_task_runner_( |
223 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {} | 227 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)), |
228 shutting_down_(false) {} | |
224 | 229 |
225 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} | 230 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
226 | 231 |
227 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { | 232 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
228 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 233 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
234 if (shutting_down_) | |
mmenke
2016/07/27 17:23:45
Could null out io_thread_ instead, don't think it
mef
2016/07/27 18:04:27
Done.
| |
235 return nullptr; | |
229 DCHECK(io_thread_->globals()->system_request_context.get()); | 236 DCHECK(io_thread_->globals()->system_request_context.get()); |
230 | 237 |
231 return io_thread_->globals()->system_request_context.get(); | 238 return io_thread_->globals()->system_request_context.get(); |
232 } | 239 } |
233 | 240 |
234 scoped_refptr<base::SingleThreadTaskRunner> | 241 scoped_refptr<base::SingleThreadTaskRunner> |
235 SystemURLRequestContextGetter::GetNetworkTaskRunner() const { | 242 SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
236 return network_task_runner_; | 243 return network_task_runner_; |
237 } | 244 } |
238 | 245 |
246 void SystemURLRequestContextGetter::Shutdown() { | |
247 DCHECK_CURRENTLY_ON(web::WebThread::IO); | |
248 shutting_down_ = true; | |
249 NotifyContextShuttingDown(); | |
250 } | |
251 | |
239 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: | 252 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: |
240 SystemRequestContextLeakChecker(Globals* globals) | 253 SystemRequestContextLeakChecker(Globals* globals) |
241 : globals_(globals) { | 254 : globals_(globals) { |
242 DCHECK(globals_); | 255 DCHECK(globals_); |
243 } | 256 } |
244 | 257 |
245 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: | 258 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: |
246 ~SystemRequestContextLeakChecker() { | 259 ~SystemRequestContextLeakChecker() { |
247 if (globals_->system_request_context.get()) | 260 if (globals_->system_request_context.get()) |
248 globals_->system_request_context->AssertNoURLRequests(); | 261 globals_->system_request_context->AssertNoURLRequests(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 // get it onto the message loop while the IOSChromeIOThread object still | 429 // get it onto the message loop while the IOSChromeIOThread object still |
417 // exists. However, the message might not be processed on the UI | 430 // exists. However, the message might not be processed on the UI |
418 // thread until after IOSChromeIOThread is gone, so use a weak pointer. | 431 // thread until after IOSChromeIOThread is gone, so use a weak pointer. |
419 web::WebThread::PostTask( | 432 web::WebThread::PostTask( |
420 web::WebThread::UI, FROM_HERE, | 433 web::WebThread::UI, FROM_HERE, |
421 base::Bind(&IOSChromeIOThread::InitSystemRequestContext, | 434 base::Bind(&IOSChromeIOThread::InitSystemRequestContext, |
422 weak_factory_.GetWeakPtr())); | 435 weak_factory_.GetWeakPtr())); |
423 } | 436 } |
424 | 437 |
425 void IOSChromeIOThread::CleanUp() { | 438 void IOSChromeIOThread::CleanUp() { |
439 system_url_request_context_getter_->Shutdown(); | |
426 system_url_request_context_getter_ = nullptr; | 440 system_url_request_context_getter_ = nullptr; |
427 | 441 |
428 // Release objects that the net::URLRequestContext could have been pointing | 442 // Release objects that the net::URLRequestContext could have been pointing |
429 // to. | 443 // to. |
430 | 444 |
431 // Shutdown the HistogramWatcher on the IO thread. | 445 // Shutdown the HistogramWatcher on the IO thread. |
432 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); | 446 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); |
433 | 447 |
434 // This must be reset before the ChromeNetLog is destroyed. | 448 // This must be reset before the ChromeNetLog is destroyed. |
435 network_change_observer_.reset(); | 449 network_change_observer_.reset(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 | 573 |
560 globals->system_http_network_session.reset( | 574 globals->system_http_network_session.reset( |
561 new net::HttpNetworkSession(system_params)); | 575 new net::HttpNetworkSession(system_params)); |
562 globals->system_http_transaction_factory.reset( | 576 globals->system_http_transaction_factory.reset( |
563 new net::HttpNetworkLayer(globals->system_http_network_session.get())); | 577 new net::HttpNetworkLayer(globals->system_http_network_session.get())); |
564 context->set_http_transaction_factory( | 578 context->set_http_transaction_factory( |
565 globals->system_http_transaction_factory.get()); | 579 globals->system_http_transaction_factory.get()); |
566 | 580 |
567 return context; | 581 return context; |
568 } | 582 } |
OLD | NEW |