Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1468)

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New approach. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return scoped_ptr<MutableDictionary>( 57 return scoped_ptr<MutableDictionary>(
58 new SimpleMutableDictionary(this)); 58 new SimpleMutableDictionary(this));
59 } 59 }
60 60
61 virtual std::string GetSuperMac() const OVERRIDE { return super_mac_; } 61 virtual std::string GetSuperMac() const OVERRIDE { return super_mac_; }
62 62
63 virtual void SetSuperMac(const std::string& super_mac) OVERRIDE { 63 virtual void SetSuperMac(const std::string& super_mac) OVERRIDE {
64 super_mac_ = super_mac; 64 super_mac_ = super_mac;
65 } 65 }
66 66
67 virtual void CommitPendingWrite() OVERRIDE {}
68
69 private: 67 private:
70 class SimpleMutableDictionary 68 class SimpleMutableDictionary
71 : public HashStoreContents::MutableDictionary { 69 : public HashStoreContents::MutableDictionary {
72 public: 70 public:
73 explicit SimpleMutableDictionary(DictionaryHashStoreContents* outer) 71 explicit SimpleMutableDictionary(DictionaryHashStoreContents* outer)
74 : outer_(outer) {} 72 : outer_(outer) {}
75 73
76 virtual ~SimpleMutableDictionary() {} 74 virtual ~SimpleMutableDictionary() {}
77 75
78 // MutableDictionary implementation 76 // MutableDictionary implementation
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { 202 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
205 protected_configuration.push_back(*it); 203 protected_configuration.push_back(*it);
206 protected_pref_names.insert(it->name); 204 protected_pref_names.insert(it->name);
207 } else { 205 } else {
208 unprotected_configuration.push_back(*it); 206 unprotected_configuration.push_back(*it);
209 unprotected_pref_names.insert(it->name); 207 unprotected_pref_names.insert(it->name);
210 } 208 }
211 } 209 }
212 210
213 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( 211 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter(
214 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 212 new PrefHashFilter(GetPrefHashStoreImpl(false).PassAs<PrefHashStore>(),
215 unprotected_configuration, 213 unprotected_configuration,
216 validation_delegate, 214 validation_delegate,
217 reporting_ids_count_)); 215 reporting_ids_count_));
218 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( 216 scoped_ptr<PrefHashFilter> protected_pref_hash_filter(
219 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 217 new PrefHashFilter(GetPrefHashStoreImpl(true).PassAs<PrefHashStore>(),
220 protected_configuration, 218 protected_configuration,
221 validation_delegate, 219 validation_delegate,
222 reporting_ids_count_)); 220 reporting_ids_count_));
223 221
224 PrefHashFilter* raw_unprotected_pref_hash_filter = 222 PrefHashFilter* raw_unprotected_pref_hash_filter =
225 unprotected_pref_hash_filter.get(); 223 unprotected_pref_hash_filter.get();
226 PrefHashFilter* raw_protected_pref_hash_filter = 224 PrefHashFilter* raw_protected_pref_hash_filter =
227 protected_pref_hash_filter.get(); 225 protected_pref_hash_filter.get();
228 226
229 scoped_refptr<JsonPrefStore> unprotected_pref_store( 227 scoped_refptr<JsonPrefStore> unprotected_pref_store(
230 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 228 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
231 io_task_runner, 229 io_task_runner,
232 unprotected_pref_hash_filter.PassAs<PrefFilter>())); 230 unprotected_pref_hash_filter.PassAs<PrefFilter>()));
233 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore( 231 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore(
234 profile_path_.Append(chrome::kProtectedPreferencesFilename), 232 profile_path_.Append(chrome::kProtectedPreferencesFilename),
235 io_task_runner, 233 io_task_runner,
236 protected_pref_hash_filter.PassAs<PrefFilter>())); 234 protected_pref_hash_filter.PassAs<PrefFilter>()));
237 235
238 SetupTrackedPreferencesMigration( 236 SetupTrackedPreferencesMigration(
239 unprotected_pref_names, 237 unprotected_pref_names,
240 protected_pref_names, 238 protected_pref_names,
241 base::Bind(&JsonPrefStore::RemoveValueSilently, 239 base::Bind(&JsonPrefStore::RemoveValueSilently,
242 unprotected_pref_store->AsWeakPtr()), 240 unprotected_pref_store->AsWeakPtr()),
243 base::Bind(&JsonPrefStore::RemoveValueSilently, 241 base::Bind(&JsonPrefStore::RemoveValueSilently,
244 protected_pref_store->AsWeakPtr()), 242 protected_pref_store->AsWeakPtr()),
245 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, 243 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback,
246 unprotected_pref_store->AsWeakPtr()), 244 unprotected_pref_store->AsWeakPtr()),
247 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, 245 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback,
248 protected_pref_store->AsWeakPtr()), 246 protected_pref_store->AsWeakPtr()),
247 GetPrefHashStoreImpl(false).PassAs<PrefHashStore>(),
248 GetPrefHashStoreImpl(true).PassAs<PrefHashStore>(),
249 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents(
250 profile_path_.AsUTF8Unsafe(), local_state_)),
249 raw_unprotected_pref_hash_filter, 251 raw_unprotected_pref_hash_filter,
250 raw_protected_pref_hash_filter); 252 raw_protected_pref_hash_filter);
251 253
252 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, 254 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
253 protected_pref_names); 255 protected_pref_names);
254 } 256 }
255 257
256 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( 258 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
257 const base::DictionaryValue& master_prefs) { 259 const base::DictionaryValue& master_prefs) {
258 // Create the profile directory if it doesn't exist yet (very possible on 260 // Create the profile directory if it doesn't exist yet (very possible on
259 // first run). 261 // first run).
260 if (!base::CreateDirectory(profile_path_)) 262 if (!base::CreateDirectory(profile_path_))
261 return false; 263 return false;
262 264
265 const base::DictionaryValue* to_serialize = &master_prefs;
266 scoped_ptr<base::DictionaryValue> copy;
267
268 if (kPlatformSupportsPreferenceTracking) {
269 copy.reset(master_prefs.DeepCopy());
270 to_serialize = copy.get();
271 PrefHashFilter(GetPrefHashStoreImpl(false).PassAs<PrefHashStore>(),
272 tracking_configuration_,
273 NULL,
274 reporting_ids_count_).Initialize(copy.get());
275 }
276
263 // This will write out to a single combined file which will be immediately 277 // This will write out to a single combined file which will be immediately
264 // migrated to two files on load. 278 // migrated to two files on load.
265 JSONFileValueSerializer serializer( 279 JSONFileValueSerializer serializer(
266 GetPrefFilePathFromProfilePath(profile_path_)); 280 GetPrefFilePathFromProfilePath(profile_path_));
267 281
268 // Call Serialize (which does IO) on the main thread, which would _normally_ 282 // Call Serialize (which does IO) on the main thread, which would _normally_
269 // be verboten. In this case however, we require this IO to synchronously 283 // be verboten. In this case however, we require this IO to synchronously
270 // complete before Chrome can start (as master preferences seed the Local 284 // complete before Chrome can start (as master preferences seed the Local
271 // State and Preferences files). This won't trip ThreadIORestrictions as they 285 // State and Preferences files). This won't trip ThreadIORestrictions as they
272 // won't have kicked in yet on the main thread. 286 // won't have kicked in yet on the main thread.
273 bool success = serializer.Serialize(master_prefs); 287 bool success = serializer.Serialize(*to_serialize);
274
275 if (success && kPlatformSupportsPreferenceTracking) {
276 scoped_refptr<const PrefStore> pref_store(
277 new DictionaryPrefStore(&master_prefs));
278 PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(),
279 tracking_configuration_,
280 NULL,
281 reporting_ids_count_).Initialize(*pref_store);
282 }
283 288
284 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); 289 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success);
285 return success; 290 return success;
286 } 291 }
287 292
288 PersistentPrefStore* 293 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl(
289 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( 294 bool use_super_mac) {
290 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
291 scoped_ptr<PrefFilter> pref_filter;
292 if (kPlatformSupportsPreferenceTracking) {
293 pref_filter.reset(
294 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(),
295 tracking_configuration_,
296 NULL,
297 reporting_ids_count_));
298 }
299 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
300 io_task_runner,
301 pref_filter.Pass());
302 }
303
304 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() {
305 DCHECK(kPlatformSupportsPreferenceTracking); 295 DCHECK(kPlatformSupportsPreferenceTracking);
306 296
307 return make_scoped_ptr(new PrefHashStoreImpl( 297 return make_scoped_ptr(new PrefHashStoreImpl(
308 seed_, 298 seed_,
309 device_id_, 299 device_id_,
310 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( 300 use_super_mac));
311 profile_path_.AsUTF8Unsafe(), local_state_)),
312 true));
313 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698