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

Side by Side Diff: ios/chrome/browser/ios_chrome_io_thread.mm

Issue 2170103002: Notify SystemURLRequestContextGetter before shutdown on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Few more comments. Created 4 years, 4 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 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
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* io_thread_; // Weak pointer, owned by ApplicationContext.
213 io_thread_; // Weak pointer, owned by ApplicationContext.
214 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 216 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
215 217
216 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; 218 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
217 }; 219 };
218 220
219 SystemURLRequestContextGetter::SystemURLRequestContextGetter( 221 SystemURLRequestContextGetter::SystemURLRequestContextGetter(
220 IOSChromeIOThread* io_thread) 222 IOSChromeIOThread* io_thread)
221 : io_thread_(io_thread), 223 : io_thread_(io_thread),
222 network_task_runner_( 224 network_task_runner_(
223 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {} 225 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {}
224 226
225 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} 227 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
226 228
227 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { 229 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
228 DCHECK_CURRENTLY_ON(web::WebThread::IO); 230 DCHECK_CURRENTLY_ON(web::WebThread::IO);
231 if (!io_thread_)
232 return nullptr;
229 DCHECK(io_thread_->globals()->system_request_context.get()); 233 DCHECK(io_thread_->globals()->system_request_context.get());
230 234
231 return io_thread_->globals()->system_request_context.get(); 235 return io_thread_->globals()->system_request_context.get();
232 } 236 }
233 237
234 scoped_refptr<base::SingleThreadTaskRunner> 238 scoped_refptr<base::SingleThreadTaskRunner>
235 SystemURLRequestContextGetter::GetNetworkTaskRunner() const { 239 SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
236 return network_task_runner_; 240 return network_task_runner_;
237 } 241 }
238 242
243 void SystemURLRequestContextGetter::Shutdown() {
244 DCHECK_CURRENTLY_ON(web::WebThread::IO);
245 io_thread_ = nullptr;
246 NotifyContextShuttingDown();
247 }
248
239 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: 249 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
240 SystemRequestContextLeakChecker(Globals* globals) 250 SystemRequestContextLeakChecker(Globals* globals)
241 : globals_(globals) { 251 : globals_(globals) {
242 DCHECK(globals_); 252 DCHECK(globals_);
243 } 253 }
244 254
245 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: 255 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
246 ~SystemRequestContextLeakChecker() { 256 ~SystemRequestContextLeakChecker() {
247 if (globals_->system_request_context.get()) 257 if (globals_->system_request_context.get())
248 globals_->system_request_context->AssertNoURLRequests(); 258 globals_->system_request_context->AssertNoURLRequests();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // get it onto the message loop while the IOSChromeIOThread object still 426 // get it onto the message loop while the IOSChromeIOThread object still
417 // exists. However, the message might not be processed on the UI 427 // exists. However, the message might not be processed on the UI
418 // thread until after IOSChromeIOThread is gone, so use a weak pointer. 428 // thread until after IOSChromeIOThread is gone, so use a weak pointer.
419 web::WebThread::PostTask( 429 web::WebThread::PostTask(
420 web::WebThread::UI, FROM_HERE, 430 web::WebThread::UI, FROM_HERE,
421 base::Bind(&IOSChromeIOThread::InitSystemRequestContext, 431 base::Bind(&IOSChromeIOThread::InitSystemRequestContext,
422 weak_factory_.GetWeakPtr())); 432 weak_factory_.GetWeakPtr()));
423 } 433 }
424 434
425 void IOSChromeIOThread::CleanUp() { 435 void IOSChromeIOThread::CleanUp() {
436 system_url_request_context_getter_->Shutdown();
426 system_url_request_context_getter_ = nullptr; 437 system_url_request_context_getter_ = nullptr;
427 438
428 // Release objects that the net::URLRequestContext could have been pointing 439 // Release objects that the net::URLRequestContext could have been pointing
429 // to. 440 // to.
430 441
431 // Shutdown the HistogramWatcher on the IO thread. 442 // Shutdown the HistogramWatcher on the IO thread.
432 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 443 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
433 444
434 // This must be reset before the ChromeNetLog is destroyed. 445 // This must be reset before the ChromeNetLog is destroyed.
435 network_change_observer_.reset(); 446 network_change_observer_.reset();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 570
560 globals->system_http_network_session.reset( 571 globals->system_http_network_session.reset(
561 new net::HttpNetworkSession(system_params)); 572 new net::HttpNetworkSession(system_params));
562 globals->system_http_transaction_factory.reset( 573 globals->system_http_transaction_factory.reset(
563 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 574 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
564 context->set_http_transaction_factory( 575 context->set_http_transaction_factory(
565 globals->system_http_transaction_factory.get()); 576 globals->system_http_transaction_factory.get());
566 577
567 return context; 578 return context;
568 } 579 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ios_chrome_io_thread.h ('k') | ios/chrome/browser/ios_chrome_io_thread_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698