| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { | 101 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { |
| 102 protected_configuration.push_back(*it); | 102 protected_configuration.push_back(*it); |
| 103 protected_pref_names.insert(it->name); | 103 protected_pref_names.insert(it->name); |
| 104 } else { | 104 } else { |
| 105 unprotected_configuration.push_back(*it); | 105 unprotected_configuration.push_back(*it); |
| 106 unprotected_pref_names.insert(it->name); | 106 unprotected_pref_names.insert(it->name); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( | 110 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( |
| 111 new PrefHashFilter(GetPrefHashStore(false), unprotected_configuration, | 111 new PrefHashFilter( |
| 112 base::Closure(), validation_delegate, | 112 GetPrefHashStore(false), MaybeGetRegistryPrefHashStore(), |
| 113 reporting_ids_count_, false)); | 113 unprotected_configuration, profile_path_, base::Closure(), |
| 114 validation_delegate, reporting_ids_count_, false)); |
| 114 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( | 115 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( |
| 115 GetPrefHashStore(true), protected_configuration, on_reset_on_load, | 116 GetPrefHashStore(true), MaybeGetRegistryPrefHashStore(), |
| 117 protected_configuration, profile_path_, on_reset_on_load, |
| 116 validation_delegate, reporting_ids_count_, true)); | 118 validation_delegate, reporting_ids_count_, true)); |
| 117 | 119 |
| 118 PrefHashFilter* raw_unprotected_pref_hash_filter = | 120 PrefHashFilter* raw_unprotected_pref_hash_filter = |
| 119 unprotected_pref_hash_filter.get(); | 121 unprotected_pref_hash_filter.get(); |
| 120 PrefHashFilter* raw_protected_pref_hash_filter = | 122 PrefHashFilter* raw_protected_pref_hash_filter = |
| 121 protected_pref_hash_filter.get(); | 123 protected_pref_hash_filter.get(); |
| 122 | 124 |
| 123 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( | 125 scoped_refptr<JsonPrefStore> unprotected_pref_store(new JsonPrefStore( |
| 124 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), | 126 profile_path_.Append(chrome::kPreferencesFilename), io_task_runner.get(), |
| 125 std::move(unprotected_pref_hash_filter))); | 127 std::move(unprotected_pref_hash_filter))); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 151 // first run). | 153 // first run). |
| 152 if (!base::CreateDirectory(profile_path_)) | 154 if (!base::CreateDirectory(profile_path_)) |
| 153 return false; | 155 return false; |
| 154 | 156 |
| 155 const base::DictionaryValue* to_serialize = &master_prefs; | 157 const base::DictionaryValue* to_serialize = &master_prefs; |
| 156 std::unique_ptr<base::DictionaryValue> copy; | 158 std::unique_ptr<base::DictionaryValue> copy; |
| 157 | 159 |
| 158 if (kPlatformSupportsPreferenceTracking) { | 160 if (kPlatformSupportsPreferenceTracking) { |
| 159 copy.reset(master_prefs.DeepCopy()); | 161 copy.reset(master_prefs.DeepCopy()); |
| 160 to_serialize = copy.get(); | 162 to_serialize = copy.get(); |
| 161 PrefHashFilter(GetPrefHashStore(false), | 163 PrefHashFilter(GetPrefHashStore(false), MaybeGetRegistryPrefHashStore(), |
| 162 tracking_configuration_, | 164 tracking_configuration_, profile_path_, base::Closure(), |
| 163 base::Closure(), | 165 NULL, reporting_ids_count_, false) |
| 164 NULL, | 166 .Initialize(copy.get()); |
| 165 reporting_ids_count_, | |
| 166 false).Initialize(copy.get()); | |
| 167 } | 167 } |
| 168 | 168 |
| 169 // This will write out to a single combined file which will be immediately | 169 // This will write out to a single combined file which will be immediately |
| 170 // migrated to two files on load. | 170 // migrated to two files on load. |
| 171 JSONFileValueSerializer serializer( | 171 JSONFileValueSerializer serializer( |
| 172 profile_path_.Append(chrome::kPreferencesFilename)); | 172 profile_path_.Append(chrome::kPreferencesFilename)); |
| 173 | 173 |
| 174 // Call Serialize (which does IO) on the main thread, which would _normally_ | 174 // Call Serialize (which does IO) on the main thread, which would _normally_ |
| 175 // be verboten. In this case however, we require this IO to synchronously | 175 // be verboten. In this case however, we require this IO to synchronously |
| 176 // complete before Chrome can start (as master preferences seed the Local | 176 // complete before Chrome can start (as master preferences seed the Local |
| 177 // State and Preferences files). This won't trip ThreadIORestrictions as they | 177 // State and Preferences files). This won't trip ThreadIORestrictions as they |
| 178 // won't have kicked in yet on the main thread. | 178 // won't have kicked in yet on the main thread. |
| 179 bool success = serializer.Serialize(*to_serialize); | 179 bool success = serializer.Serialize(*to_serialize); |
| 180 | 180 |
| 181 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); | 181 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); |
| 182 return success; | 182 return success; |
| 183 } | 183 } |
| 184 | 184 |
| 185 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( | 185 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( |
| 186 bool use_super_mac) { | 186 bool use_super_mac) { |
| 187 DCHECK(kPlatformSupportsPreferenceTracking); | 187 DCHECK(kPlatformSupportsPreferenceTracking); |
| 188 | 188 |
| 189 return std::unique_ptr<PrefHashStore>( | 189 return std::unique_ptr<PrefHashStore>( |
| 190 new PrefHashStoreImpl(seed_, device_id_, use_super_mac)); | 190 new PrefHashStoreImpl(seed_, device_id_, use_super_mac)); |
| 191 } | 191 } |
| 192 |
| 193 std::unique_ptr<PrefHashStore> |
| 194 ProfilePrefStoreManager::MaybeGetRegistryPrefHashStore() { |
| 195 DCHECK(kPlatformSupportsPreferenceTracking); |
| 196 #if defined(OS_WIN) |
| 197 return std::unique_ptr<PrefHashStore>( |
| 198 new PrefHashStoreImpl("ChromiumRegistryHashStoreValidationSeed", |
| 199 device_id_, false /* use_super_mac */)); |
| 200 #else |
| 201 return nullptr; |
| 202 #endif |
| 203 } |
| OLD | NEW |