Chromium Code Reviews| Index: ios/chrome/browser/ios_chrome_io_thread.mm |
| diff --git a/ios/chrome/browser/ios_chrome_io_thread.mm b/ios/chrome/browser/ios_chrome_io_thread.mm |
| index 22fc9c5d63ea76b7f38680d87d3bf72ead16e01d..adb4196f293009bf1205466c7c664b739ee96126 100644 |
| --- a/ios/chrome/browser/ios_chrome_io_thread.mm |
| +++ b/ios/chrome/browser/ios_chrome_io_thread.mm |
| @@ -205,6 +205,9 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| const override; |
| + // Tells the getter that the URLRequestContext is about to be shut down. |
| + void Shutdown(); |
| + |
| protected: |
| ~SystemURLRequestContextGetter() override; |
| @@ -212,6 +215,7 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| IOSChromeIOThread* const |
| io_thread_; // Weak pointer, owned by ApplicationContext. |
| scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| + bool shutting_down_; |
| base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| }; |
| @@ -220,12 +224,15 @@ SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| IOSChromeIOThread* io_thread) |
| : io_thread_(io_thread), |
| network_task_runner_( |
| - web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {} |
| + web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)), |
| + shutting_down_(false) {} |
| SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| + 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.
|
| + return nullptr; |
| DCHECK(io_thread_->globals()->system_request_context.get()); |
| return io_thread_->globals()->system_request_context.get(); |
| @@ -236,6 +243,12 @@ SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| return network_task_runner_; |
| } |
| +void SystemURLRequestContextGetter::Shutdown() { |
| + DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| + shutting_down_ = true; |
| + NotifyContextShuttingDown(); |
| +} |
| + |
| IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: |
| SystemRequestContextLeakChecker(Globals* globals) |
| : globals_(globals) { |
| @@ -423,6 +436,7 @@ void IOSChromeIOThread::Init() { |
| } |
| void IOSChromeIOThread::CleanUp() { |
| + system_url_request_context_getter_->Shutdown(); |
| system_url_request_context_getter_ = nullptr; |
| // Release objects that the net::URLRequestContext could have been pointing |