Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/prefs/json_pref_store.h" | |
| 13 #include "base/prefs/pref_filter.h" | |
| 12 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
| 13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 14 #include "base/profiler/scoped_tracker.h" | 16 #include "base/profiler/scoped_tracker.h" |
| 15 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 17 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
| 20 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 #include "net/http/http_cache.h" | 61 #include "net/http/http_cache.h" |
| 60 #include "net/http/http_server_properties_manager.h" | 62 #include "net/http/http_server_properties_manager.h" |
| 61 #include "net/sdch/sdch_owner.h" | 63 #include "net/sdch/sdch_owner.h" |
| 62 #include "net/ssl/channel_id_service.h" | 64 #include "net/ssl/channel_id_service.h" |
| 63 #include "net/url_request/url_request_intercepting_job_factory.h" | 65 #include "net/url_request/url_request_intercepting_job_factory.h" |
| 64 #include "net/url_request/url_request_job_factory_impl.h" | 66 #include "net/url_request/url_request_job_factory_impl.h" |
| 65 #include "storage/browser/quota/special_storage_policy.h" | 67 #include "storage/browser/quota/special_storage_policy.h" |
| 66 | 68 |
| 67 namespace { | 69 namespace { |
| 68 | 70 |
| 71 // Seconds to delay writing persisted preferences to disk. | |
| 72 const int kPrefsCommitDelay = 10; | |
| 73 | |
| 69 net::BackendType ChooseCacheBackendType() { | 74 net::BackendType ChooseCacheBackendType() { |
| 70 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
| 71 return net::CACHE_BACKEND_SIMPLE; | 76 return net::CACHE_BACKEND_SIMPLE; |
| 72 #else | 77 #else |
| 73 const base::CommandLine& command_line = | 78 const base::CommandLine& command_line = |
| 74 *base::CommandLine::ForCurrentProcess(); | 79 *base::CommandLine::ForCurrentProcess(); |
| 75 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { | 80 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { |
| 76 const std::string opt_value = | 81 const std::string opt_value = |
| 77 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); | 82 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); |
| 78 if (LowerCaseEqualsASCII(opt_value, "off")) | 83 if (LowerCaseEqualsASCII(opt_value, "off")) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 ProfileImplIOData::LazyParams::LazyParams() | 400 ProfileImplIOData::LazyParams::LazyParams() |
| 396 : cache_max_size(0), | 401 : cache_max_size(0), |
| 397 media_cache_max_size(0), | 402 media_cache_max_size(0), |
| 398 session_cookie_mode( | 403 session_cookie_mode( |
| 399 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES) {} | 404 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES) {} |
| 400 | 405 |
| 401 ProfileImplIOData::LazyParams::~LazyParams() {} | 406 ProfileImplIOData::LazyParams::~LazyParams() {} |
| 402 | 407 |
| 403 ProfileImplIOData::ProfileImplIOData() | 408 ProfileImplIOData::ProfileImplIOData() |
| 404 : ProfileIOData(Profile::REGULAR_PROFILE), | 409 : ProfileIOData(Profile::REGULAR_PROFILE), |
| 410 network_store_commit_timer_(false, false), | |
| 405 http_server_properties_manager_(NULL), | 411 http_server_properties_manager_(NULL), |
| 406 app_cache_max_size_(0), | 412 app_cache_max_size_(0), |
| 407 app_media_cache_max_size_(0) { | 413 app_media_cache_max_size_(0), |
| 414 factory_(this) { | |
| 408 } | 415 } |
| 409 | 416 |
| 410 ProfileImplIOData::~ProfileImplIOData() { | 417 ProfileImplIOData::~ProfileImplIOData() { |
| 411 DestroyResourceContext(); | 418 DestroyResourceContext(); |
| 412 | 419 |
| 413 if (media_request_context_) | 420 if (media_request_context_) |
| 414 media_request_context_->AssertNoURLRequests(); | 421 media_request_context_->AssertNoURLRequests(); |
| 415 } | 422 } |
| 416 | 423 |
| 417 void ProfileImplIOData::InitializeInternal( | 424 void ProfileImplIOData::InitializeInternal( |
| 418 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate, | 425 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate, |
| 419 ProfileParams* profile_params, | 426 ProfileParams* profile_params, |
| 420 content::ProtocolHandlerMap* protocol_handlers, | 427 content::ProtocolHandlerMap* protocol_handlers, |
| 421 content::URLRequestInterceptorScopedVector request_interceptors) const { | 428 content::URLRequestInterceptorScopedVector request_interceptors) const { |
| 422 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | 429 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. |
| 423 tracked_objects::ScopedTracker tracking_profile( | 430 tracked_objects::ScopedTracker tracking_profile( |
| 424 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 431 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 425 "436671 ProfileImplIOData::InitializeInternal")); | 432 "436671 ProfileImplIOData::InitializeInternal")); |
| 426 | 433 |
| 434 // Set up a persistent store for use by the network stack on the IO thread. | |
| 435 base::FilePath network_json_store_filepath( | |
| 436 profile_path_.Append(chrome::kNetworkPersistentStateFilename)); | |
| 437 network_json_store_ = new JsonPrefStore( | |
| 438 network_json_store_filepath, | |
| 439 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, | |
| 440 BrowserThread::GetBlockingPool()), | |
| 441 scoped_ptr<PrefFilter>()); | |
| 442 network_json_store_->ReadPrefsAsync(nullptr); | |
| 443 | |
| 427 net::URLRequestContext* main_context = main_request_context(); | 444 net::URLRequestContext* main_context = main_request_context(); |
| 428 | 445 |
| 429 IOThread* const io_thread = profile_params->io_thread; | 446 IOThread* const io_thread = profile_params->io_thread; |
| 430 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 447 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 431 | 448 |
| 432 chrome_network_delegate->set_predictor(predictor_.get()); | 449 chrome_network_delegate->set_predictor(predictor_.get()); |
| 433 | 450 |
| 434 if (domain_reliability_monitor_) { | 451 if (domain_reliability_monitor_) { |
| 435 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. | 452 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436671 is fixed. |
| 436 tracked_objects::ScopedTracker tracking_profile1( | 453 tracked_objects::ScopedTracker tracking_profile1( |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 "436671 ProfileImplIOData::InitializeInternal9")); | 621 "436671 ProfileImplIOData::InitializeInternal9")); |
| 605 | 622 |
| 606 #if defined(ENABLE_EXTENSIONS) | 623 #if defined(ENABLE_EXTENSIONS) |
| 607 InitializeExtensionsRequestContext(profile_params); | 624 InitializeExtensionsRequestContext(profile_params); |
| 608 #endif | 625 #endif |
| 609 | 626 |
| 610 // Setup SDCH for this profile. | 627 // Setup SDCH for this profile. |
| 611 sdch_manager_.reset(new net::SdchManager); | 628 sdch_manager_.reset(new net::SdchManager); |
| 612 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | 629 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
| 613 main_context->set_sdch_manager(sdch_manager_.get()); | 630 main_context->set_sdch_manager(sdch_manager_.get()); |
| 631 sdch_policy_->EnablePersistentStorage(network_json_store_.get()); | |
| 614 | 632 |
| 615 // Create a media request context based on the main context, but using a | 633 // Create a media request context based on the main context, but using a |
| 616 // media cache. It shares the same job factory as the main context. | 634 // media cache. It shares the same job factory as the main context. |
| 617 StoragePartitionDescriptor details(profile_path_, false); | 635 StoragePartitionDescriptor details(profile_path_, false); |
| 618 media_request_context_.reset(InitializeMediaRequestContext(main_context, | 636 media_request_context_.reset(InitializeMediaRequestContext(main_context, |
| 619 details)); | 637 details)); |
| 620 | 638 |
| 621 lazy_params_.reset(); | 639 lazy_params_.reset(); |
| 622 } | 640 } |
| 623 | 641 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 const base::Closure& completion) { | 864 const base::Closure& completion) { |
| 847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 848 DCHECK(initialized()); | 866 DCHECK(initialized()); |
| 849 | 867 |
| 850 DCHECK(transport_security_state()); | 868 DCHECK(transport_security_state()); |
| 851 // Completes synchronously. | 869 // Completes synchronously. |
| 852 transport_security_state()->DeleteAllDynamicDataSince(time); | 870 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 853 DCHECK(http_server_properties_manager_); | 871 DCHECK(http_server_properties_manager_); |
| 854 http_server_properties_manager_->Clear(completion); | 872 http_server_properties_manager_->Clear(completion); |
| 855 } | 873 } |
| 874 | |
| 875 void ProfileImplIOData::FlushPrefsToDisk() { | |
| 876 network_json_store_->CommitPendingWrite(); | |
| 877 } | |
| 878 | |
| 879 void ProfileImplIOData::OnPrefValueChanged(const std::string& key) { | |
| 880 // Schedule a write to disk for the preferences. This will | |
| 881 // reset (i.e. push out) any previously scheduled but untriggered | |
| 882 // timer. In other words, if there's a lot of preference activity, | |
| 883 // disk commit will be delayed until kPrefsCommitDelay seconds | |
| 884 // after it stops. | |
| 885 network_store_commit_timer_.Start( | |
| 886 FROM_HERE, base::TimeDelta::FromSeconds(kPrefsCommitDelay), | |
| 887 base::Bind(&ProfileImplIOData::FlushPrefsToDisk, factory_.GetWeakPtr())); | |
|
Bernhard Bauer
2015/02/02 14:39:46
JsonPrefStore has an internal timer that will comm
Randy Smith (Not in Mondays)
2015/02/04 19:29:03
That makes my life simpler! Much excess stuff rem
| |
| 888 } | |
| 889 | |
| 890 void ProfileImplIOData::OnInitializationCompleted(bool succeeded) {} | |
| OLD | NEW |