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" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
19 #include "components/prefs/json_pref_store.h" | 19 #include "components/prefs/json_pref_store.h" |
20 #include "components/prefs/persistent_pref_store.h" | 20 #include "components/prefs/persistent_pref_store.h" |
21 #include "components/prefs/pref_registry_simple.h" | 21 #include "components/prefs/pref_registry_simple.h" |
22 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 22 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
23 #include "components/user_prefs/tracked/pref_service_hash_store_contents.h" | |
24 #include "components/user_prefs/tracked/segregated_pref_store.h" | 23 #include "components/user_prefs/tracked/segregated_pref_store.h" |
25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | 24 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, | 28 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, |
30 const std::string& key) { | 29 const std::string& key) { |
31 if (pref_store) { | 30 if (pref_store) { |
32 pref_store->RemoveValueSilently( | 31 pref_store->RemoveValueSilently( |
33 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 32 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
(...skipping 22 matching lines...) Expand all Loading... |
56 : profile_path_(profile_path), | 55 : profile_path_(profile_path), |
57 tracking_configuration_(tracking_configuration), | 56 tracking_configuration_(tracking_configuration), |
58 reporting_ids_count_(reporting_ids_count), | 57 reporting_ids_count_(reporting_ids_count), |
59 seed_(seed), | 58 seed_(seed), |
60 device_id_(device_id), | 59 device_id_(device_id), |
61 local_state_(local_state) {} | 60 local_state_(local_state) {} |
62 | 61 |
63 ProfilePrefStoreManager::~ProfilePrefStoreManager() {} | 62 ProfilePrefStoreManager::~ProfilePrefStoreManager() {} |
64 | 63 |
65 // static | 64 // static |
66 void ProfilePrefStoreManager::RegisterPrefs(PrefRegistrySimple* registry) { | |
67 PrefServiceHashStoreContents::RegisterPrefs(registry); | |
68 } | |
69 | |
70 // static | |
71 void ProfilePrefStoreManager::RegisterProfilePrefs( | 65 void ProfilePrefStoreManager::RegisterProfilePrefs( |
72 user_prefs::PrefRegistrySyncable* registry) { | 66 user_prefs::PrefRegistrySyncable* registry) { |
73 PrefHashFilter::RegisterProfilePrefs(registry); | 67 PrefHashFilter::RegisterProfilePrefs(registry); |
74 } | 68 } |
75 | 69 |
76 // static | |
77 void ProfilePrefStoreManager::ResetAllPrefHashStores(PrefService* local_state) { | |
78 PrefServiceHashStoreContents::ResetAllPrefHashStores(local_state); | |
79 } | |
80 | |
81 // static | 70 // static |
82 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { | 71 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { |
83 return PrefHashFilter::GetResetTime(pref_service); | 72 return PrefHashFilter::GetResetTime(pref_service); |
84 } | 73 } |
85 | 74 |
86 // static | 75 // static |
87 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { | 76 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { |
88 PrefHashFilter::ClearResetTime(pref_service); | 77 PrefHashFilter::ClearResetTime(pref_service); |
89 } | 78 } |
90 | 79 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 132 |
144 SetupTrackedPreferencesMigration( | 133 SetupTrackedPreferencesMigration( |
145 unprotected_pref_names, protected_pref_names, | 134 unprotected_pref_names, protected_pref_names, |
146 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()), | 135 base::Bind(&RemoveValueSilently, unprotected_pref_store->AsWeakPtr()), |
147 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()), | 136 base::Bind(&RemoveValueSilently, protected_pref_store->AsWeakPtr()), |
148 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, | 137 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, |
149 unprotected_pref_store->AsWeakPtr()), | 138 unprotected_pref_store->AsWeakPtr()), |
150 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, | 139 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, |
151 protected_pref_store->AsWeakPtr()), | 140 protected_pref_store->AsWeakPtr()), |
152 GetPrefHashStore(false), GetPrefHashStore(true), | 141 GetPrefHashStore(false), GetPrefHashStore(true), |
153 std::unique_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | |
154 profile_path_.AsUTF8Unsafe(), local_state_)), | |
155 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); | 142 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); |
156 | 143 |
157 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, | 144 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, |
158 protected_pref_names); | 145 protected_pref_names); |
159 } | 146 } |
160 | 147 |
161 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( | 148 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs( |
162 const base::DictionaryValue& master_prefs) { | 149 const base::DictionaryValue& master_prefs) { |
163 // Create the profile directory if it doesn't exist yet (very possible on | 150 // Create the profile directory if it doesn't exist yet (very possible on |
164 // first run). | 151 // first run). |
(...skipping 23 matching lines...) Expand all Loading... |
188 // 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 |
189 // complete before Chrome can start (as master preferences seed the Local | 176 // complete before Chrome can start (as master preferences seed the Local |
190 // State and Preferences files). This won't trip ThreadIORestrictions as they | 177 // State and Preferences files). This won't trip ThreadIORestrictions as they |
191 // won't have kicked in yet on the main thread. | 178 // won't have kicked in yet on the main thread. |
192 bool success = serializer.Serialize(*to_serialize); | 179 bool success = serializer.Serialize(*to_serialize); |
193 | 180 |
194 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); | 181 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); |
195 return success; | 182 return success; |
196 } | 183 } |
197 | 184 |
198 PersistentPrefStore* | |
199 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( | |
200 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { | |
201 std::unique_ptr<PrefFilter> pref_filter; | |
202 if (kPlatformSupportsPreferenceTracking) { | |
203 std::unique_ptr<PrefHashStoreImpl> pref_hash_store_impl( | |
204 new PrefHashStoreImpl(seed_, device_id_, true)); | |
205 pref_hash_store_impl->set_legacy_hash_store_contents( | |
206 std::unique_ptr<HashStoreContents>(new PrefServiceHashStoreContents( | |
207 profile_path_.AsUTF8Unsafe(), local_state_))); | |
208 pref_filter.reset(new PrefHashFilter( | |
209 std::move(pref_hash_store_impl), tracking_configuration_, | |
210 base::Closure(), NULL, reporting_ids_count_, false)); | |
211 } | |
212 return new JsonPrefStore(profile_path_.Append(chrome::kPreferencesFilename), | |
213 io_task_runner.get(), std::move(pref_filter)); | |
214 } | |
215 | |
216 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( | 185 std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore( |
217 bool use_super_mac) { | 186 bool use_super_mac) { |
218 DCHECK(kPlatformSupportsPreferenceTracking); | 187 DCHECK(kPlatformSupportsPreferenceTracking); |
219 | 188 |
220 return std::unique_ptr<PrefHashStore>( | 189 return std::unique_ptr<PrefHashStore>( |
221 new PrefHashStoreImpl(seed_, device_id_, use_super_mac)); | 190 new PrefHashStoreImpl(seed_, device_id_, use_super_mac)); |
222 } | 191 } |
OLD | NEW |