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/callback.h" | |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/json_pref_store.h" | 13 #include "base/prefs/json_pref_store.h" |
| 13 #include "base/prefs/persistent_pref_store.h" | 14 #include "base/prefs/persistent_pref_store.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "chrome/browser/prefs/pref_hash_store_impl.h" | 16 #include "chrome/browser/prefs/pref_hash_store_impl.h" |
| 16 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 17 #include "chrome/browser/prefs/tracked/pref_service_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" |
| 20 #include "chrome/browser/sync/glue/sync_start_util.h" | |
| 19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 24 #include "sync/internal_api/public/base/model_type.h" | |
| 22 | 25 |
| 23 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved | 26 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved |
| 24 // out of Local State. This will resolve a race condition on Android and a | 27 // out of Local State. This will resolve a race condition on Android and a |
| 25 // privacy issue on ChromeOS. http://crbug.com/349158 | 28 // privacy issue on ChromeOS. http://crbug.com/349158 |
| 26 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = | 29 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = |
| 27 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 30 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 28 false; | 31 false; |
| 29 #else | 32 #else |
| 30 true; | 33 true; |
| 31 #endif | 34 #endif |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 ++it) { | 104 ++it) { |
| 102 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 105 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
| 103 protected_configuration.push_back(*it); | 106 protected_configuration.push_back(*it); |
| 104 protected_pref_names.insert(it->name); | 107 protected_pref_names.insert(it->name); |
| 105 } else { | 108 } else { |
| 106 unprotected_configuration.push_back(*it); | 109 unprotected_configuration.push_back(*it); |
| 107 unprotected_pref_names.insert(it->name); | 110 unprotected_pref_names.insert(it->name); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 114 // Used to kick sync early in case of a reset event. This is done since sync | |
| 115 // may bring back the user's server value post-reset which could potentially | |
| 116 // cause a "settings flash" between the factory default and the | |
| 117 // re-instantiated server value. Starting sync ASAP minimizes the window | |
| 118 // before the server value is re-instantiated (this window can otherwise be | |
| 119 // as long as 10 seconds by default). | |
| 120 const base::Closure start_sync_flare_for_prefs = | |
|
erikwright (departed)
2014/07/16 20:23:43
This should be a dependency passed in by chrome_pr
gab
2014/07/16 20:30:39
How is it more testable? I thought about it, but I
| |
| 121 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path_), | |
| 122 syncer::PREFERENCES); | |
| 123 | |
| 111 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 124 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 112 new PrefHashFilter(GetPrefHashStore(false), | 125 new PrefHashFilter(GetPrefHashStore(false), |
| 113 unprotected_configuration, | 126 unprotected_configuration, |
| 127 base::Closure(), | |
| 114 validation_delegate, | 128 validation_delegate, |
| 115 reporting_ids_count_, | 129 reporting_ids_count_, |
| 116 false)); | 130 false)); |
| 117 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( | 131 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( |
| 118 new PrefHashFilter(GetPrefHashStore(true), | 132 new PrefHashFilter(GetPrefHashStore(true), |
| 119 protected_configuration, | 133 protected_configuration, |
| 134 start_sync_flare_for_prefs, | |
| 120 validation_delegate, | 135 validation_delegate, |
| 121 reporting_ids_count_, | 136 reporting_ids_count_, |
| 122 true)); | 137 true)); |
| 123 | 138 |
| 124 PrefHashFilter* raw_unprotected_pref_hash_filter = | 139 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 125 unprotected_pref_hash_filter.get(); | 140 unprotected_pref_hash_filter.get(); |
| 126 PrefHashFilter* raw_protected_pref_hash_filter = | 141 PrefHashFilter* raw_protected_pref_hash_filter = |
| 127 protected_pref_hash_filter.get(); | 142 protected_pref_hash_filter.get(); |
| 128 | 143 |
| 129 scoped_refptr<JsonPrefStore> unprotected_pref_store( | 144 scoped_refptr<JsonPrefStore> unprotected_pref_store( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 return false; | 183 return false; |
| 169 | 184 |
| 170 const base::DictionaryValue* to_serialize = &master_prefs; | 185 const base::DictionaryValue* to_serialize = &master_prefs; |
| 171 scoped_ptr<base::DictionaryValue> copy; | 186 scoped_ptr<base::DictionaryValue> copy; |
| 172 | 187 |
| 173 if (kPlatformSupportsPreferenceTracking) { | 188 if (kPlatformSupportsPreferenceTracking) { |
| 174 copy.reset(master_prefs.DeepCopy()); | 189 copy.reset(master_prefs.DeepCopy()); |
| 175 to_serialize = copy.get(); | 190 to_serialize = copy.get(); |
| 176 PrefHashFilter(GetPrefHashStore(false), | 191 PrefHashFilter(GetPrefHashStore(false), |
| 177 tracking_configuration_, | 192 tracking_configuration_, |
| 193 base::Closure(), | |
| 178 NULL, | 194 NULL, |
| 179 reporting_ids_count_, | 195 reporting_ids_count_, |
| 180 false).Initialize(copy.get()); | 196 false).Initialize(copy.get()); |
| 181 } | 197 } |
| 182 | 198 |
| 183 // This will write out to a single combined file which will be immediately | 199 // This will write out to a single combined file which will be immediately |
| 184 // migrated to two files on load. | 200 // migrated to two files on load. |
| 185 JSONFileValueSerializer serializer( | 201 JSONFileValueSerializer serializer( |
| 186 GetPrefFilePathFromProfilePath(profile_path_)); | 202 GetPrefFilePathFromProfilePath(profile_path_)); |
| 187 | 203 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 202 scoped_ptr<PrefFilter> pref_filter; | 218 scoped_ptr<PrefFilter> pref_filter; |
| 203 if (kPlatformSupportsPreferenceTracking) { | 219 if (kPlatformSupportsPreferenceTracking) { |
| 204 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl( | 220 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl( |
| 205 new PrefHashStoreImpl(seed_, device_id_, true)); | 221 new PrefHashStoreImpl(seed_, device_id_, true)); |
| 206 pref_hash_store_impl->set_legacy_hash_store_contents( | 222 pref_hash_store_impl->set_legacy_hash_store_contents( |
| 207 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | 223 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( |
| 208 profile_path_.AsUTF8Unsafe(), local_state_))); | 224 profile_path_.AsUTF8Unsafe(), local_state_))); |
| 209 pref_filter.reset( | 225 pref_filter.reset( |
| 210 new PrefHashFilter(pref_hash_store_impl.PassAs<PrefHashStore>(), | 226 new PrefHashFilter(pref_hash_store_impl.PassAs<PrefHashStore>(), |
| 211 tracking_configuration_, | 227 tracking_configuration_, |
| 228 base::Closure(), | |
| 212 NULL, | 229 NULL, |
| 213 reporting_ids_count_, | 230 reporting_ids_count_, |
| 214 false)); | 231 false)); |
| 215 } | 232 } |
| 216 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), | 233 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), |
| 217 io_task_runner, | 234 io_task_runner, |
| 218 pref_filter.Pass()); | 235 pref_filter.Pass()); |
| 219 } | 236 } |
| 220 | 237 |
| 221 scoped_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( | 238 scoped_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( |
| 222 bool use_super_mac) { | 239 bool use_super_mac) { |
| 223 DCHECK(kPlatformSupportsPreferenceTracking); | 240 DCHECK(kPlatformSupportsPreferenceTracking); |
| 224 | 241 |
| 225 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( | 242 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( |
| 226 seed_, | 243 seed_, |
| 227 device_id_, | 244 device_id_, |
| 228 use_super_mac)); | 245 use_super_mac)); |
| 229 } | 246 } |
| OLD | NEW |