Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/prefs/profile_pref_store_manager.h" | 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/json_pref_store.h" | 12 #include "base/prefs/json_pref_store.h" |
| 13 #include "base/prefs/persistent_pref_store.h" | 13 #include "base/prefs/persistent_pref_store.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "chrome/browser/prefs/pref_hash_store_impl.h" | 15 #include "chrome/browser/prefs/pref_hash_store_impl.h" |
| 16 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 16 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
| 17 #include "chrome/browser/prefs/tracked/pref_store_hash_store_contents.h" | |
| 17 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" | 18 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" |
| 18 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | 19 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
| 19 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // An adaptor that allows a PrefHashStoreImpl to access a preference store | 26 // An in-memory PrefStore backed by an immutable DictionaryValue. |
| 26 // directly as a dictionary. Uses an equivalent layout to | 27 class DictionaryPrefStore : public WriteablePrefStore { |
| 27 // PrefStoreHashStoreContents. | |
| 28 class DictionaryHashStoreContents : public HashStoreContents { | |
| 29 public: | 28 public: |
| 30 // Instantiates a HashStoreContents that is a copy of |to_copy|. The copy is | 29 explicit DictionaryPrefStore(base::DictionaryValue* dictionary) |
| 31 // mutable but does not affect the original, nor is it persisted to disk in | |
| 32 // any other way. | |
| 33 explicit DictionaryHashStoreContents(const HashStoreContents& to_copy) | |
| 34 : hash_store_id_(to_copy.hash_store_id()), | |
| 35 super_mac_(to_copy.GetSuperMac()) { | |
| 36 if (to_copy.IsInitialized()) | |
| 37 dictionary_.reset(to_copy.GetContents()->DeepCopy()); | |
| 38 int version = 0; | |
| 39 if (to_copy.GetVersion(&version)) | |
| 40 version_.reset(new int(version)); | |
| 41 } | |
| 42 | |
| 43 // HashStoreContents implementation | |
| 44 virtual std::string hash_store_id() const OVERRIDE { return hash_store_id_; } | |
| 45 | |
| 46 virtual void Reset() OVERRIDE { | |
| 47 dictionary_.reset(); | |
| 48 super_mac_.clear(); | |
| 49 version_.reset(); | |
| 50 } | |
| 51 | |
| 52 virtual bool IsInitialized() const OVERRIDE { | |
| 53 return dictionary_; | |
| 54 } | |
| 55 | |
| 56 virtual const base::DictionaryValue* GetContents() const OVERRIDE{ | |
| 57 return dictionary_.get(); | |
| 58 } | |
| 59 | |
| 60 virtual scoped_ptr<MutableDictionary> GetMutableContents() OVERRIDE { | |
| 61 return scoped_ptr<MutableDictionary>( | |
| 62 new SimpleMutableDictionary(this)); | |
| 63 } | |
| 64 | |
| 65 virtual std::string GetSuperMac() const OVERRIDE { return super_mac_; } | |
| 66 | |
| 67 virtual void SetSuperMac(const std::string& super_mac) OVERRIDE { | |
| 68 super_mac_ = super_mac; | |
| 69 } | |
| 70 | |
| 71 virtual bool GetVersion(int* version) const OVERRIDE { | |
| 72 if (!version_) | |
| 73 return false; | |
| 74 *version = *version_; | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 virtual void SetVersion(int version) OVERRIDE { | |
| 79 version_.reset(new int(version)); | |
| 80 } | |
| 81 | |
| 82 virtual void CommitPendingWrite() OVERRIDE {} | |
| 83 | |
| 84 private: | |
| 85 class SimpleMutableDictionary | |
| 86 : public HashStoreContents::MutableDictionary { | |
| 87 public: | |
| 88 explicit SimpleMutableDictionary(DictionaryHashStoreContents* outer) | |
| 89 : outer_(outer) {} | |
| 90 | |
| 91 virtual ~SimpleMutableDictionary() {} | |
| 92 | |
| 93 // MutableDictionary implementation | |
| 94 virtual base::DictionaryValue* operator->() OVERRIDE { | |
| 95 if (!outer_->dictionary_) | |
| 96 outer_->dictionary_.reset(new base::DictionaryValue); | |
| 97 return outer_->dictionary_.get(); | |
| 98 } | |
| 99 | |
| 100 private: | |
| 101 DictionaryHashStoreContents* outer_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(SimpleMutableDictionary); | |
| 104 }; | |
| 105 | |
| 106 const std::string hash_store_id_; | |
| 107 std::string super_mac_; | |
| 108 scoped_ptr<int> version_; | |
| 109 scoped_ptr<base::DictionaryValue> dictionary_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(DictionaryHashStoreContents); | |
| 112 }; | |
| 113 | |
| 114 // An in-memory PrefStore backed by an immutable DictionaryValue. | |
| 115 class DictionaryPrefStore : public PrefStore { | |
| 116 public: | |
| 117 explicit DictionaryPrefStore(const base::DictionaryValue* dictionary) | |
| 118 : dictionary_(dictionary) {} | 30 : dictionary_(dictionary) {} |
| 119 | 31 |
| 32 // PrefStore implementation | |
| 120 virtual bool GetValue(const std::string& key, | 33 virtual bool GetValue(const std::string& key, |
| 121 const base::Value** result) const OVERRIDE { | 34 const base::Value** result) const OVERRIDE { |
| 122 const base::Value* tmp = NULL; | 35 const base::Value* tmp = NULL; |
| 123 if (!dictionary_->Get(key, &tmp)) | 36 if (!dictionary_->Get(key, &tmp)) |
| 124 return false; | 37 return false; |
| 125 | 38 |
| 39 if (result) | |
| 40 *result = tmp; | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE { | |
| 45 observers_.AddObserver(observer); | |
| 46 } | |
| 47 | |
| 48 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE { | |
| 49 observers_.RemoveObserver(observer); | |
| 50 } | |
| 51 | |
| 52 virtual bool HasObservers() const OVERRIDE { | |
| 53 return observers_.might_have_observers(); | |
| 54 } | |
| 55 | |
| 56 // WriteablePrefStore implementation | |
| 57 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE { | |
| 58 dictionary_->Set(key, value); | |
| 59 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | |
|
gab
2014/06/06 21:54:59
Call ReportValueChanged() here and below instead o
erikwright (departed)
2014/06/10 20:27:47
Done.
| |
| 60 } | |
| 61 | |
| 62 virtual void RemoveValue(const std::string& key) OVERRIDE { | |
| 63 dictionary_->Remove(key, NULL); | |
| 64 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | |
| 65 } | |
| 66 | |
| 67 virtual bool GetMutableValue(const std::string& key, | |
| 68 base::Value** result) OVERRIDE { | |
| 69 base::Value* tmp = NULL; | |
| 70 if (!dictionary_->Get(key, &tmp)) | |
| 71 return false; | |
| 72 | |
| 126 if (result) | 73 if (result) |
| 127 *result = tmp; | 74 *result = tmp; |
| 128 return true; | 75 return true; |
|
gab
2014/06/06 21:54:59
Just like JsonPrefStore::GetMutableValue(), I thin
erikwright (departed)
2014/06/10 20:27:47
Done.
| |
| 129 } | 76 } |
| 130 | 77 |
| 78 virtual void ReportValueChanged(const std::string& key) OVERRIDE { | |
| 79 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(key)); | |
| 80 } | |
| 81 | |
| 131 private: | 82 private: |
| 132 virtual ~DictionaryPrefStore() {} | 83 virtual ~DictionaryPrefStore() {} |
| 133 | 84 |
| 134 const base::DictionaryValue* dictionary_; | 85 base::DictionaryValue* dictionary_; |
| 86 ObserverList<PrefStore::Observer, true> observers_; | |
| 135 | 87 |
| 136 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); | 88 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); |
| 137 }; | 89 }; |
| 138 | 90 |
| 139 // Waits for a PrefStore to be initialized and then initializes the | 91 class MigrationDelegateImpl : public TrackedPreferencesMigrationDelegate { |
| 140 // corresponding PrefHashStore. | |
| 141 // The observer deletes itself when its work is completed. | |
| 142 class InitializeHashStoreObserver : public PrefStore::Observer { | |
| 143 public: | 92 public: |
| 144 // Creates an observer that will initialize |pref_hash_store| with the | 93 MigrationDelegateImpl(const base::WeakPtr<JsonPrefStore>& pref_store, |
|
gab
2014/06/06 21:54:59
Although this delegate is potentially a nice clean
| |
| 145 // contents of |pref_store| when the latter is fully loaded. | 94 InterceptablePrefFilter* pref_filter, |
| 146 InitializeHashStoreObserver( | 95 PrefHashStore* pref_hash_store) |
| 147 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& | 96 : pref_store_(pref_store), |
| 148 tracking_configuration, | 97 pref_filter_(pref_filter), |
| 149 size_t reporting_ids_count, | 98 pref_hash_store_(pref_hash_store) {} |
| 150 const scoped_refptr<PrefStore>& pref_store, | 99 virtual void CleanPreference(const std::string& key) OVERRIDE; |
| 151 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl) | 100 virtual void NotifyOnSuccessfulWrite( |
| 152 : tracking_configuration_(tracking_configuration), | 101 const base::Closure& on_successful_write) OVERRIDE; |
| 153 reporting_ids_count_(reporting_ids_count), | 102 virtual void InterceptLoadedPreferences(const Intercept& intercept) OVERRIDE; |
| 154 pref_store_(pref_store), | 103 virtual PrefHashStore* GetPrefHashStore() OVERRIDE; |
| 155 pref_hash_store_impl_(pref_hash_store_impl.Pass()) {} | |
| 156 | |
| 157 virtual ~InitializeHashStoreObserver(); | |
| 158 | |
| 159 // PrefStore::Observer implementation. | |
| 160 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; | |
| 161 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; | |
| 162 | 104 |
| 163 private: | 105 private: |
| 164 const std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 106 base::WeakPtr<JsonPrefStore> pref_store_; |
| 165 tracking_configuration_; | 107 InterceptablePrefFilter* pref_filter_; |
| 166 const size_t reporting_ids_count_; | 108 PrefHashStore* pref_hash_store_; |
| 167 scoped_refptr<PrefStore> pref_store_; | |
| 168 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(InitializeHashStoreObserver); | |
| 171 }; | 109 }; |
| 172 | 110 |
| 173 InitializeHashStoreObserver::~InitializeHashStoreObserver() {} | 111 void MigrationDelegateImpl::CleanPreference(const std::string& key) { |
| 112 pref_store_->RemoveValueSilently(key); | |
| 113 } | |
| 174 | 114 |
| 175 void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {} | 115 void MigrationDelegateImpl::NotifyOnSuccessfulWrite( |
| 116 const base::Closure& on_successful_write) { | |
| 117 pref_store_->RegisterOnNextSuccessfulWriteCallback(on_successful_write); | |
| 118 } | |
| 176 | 119 |
| 177 void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) { | 120 void MigrationDelegateImpl::InterceptLoadedPreferences( |
| 178 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl | 121 const Intercept& intercept) { |
| 179 // hasn't been initialized by someone else in the meantime, initialize it now. | 122 pref_filter_->InterceptNextFilterOnLoad(intercept); |
| 180 const PrefHashStoreImpl::StoreVersion pre_update_version = | 123 } |
| 181 pref_hash_store_impl_->GetCurrentVersion(); | 124 |
| 182 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) { | 125 PrefHashStore* MigrationDelegateImpl::GetPrefHashStore() { |
| 183 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(), | 126 return pref_hash_store_; |
| 184 tracking_configuration_, | |
| 185 NULL, | |
| 186 reporting_ids_count_).Initialize(*pref_store_); | |
| 187 UMA_HISTOGRAM_ENUMERATION( | |
| 188 "Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom", | |
| 189 pre_update_version, | |
| 190 PrefHashStoreImpl::VERSION_LATEST + 1); | |
| 191 } | |
| 192 pref_store_->RemoveObserver(this); | |
| 193 delete this; | |
| 194 } | 127 } |
| 195 | 128 |
| 196 } // namespace | 129 } // namespace |
| 197 | 130 |
| 198 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved | 131 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved |
| 199 // out of Local State. This will resolve a race condition on Android and a | 132 // out of Local State. This will resolve a race condition on Android and a |
| 200 // privacy issue on ChromeOS. http://crbug.com/349158 | 133 // privacy issue on ChromeOS. http://crbug.com/349158 |
| 201 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = | 134 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = |
| 202 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 135 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 203 false; | 136 false; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 it != tracking_configuration_.end(); | 213 it != tracking_configuration_.end(); |
| 281 ++it) { | 214 ++it) { |
| 282 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 215 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
| 283 protected_configuration.push_back(*it); | 216 protected_configuration.push_back(*it); |
| 284 protected_pref_names.insert(it->name); | 217 protected_pref_names.insert(it->name); |
| 285 } else { | 218 } else { |
| 286 unprotected_configuration.push_back(*it); | 219 unprotected_configuration.push_back(*it); |
| 287 unprotected_pref_names.insert(it->name); | 220 unprotected_pref_names.insert(it->name); |
| 288 } | 221 } |
| 289 } | 222 } |
| 223 scoped_ptr<PrefHashStoreImpl> unprotected_pref_hash_store = | |
| 224 GetPrefHashStoreImpl(); | |
| 225 scoped_ptr<PrefHashStoreImpl> protected_pref_hash_store = | |
| 226 GetPrefHashStoreImpl(); | |
| 227 PrefHashStoreImpl* raw_unprotected_pref_hash_store = | |
| 228 unprotected_pref_hash_store.get(); | |
| 229 PrefHashStoreImpl* raw_protected_pref_hash_store = | |
| 230 protected_pref_hash_store.get(); | |
| 290 | 231 |
| 291 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 232 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 292 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 233 new PrefHashFilter(unprotected_pref_hash_store.PassAs<PrefHashStore>(), |
| 293 unprotected_configuration, | 234 unprotected_configuration, |
| 294 validation_delegate, | 235 validation_delegate, |
| 295 reporting_ids_count_)); | 236 reporting_ids_count_)); |
| 296 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( | 237 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( |
| 297 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 238 new PrefHashFilter(protected_pref_hash_store.PassAs<PrefHashStore>(), |
| 298 protected_configuration, | 239 protected_configuration, |
| 299 validation_delegate, | 240 validation_delegate, |
| 300 reporting_ids_count_)); | 241 reporting_ids_count_)); |
| 301 | 242 |
| 302 PrefHashFilter* raw_unprotected_pref_hash_filter = | 243 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 303 unprotected_pref_hash_filter.get(); | 244 unprotected_pref_hash_filter.get(); |
| 304 PrefHashFilter* raw_protected_pref_hash_filter = | 245 PrefHashFilter* raw_protected_pref_hash_filter = |
| 305 protected_pref_hash_filter.get(); | 246 protected_pref_hash_filter.get(); |
| 306 | 247 |
| 307 scoped_refptr<JsonPrefStore> unprotected_pref_store( | 248 scoped_refptr<JsonPrefStore> unprotected_pref_store( |
| 308 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 249 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
| 309 io_task_runner, | 250 io_task_runner, |
| 310 unprotected_pref_hash_filter.PassAs<PrefFilter>())); | 251 unprotected_pref_hash_filter.PassAs<PrefFilter>())); |
| 311 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore( | 252 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore( |
| 312 profile_path_.Append(chrome::kProtectedPreferencesFilename), | 253 profile_path_.Append(chrome::kProtectedPreferencesFilename), |
| 313 io_task_runner, | 254 io_task_runner, |
| 314 protected_pref_hash_filter.PassAs<PrefFilter>())); | 255 protected_pref_hash_filter.PassAs<PrefFilter>())); |
| 315 | 256 |
| 257 scoped_ptr<HashStoreContents> unprotected_hash_store_contents( | |
| 258 new PrefStoreHashStoreContents(unprotected_pref_store)); | |
| 259 scoped_ptr<HashStoreContents> protected_hash_store_contents( | |
| 260 new PrefStoreHashStoreContents(protected_pref_store)); | |
| 261 | |
| 262 raw_unprotected_pref_hash_store->SetHashStoreContents( | |
| 263 unprotected_hash_store_contents.Pass()); | |
| 264 raw_protected_pref_hash_store->SetHashStoreContents( | |
| 265 protected_hash_store_contents.Pass()); | |
| 266 | |
| 316 SetupTrackedPreferencesMigration( | 267 SetupTrackedPreferencesMigration( |
| 317 unprotected_pref_names, | 268 unprotected_pref_names, |
| 318 protected_pref_names, | 269 protected_pref_names, |
| 319 base::Bind(&JsonPrefStore::RemoveValueSilently, | 270 scoped_ptr<TrackedPreferencesMigrationDelegate>( |
| 320 unprotected_pref_store->AsWeakPtr()), | 271 new MigrationDelegateImpl(unprotected_pref_store->AsWeakPtr(), |
| 321 base::Bind(&JsonPrefStore::RemoveValueSilently, | 272 raw_unprotected_pref_hash_filter, |
| 322 protected_pref_store->AsWeakPtr()), | 273 raw_unprotected_pref_hash_store)), |
| 323 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, | 274 scoped_ptr<TrackedPreferencesMigrationDelegate>( |
| 324 unprotected_pref_store->AsWeakPtr()), | 275 new MigrationDelegateImpl(protected_pref_store->AsWeakPtr(), |
| 325 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, | 276 raw_protected_pref_hash_filter, |
| 326 protected_pref_store->AsWeakPtr()), | 277 raw_protected_pref_hash_store)), |
| 327 raw_unprotected_pref_hash_filter, | 278 GetLegacyPrefHashStoreImpl().PassAs<PrefHashStore>()); |
| 328 raw_protected_pref_hash_filter); | |
| 329 | 279 |
| 330 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, | 280 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, |
| 331 protected_pref_names); | 281 protected_pref_names); |
| 332 } | 282 } |
| 333 | 283 |
| 334 void ProfilePrefStoreManager::UpdateProfileHashStoreIfRequired( | |
| 335 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | |
| 336 if (!kPlatformSupportsPreferenceTracking) | |
| 337 return; | |
| 338 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl(GetPrefHashStoreImpl()); | |
| 339 const PrefHashStoreImpl::StoreVersion current_version = | |
| 340 pref_hash_store_impl->GetCurrentVersion(); | |
| 341 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferencesAlternateStoreVersion", | |
| 342 current_version, | |
| 343 PrefHashStoreImpl::VERSION_LATEST + 1); | |
| 344 | |
| 345 // Update the pref hash store if it's not at the latest version. | |
| 346 if (current_version != PrefHashStoreImpl::VERSION_LATEST) { | |
| 347 scoped_refptr<JsonPrefStore> pref_store = | |
| 348 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | |
| 349 io_task_runner, | |
| 350 scoped_ptr<PrefFilter>()); | |
| 351 pref_store->AddObserver( | |
| 352 new InitializeHashStoreObserver(tracking_configuration_, | |
| 353 reporting_ids_count_, | |
| 354 pref_store, | |
| 355 pref_hash_store_impl.Pass())); | |
| 356 pref_store->ReadPrefsAsync(NULL); | |
| 357 } | |
| 358 } | |
| 359 | |
| 360 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( | 284 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( |
| 361 const base::DictionaryValue& master_prefs) { | 285 const base::DictionaryValue& master_prefs) { |
| 362 // Create the profile directory if it doesn't exist yet (very possible on | 286 // Create the profile directory if it doesn't exist yet (very possible on |
| 363 // first run). | 287 // first run). |
| 364 if (!base::CreateDirectory(profile_path_)) | 288 if (!base::CreateDirectory(profile_path_)) |
| 365 return false; | 289 return false; |
| 366 | 290 |
| 291 scoped_ptr<base::DictionaryValue> protected_master_prefs; | |
| 292 | |
| 293 if (kPlatformSupportsPreferenceTracking) { | |
| 294 protected_master_prefs.reset(master_prefs.DeepCopy()); | |
| 295 scoped_refptr<WriteablePrefStore> pref_store( | |
| 296 new DictionaryPrefStore(protected_master_prefs.get())); | |
| 297 scoped_ptr<PrefHashStoreImpl> pref_hash_store(GetPrefHashStoreImpl()); | |
| 298 pref_hash_store->SetHashStoreContents(scoped_ptr<HashStoreContents>( | |
| 299 new PrefStoreHashStoreContents(pref_store))); | |
| 300 PrefHashFilter(pref_hash_store.PassAs<PrefHashStore>(), | |
| 301 tracking_configuration_, | |
| 302 NULL, | |
| 303 reporting_ids_count_).Initialize(*pref_store); | |
| 304 } | |
|
gab
2014/06/06 21:54:59
In my proposed model this logic can remain as it u
erikwright (departed)
2014/06/10 20:27:47
Hmm. I don't see how. Previously we wrote out the
gab
2014/06/11 18:23:55
This new code is required because of the circular
| |
| 305 | |
| 367 // This will write out to a single combined file which will be immediately | 306 // This will write out to a single combined file which will be immediately |
| 368 // migrated to two files on load. | 307 // migrated to two files on load. |
| 369 JSONFileValueSerializer serializer( | 308 JSONFileValueSerializer serializer( |
| 370 GetPrefFilePathFromProfilePath(profile_path_)); | 309 GetPrefFilePathFromProfilePath(profile_path_)); |
| 371 | 310 |
| 372 // Call Serialize (which does IO) on the main thread, which would _normally_ | 311 // Call Serialize (which does IO) on the main thread, which would _normally_ |
| 373 // be verboten. In this case however, we require this IO to synchronously | 312 // be verboten. In this case however, we require this IO to synchronously |
| 374 // complete before Chrome can start (as master preferences seed the Local | 313 // complete before Chrome can start (as master preferences seed the Local |
| 375 // State and Preferences files). This won't trip ThreadIORestrictions as they | 314 // State and Preferences files). This won't trip ThreadIORestrictions as they |
| 376 // won't have kicked in yet on the main thread. | 315 // won't have kicked in yet on the main thread. |
| 377 bool success = serializer.Serialize(master_prefs); | 316 bool success = serializer.Serialize( |
| 378 | 317 protected_master_prefs ? *protected_master_prefs : master_prefs); |
| 379 if (success && kPlatformSupportsPreferenceTracking) { | |
| 380 scoped_refptr<const PrefStore> pref_store( | |
| 381 new DictionaryPrefStore(&master_prefs)); | |
| 382 PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | |
| 383 tracking_configuration_, | |
| 384 NULL, | |
| 385 reporting_ids_count_).Initialize(*pref_store); | |
| 386 } | |
| 387 | 318 |
| 388 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); | 319 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); |
| 389 return success; | 320 return success; |
| 390 } | 321 } |
| 391 | 322 |
| 392 PersistentPrefStore* | 323 PersistentPrefStore* |
| 393 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( | 324 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( |
| 394 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | 325 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { |
| 395 scoped_ptr<PrefFilter> pref_filter; | 326 scoped_ptr<PrefFilter> pref_filter; |
| 396 if (kPlatformSupportsPreferenceTracking) { | 327 if (kPlatformSupportsPreferenceTracking) { |
| 397 pref_filter.reset( | 328 pref_filter.reset( |
| 398 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), | 329 new PrefHashFilter(GetLegacyPrefHashStoreImpl().PassAs<PrefHashStore>(), |
| 399 tracking_configuration_, | 330 tracking_configuration_, |
| 400 NULL, | 331 NULL, |
| 401 reporting_ids_count_)); | 332 reporting_ids_count_)); |
| 402 } | 333 } |
| 403 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 334 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
| 404 io_task_runner, | 335 io_task_runner, |
| 405 pref_filter.Pass()); | 336 pref_filter.Pass()); |
| 406 } | 337 } |
| 407 | 338 |
| 408 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { | 339 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { |
| 409 DCHECK(kPlatformSupportsPreferenceTracking); | 340 DCHECK(kPlatformSupportsPreferenceTracking); |
| 410 | 341 |
| 411 return make_scoped_ptr(new PrefHashStoreImpl( | 342 return make_scoped_ptr(new PrefHashStoreImpl(seed_, device_id_)); |
| 412 seed_, | 343 } |
| 413 device_id_, | 344 |
| 345 scoped_ptr<PrefHashStoreImpl> | |
| 346 ProfilePrefStoreManager::GetLegacyPrefHashStoreImpl() { | |
| 347 DCHECK(kPlatformSupportsPreferenceTracking); | |
| 348 | |
| 349 scoped_ptr<PrefHashStoreImpl> instance( | |
| 350 new PrefHashStoreImpl(seed_, device_id_)); | |
| 351 instance->SetHashStoreContents( | |
| 414 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | 352 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( |
| 415 profile_path_.AsUTF8Unsafe(), local_state_)))); | 353 profile_path_.AsUTF8Unsafe(), local_state_))); |
| 354 return instance.Pass(); | |
| 416 } | 355 } |
| OLD | NEW |