Index: chrome/browser/profiles/profile_impl_io_data.cc |
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc |
index 5af118651a2aaa4c21d25a03237586d558a741d4..8cccd0f03cdd6daea468c38dcd9d1f9f18e02f2d 100644 |
--- a/chrome/browser/profiles/profile_impl_io_data.cc |
+++ b/chrome/browser/profiles/profile_impl_io_data.cc |
@@ -9,6 +9,8 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/metrics/field_trial.h" |
+#include "base/prefs/json_pref_store.h" |
+#include "base/prefs/pref_filter.h" |
#include "base/prefs/pref_member.h" |
#include "base/prefs/pref_service.h" |
#include "base/profiler/scoped_tracker.h" |
@@ -66,6 +68,9 @@ |
namespace { |
+// Seconds to delay writing persisted preferences to disk. |
+const int kPrefsCommitDelay = 10; |
+ |
net::BackendType ChooseCacheBackendType() { |
#if defined(OS_ANDROID) |
return net::CACHE_BACKEND_SIMPLE; |
@@ -402,9 +407,11 @@ ProfileImplIOData::LazyParams::~LazyParams() {} |
ProfileImplIOData::ProfileImplIOData() |
: ProfileIOData(Profile::REGULAR_PROFILE), |
+ network_store_commit_timer_(false, false), |
http_server_properties_manager_(NULL), |
app_cache_max_size_(0), |
- app_media_cache_max_size_(0) { |
+ app_media_cache_max_size_(0), |
+ factory_(this) { |
} |
ProfileImplIOData::~ProfileImplIOData() { |
@@ -424,6 +431,16 @@ void ProfileImplIOData::InitializeInternal( |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
"436671 ProfileImplIOData::InitializeInternal")); |
+ // Set up a persistent store for use by the network stack on the IO thread. |
+ base::FilePath network_json_store_filepath( |
+ profile_path_.Append(chrome::kNetworkPersistentStateFilename)); |
+ network_json_store_ = new JsonPrefStore( |
+ network_json_store_filepath, |
+ JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, |
+ BrowserThread::GetBlockingPool()), |
+ scoped_ptr<PrefFilter>()); |
+ network_json_store_->ReadPrefsAsync(nullptr); |
+ |
net::URLRequestContext* main_context = main_request_context(); |
IOThread* const io_thread = profile_params->io_thread; |
@@ -611,6 +628,7 @@ void ProfileImplIOData::InitializeInternal( |
sdch_manager_.reset(new net::SdchManager); |
sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
main_context->set_sdch_manager(sdch_manager_.get()); |
+ sdch_policy_->EnablePersistentStorage(network_json_store_.get()); |
// Create a media request context based on the main context, but using a |
// media cache. It shares the same job factory as the main context. |
@@ -853,3 +871,20 @@ void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
DCHECK(http_server_properties_manager_); |
http_server_properties_manager_->Clear(completion); |
} |
+ |
+void ProfileImplIOData::FlushPrefsToDisk() { |
+ network_json_store_->CommitPendingWrite(); |
+} |
+ |
+void ProfileImplIOData::OnPrefValueChanged(const std::string& key) { |
+ // Schedule a write to disk for the preferences. This will |
+ // reset (i.e. push out) any previously scheduled but untriggered |
+ // timer. In other words, if there's a lot of preference activity, |
+ // disk commit will be delayed until kPrefsCommitDelay seconds |
+ // after it stops. |
+ network_store_commit_timer_.Start( |
+ FROM_HERE, base::TimeDelta::FromSeconds(kPrefsCommitDelay), |
+ 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
|
+} |
+ |
+void ProfileImplIOData::OnInitializationCompleted(bool succeeded) {} |