| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
| 13 #include "chrome/browser/net/chrome_net_log.h" | 13 #include "chrome/browser/net/chrome_net_log.h" |
| 14 #include "chrome/browser/net/chrome_network_delegate.h" | 14 #include "chrome/browser/net/chrome_network_delegate.h" |
| 15 #include "chrome/browser/net/connect_interceptor.h" |
| 16 #include "chrome/browser/net/predictor.h" |
| 15 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" | 17 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" |
| 16 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 18 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 17 #include "chrome/browser/prefs/pref_member.h" | 19 #include "chrome/browser/prefs/pref_member.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 23 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
| 24 #include "content/browser/resource_context.h" | 26 #include "content/browser/resource_context.h" |
| 25 #include "net/base/origin_bound_cert_service.h" | 27 #include "net/base/origin_bound_cert_service.h" |
| 26 #include "net/ftp/ftp_network_layer.h" | 28 #include "net/ftp/ftp_network_layer.h" |
| 27 #include "net/http/http_cache.h" | 29 #include "net/http/http_cache.h" |
| 30 #include "net/url_request/url_request_job_factory.h" |
| 28 | 31 |
| 29 ProfileImplIOData::Handle::Handle(Profile* profile) | 32 ProfileImplIOData::Handle::Handle(Profile* profile) |
| 30 : io_data_(new ProfileImplIOData), | 33 : io_data_(new ProfileImplIOData), |
| 31 profile_(profile), | 34 profile_(profile), |
| 32 initialized_(false) { | 35 initialized_(false) { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 34 DCHECK(profile); | 37 DCHECK(profile); |
| 35 } | 38 } |
| 36 | 39 |
| 37 ProfileImplIOData::Handle::~Handle() { | 40 ProfileImplIOData::Handle::~Handle() { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 if (main_request_context_getter_) | 42 if (main_request_context_getter_) |
| 40 main_request_context_getter_->CleanupOnUIThread(); | 43 main_request_context_getter_->CleanupOnUIThread(); |
| 41 if (media_request_context_getter_) | 44 if (media_request_context_getter_) |
| 42 media_request_context_getter_->CleanupOnUIThread(); | 45 media_request_context_getter_->CleanupOnUIThread(); |
| 43 if (extensions_request_context_getter_) | 46 if (extensions_request_context_getter_) |
| 44 extensions_request_context_getter_->CleanupOnUIThread(); | 47 extensions_request_context_getter_->CleanupOnUIThread(); |
| 45 | 48 |
| 49 io_data_->predictor_->ShutdownOnUIThread(profile_->GetPrefs()); |
| 50 |
| 46 // Clean up all isolated app request contexts. | 51 // Clean up all isolated app request contexts. |
| 47 for (ChromeURLRequestContextGetterMap::iterator iter = | 52 for (ChromeURLRequestContextGetterMap::iterator iter = |
| 48 app_request_context_getter_map_.begin(); | 53 app_request_context_getter_map_.begin(); |
| 49 iter != app_request_context_getter_map_.end(); | 54 iter != app_request_context_getter_map_.end(); |
| 50 ++iter) { | 55 ++iter) { |
| 51 iter->second->CleanupOnUIThread(); | 56 iter->second->CleanupOnUIThread(); |
| 52 } | 57 } |
| 53 | 58 |
| 54 io_data_->ShutdownOnUIThread(); | 59 io_data_->ShutdownOnUIThread(); |
| 55 } | 60 } |
| 56 | 61 |
| 57 void ProfileImplIOData::Handle::Init(const FilePath& cookie_path, | 62 void ProfileImplIOData::Handle::Init( |
| 58 const FilePath& origin_bound_cert_path, | 63 const FilePath& cookie_path, |
| 59 const FilePath& cache_path, | 64 const FilePath& origin_bound_cert_path, |
| 60 int cache_max_size, | 65 const FilePath& cache_path, |
| 61 const FilePath& media_cache_path, | 66 int cache_max_size, |
| 62 int media_cache_max_size, | 67 const FilePath& media_cache_path, |
| 63 const FilePath& extensions_cookie_path, | 68 int media_cache_max_size, |
| 64 const FilePath& app_path) { | 69 const FilePath& extensions_cookie_path, |
| 70 const FilePath& app_path, |
| 71 chrome_browser_net::Predictor* predictor, |
| 72 PrefService* local_state, |
| 73 IOThread* io_thread) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 66 DCHECK(!io_data_->lazy_params_.get()); | 75 DCHECK(!io_data_->lazy_params_.get()); |
| 76 DCHECK(predictor); |
| 77 |
| 67 LazyParams* lazy_params = new LazyParams; | 78 LazyParams* lazy_params = new LazyParams; |
| 68 | 79 |
| 69 lazy_params->cookie_path = cookie_path; | 80 lazy_params->cookie_path = cookie_path; |
| 70 lazy_params->origin_bound_cert_path = origin_bound_cert_path; | 81 lazy_params->origin_bound_cert_path = origin_bound_cert_path; |
| 71 lazy_params->cache_path = cache_path; | 82 lazy_params->cache_path = cache_path; |
| 72 lazy_params->cache_max_size = cache_max_size; | 83 lazy_params->cache_max_size = cache_max_size; |
| 73 lazy_params->media_cache_path = media_cache_path; | 84 lazy_params->media_cache_path = media_cache_path; |
| 74 lazy_params->media_cache_max_size = media_cache_max_size; | 85 lazy_params->media_cache_max_size = media_cache_max_size; |
| 75 lazy_params->extensions_cookie_path = extensions_cookie_path; | 86 lazy_params->extensions_cookie_path = extensions_cookie_path; |
| 76 | 87 |
| 77 io_data_->lazy_params_.reset(lazy_params); | 88 io_data_->lazy_params_.reset(lazy_params); |
| 78 | 89 |
| 79 // Keep track of isolated app path separately so we can use it on demand. | 90 // Keep track of isolated app path separately so we can use it on demand. |
| 80 io_data_->app_path_ = app_path; | 91 io_data_->app_path_ = app_path; |
| 92 |
| 93 io_data_->predictor_.reset(predictor); |
| 94 io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), |
| 95 local_state, |
| 96 io_thread); |
| 81 } | 97 } |
| 82 | 98 |
| 83 base::Callback<ChromeURLDataManagerBackend*(void)> | 99 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 84 ProfileImplIOData::Handle::GetChromeURLDataManagerBackendGetter() const { | 100 ProfileImplIOData::Handle::GetChromeURLDataManagerBackendGetter() const { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 86 LazyInitialize(); | 102 LazyInitialize(); |
| 87 return base::Bind(&ProfileIOData::GetChromeURLDataManagerBackend, | 103 return base::Bind(&ProfileIOData::GetChromeURLDataManagerBackend, |
| 88 base::Unretained(io_data_)); | 104 base::Unretained(io_data_)); |
| 89 } | 105 } |
| 90 | 106 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 main_context->set_ftp_transaction_factory( | 345 main_context->set_ftp_transaction_factory( |
| 330 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 346 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
| 331 | 347 |
| 332 main_context->set_chrome_url_data_manager_backend( | 348 main_context->set_chrome_url_data_manager_backend( |
| 333 chrome_url_data_manager_backend()); | 349 chrome_url_data_manager_backend()); |
| 334 | 350 |
| 335 main_context->set_job_factory(job_factory()); | 351 main_context->set_job_factory(job_factory()); |
| 336 media_request_context_->set_job_factory(job_factory()); | 352 media_request_context_->set_job_factory(job_factory()); |
| 337 extensions_context->set_job_factory(job_factory()); | 353 extensions_context->set_job_factory(job_factory()); |
| 338 | 354 |
| 355 job_factory()->AddInterceptor( |
| 356 new chrome_browser_net::ConnectInterceptor(predictor_.get())); |
| 357 |
| 339 lazy_params_.reset(); | 358 lazy_params_.reset(); |
| 340 } | 359 } |
| 341 | 360 |
| 342 scoped_refptr<ChromeURLRequestContext> | 361 scoped_refptr<ChromeURLRequestContext> |
| 343 ProfileImplIOData::InitializeAppRequestContext( | 362 ProfileImplIOData::InitializeAppRequestContext( |
| 344 scoped_refptr<ChromeURLRequestContext> main_context, | 363 scoped_refptr<ChromeURLRequestContext> main_context, |
| 345 const std::string& app_id) const { | 364 const std::string& app_id) const { |
| 346 AppRequestContext* context = new AppRequestContext; | 365 AppRequestContext* context = new AppRequestContext; |
| 347 | 366 |
| 348 // Copy most state from the main context. | 367 // Copy most state from the main context. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 scoped_refptr<ChromeURLRequestContext> | 429 scoped_refptr<ChromeURLRequestContext> |
| 411 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 430 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
| 412 scoped_refptr<ChromeURLRequestContext> main_context, | 431 scoped_refptr<ChromeURLRequestContext> main_context, |
| 413 const std::string& app_id) const { | 432 const std::string& app_id) const { |
| 414 // We create per-app contexts on demand, unlike the others above. | 433 // We create per-app contexts on demand, unlike the others above. |
| 415 scoped_refptr<ChromeURLRequestContext> app_request_context = | 434 scoped_refptr<ChromeURLRequestContext> app_request_context = |
| 416 InitializeAppRequestContext(main_context, app_id); | 435 InitializeAppRequestContext(main_context, app_id); |
| 417 DCHECK(app_request_context); | 436 DCHECK(app_request_context); |
| 418 return app_request_context; | 437 return app_request_context; |
| 419 } | 438 } |
| OLD | NEW |