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

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: Respond to CR comments. 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"
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/dictionary_pref_store.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"
18 #include "chrome/browser/prefs/tracked/pref_store_hash_store_contents.h"
17 #include "chrome/browser/prefs/tracked/segregated_pref_store.h" 19 #include "chrome/browser/prefs/tracked/segregated_pref_store.h"
18 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" 20 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.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"
22 24
23 namespace { 25 namespace {
24 26
25 // An adaptor that allows a PrefHashStoreImpl to access a preference store 27 class MigrationDelegateImpl : public TrackedPreferencesMigrationDelegate {
26 // directly as a dictionary. Uses an equivalent layout to
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 MigrationDelegateImpl(const base::WeakPtr<JsonPrefStore>& pref_store,
31 // mutable but does not affect the original, nor is it persisted to disk in 30 InterceptablePrefFilter* pref_filter,
32 // any other way. 31 PrefHashStore* pref_hash_store)
33 explicit DictionaryHashStoreContents(const HashStoreContents& to_copy) 32 : pref_store_(pref_store),
34 : hash_store_id_(to_copy.hash_store_id()), 33 pref_filter_(pref_filter),
35 super_mac_(to_copy.GetSuperMac()) { 34 pref_hash_store_(pref_hash_store) {}
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 35
43 // HashStoreContents implementation 36 // TrackedPreferencesMigrationDelegate implementation
44 virtual std::string hash_store_id() const OVERRIDE { return hash_store_id_; } 37 virtual bool IsValid() OVERRIDE;
45 38 virtual void CleanPreference(const std::string& key) OVERRIDE;
46 virtual void Reset() OVERRIDE { 39 virtual void NotifyOnSuccessfulWrite(
47 dictionary_.reset(); 40 const base::Closure& on_successful_write) OVERRIDE;
48 super_mac_.clear(); 41 virtual void InterceptLoadedPreferences(const Intercept& intercept) OVERRIDE;
49 version_.reset(); 42 virtual PrefHashStore* GetPrefHashStore() OVERRIDE;
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 43
84 private: 44 private:
85 class SimpleMutableDictionary 45 base::WeakPtr<JsonPrefStore> pref_store_;
86 : public HashStoreContents::MutableDictionary { 46 InterceptablePrefFilter* pref_filter_;
87 public: 47 PrefHashStore* pref_hash_store_;
88 explicit SimpleMutableDictionary(DictionaryHashStoreContents* outer)
89 : outer_(outer) {}
90 48
91 virtual ~SimpleMutableDictionary() {} 49 DISALLOW_COPY_AND_ASSIGN(MigrationDelegateImpl);
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 }; 50 };
113 51
114 // An in-memory PrefStore backed by an immutable DictionaryValue. 52 bool MigrationDelegateImpl::IsValid() {
115 class DictionaryPrefStore : public PrefStore { 53 return pref_store_;
116 public: 54 }
117 explicit DictionaryPrefStore(const base::DictionaryValue* dictionary) 55 void MigrationDelegateImpl::CleanPreference(const std::string& key) {
118 : dictionary_(dictionary) {} 56 if (pref_store_)
57 pref_store_->RemoveValueSilently(key);
58 }
119 59
120 virtual bool GetValue(const std::string& key, 60 void MigrationDelegateImpl::NotifyOnSuccessfulWrite(
121 const base::Value** result) const OVERRIDE { 61 const base::Closure& on_successful_write) {
122 const base::Value* tmp = NULL; 62 if (pref_store_)
123 if (!dictionary_->Get(key, &tmp)) 63 pref_store_->RegisterOnNextSuccessfulWriteCallback(on_successful_write);
124 return false; 64 }
125 65
126 if (result) 66 void MigrationDelegateImpl::InterceptLoadedPreferences(
127 *result = tmp; 67 const Intercept& intercept) {
128 return true; 68 // |pref_filter_| is owned by |pref_store_|.
129 } 69 if (pref_store_)
70 pref_filter_->InterceptNextFilterOnLoad(intercept);
71 }
130 72
131 private: 73 PrefHashStore* MigrationDelegateImpl::GetPrefHashStore() {
132 virtual ~DictionaryPrefStore() {} 74 // |pref_hash_store_| is owned indirectly by |pref_store_|.
133 75 return pref_store_ ? pref_hash_store_ : NULL;
134 const base::DictionaryValue* dictionary_;
135
136 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore);
137 };
138
139 // Waits for a PrefStore to be initialized and then initializes the
140 // corresponding PrefHashStore.
141 // The observer deletes itself when its work is completed.
142 class InitializeHashStoreObserver : public PrefStore::Observer {
143 public:
144 // Creates an observer that will initialize |pref_hash_store| with the
145 // contents of |pref_store| when the latter is fully loaded.
146 InitializeHashStoreObserver(
147 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>&
148 tracking_configuration,
149 size_t reporting_ids_count,
150 const scoped_refptr<PrefStore>& pref_store,
151 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl)
152 : tracking_configuration_(tracking_configuration),
153 reporting_ids_count_(reporting_ids_count),
154 pref_store_(pref_store),
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
163 private:
164 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>
165 tracking_configuration_;
166 const size_t reporting_ids_count_;
167 scoped_refptr<PrefStore> pref_store_;
168 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl_;
169
170 DISALLOW_COPY_AND_ASSIGN(InitializeHashStoreObserver);
171 };
172
173 InitializeHashStoreObserver::~InitializeHashStoreObserver() {}
174
175 void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {}
176
177 void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) {
178 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl
179 // hasn't been initialized by someone else in the meantime, initialize it now.
180 const PrefHashStoreImpl::StoreVersion pre_update_version =
181 pref_hash_store_impl_->GetCurrentVersion();
182 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) {
183 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(),
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 } 76 }
195 77
196 } // namespace 78 } // namespace
197 79
198 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved 80 // 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 81 // out of Local State. This will resolve a race condition on Android and a
200 // privacy issue on ChromeOS. http://crbug.com/349158 82 // privacy issue on ChromeOS. http://crbug.com/349158
201 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = 83 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking =
202 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 84 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
203 false; 85 false;
(...skipping 20 matching lines...) Expand all
224 106
225 // static 107 // static
226 void ProfilePrefStoreManager::RegisterPrefs(PrefRegistrySimple* registry) { 108 void ProfilePrefStoreManager::RegisterPrefs(PrefRegistrySimple* registry) {
227 PrefServiceHashStoreContents::RegisterPrefs(registry); 109 PrefServiceHashStoreContents::RegisterPrefs(registry);
228 } 110 }
229 111
230 // static 112 // static
231 void ProfilePrefStoreManager::RegisterProfilePrefs( 113 void ProfilePrefStoreManager::RegisterProfilePrefs(
232 user_prefs::PrefRegistrySyncable* registry) { 114 user_prefs::PrefRegistrySyncable* registry) {
233 PrefHashFilter::RegisterProfilePrefs(registry); 115 PrefHashFilter::RegisterProfilePrefs(registry);
116 PrefStoreHashStoreContents::RegisterProfilePrefs(registry);
234 } 117 }
235 118
236 // static 119 // static
237 base::FilePath ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( 120 base::FilePath ProfilePrefStoreManager::GetPrefFilePathFromProfilePath(
238 const base::FilePath& profile_path) { 121 const base::FilePath& profile_path) {
239 return profile_path.Append(chrome::kPreferencesFilename); 122 return profile_path.Append(chrome::kPreferencesFilename);
240 } 123 }
241 124
242 // static 125 // static
243 void ProfilePrefStoreManager::ResetAllPrefHashStores(PrefService* local_state) { 126 void ProfilePrefStoreManager::ResetAllPrefHashStores(PrefService* local_state) {
244 PrefServiceHashStoreContents::ResetAllPrefHashStores(local_state); 127 PrefServiceHashStoreContents::ResetAllPrefHashStores(local_state);
245 } 128 }
246 129
247 // static 130 // static
248 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { 131 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) {
249 return PrefHashFilter::GetResetTime(pref_service); 132 return PrefHashFilter::GetResetTime(pref_service);
250 } 133 }
251 134
252 // static 135 // static
253 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { 136 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) {
254 PrefHashFilter::ClearResetTime(pref_service); 137 PrefHashFilter::ClearResetTime(pref_service);
255 } 138 }
256 139
257 void ProfilePrefStoreManager::ResetPrefHashStore() {
258 if (kPlatformSupportsPreferenceTracking)
259 GetPrefHashStoreImpl()->Reset();
260 }
261
262 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore( 140 PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
263 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 141 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
264 TrackedPreferenceValidationDelegate* validation_delegate) { 142 TrackedPreferenceValidationDelegate* validation_delegate) {
265 scoped_ptr<PrefFilter> pref_filter; 143 scoped_ptr<PrefFilter> pref_filter;
266 if (!kPlatformSupportsPreferenceTracking) { 144 if (!kPlatformSupportsPreferenceTracking) {
267 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 145 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
268 io_task_runner, 146 io_task_runner,
269 scoped_ptr<PrefFilter>()); 147 scoped_ptr<PrefFilter>());
270 } 148 }
271 149
272 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 150 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
273 unprotected_configuration; 151 unprotected_configuration;
274 std::vector<PrefHashFilter::TrackedPreferenceMetadata> 152 std::vector<PrefHashFilter::TrackedPreferenceMetadata>
275 protected_configuration; 153 protected_configuration;
276 std::set<std::string> protected_pref_names; 154 std::set<std::string> protected_pref_names;
277 std::set<std::string> unprotected_pref_names; 155 std::set<std::string> unprotected_pref_names;
278 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator 156 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::const_iterator
279 it = tracking_configuration_.begin(); 157 it = tracking_configuration_.begin();
280 it != tracking_configuration_.end(); 158 it != tracking_configuration_.end();
281 ++it) { 159 ++it) {
282 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) { 160 if (it->enforcement_level > PrefHashFilter::NO_ENFORCEMENT) {
283 protected_configuration.push_back(*it); 161 protected_configuration.push_back(*it);
284 protected_pref_names.insert(it->name); 162 protected_pref_names.insert(it->name);
285 } else { 163 } else {
286 unprotected_configuration.push_back(*it); 164 unprotected_configuration.push_back(*it);
287 unprotected_pref_names.insert(it->name); 165 unprotected_pref_names.insert(it->name);
288 } 166 }
289 } 167 }
168 scoped_ptr<PrefHashStoreImpl> unprotected_pref_hash_store =
169 GetPrefHashStoreImpl(false);
170 scoped_ptr<PrefHashStoreImpl> protected_pref_hash_store =
171 GetPrefHashStoreImpl(true);
172 PrefHashStoreImpl* raw_unprotected_pref_hash_store =
173 unprotected_pref_hash_store.get();
174 PrefHashStoreImpl* raw_protected_pref_hash_store =
175 protected_pref_hash_store.get();
290 176
291 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter( 177 scoped_ptr<PrefHashFilter> unprotected_pref_hash_filter(
292 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 178 new PrefHashFilter(unprotected_pref_hash_store.PassAs<PrefHashStore>(),
293 unprotected_configuration, 179 unprotected_configuration,
294 validation_delegate, 180 validation_delegate,
295 reporting_ids_count_)); 181 reporting_ids_count_));
296 scoped_ptr<PrefHashFilter> protected_pref_hash_filter( 182 scoped_ptr<PrefHashFilter> protected_pref_hash_filter(
297 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 183 new PrefHashFilter(protected_pref_hash_store.PassAs<PrefHashStore>(),
298 protected_configuration, 184 protected_configuration,
299 validation_delegate, 185 validation_delegate,
300 reporting_ids_count_)); 186 reporting_ids_count_));
301 187
302 PrefHashFilter* raw_unprotected_pref_hash_filter = 188 PrefHashFilter* raw_unprotected_pref_hash_filter =
303 unprotected_pref_hash_filter.get(); 189 unprotected_pref_hash_filter.get();
304 PrefHashFilter* raw_protected_pref_hash_filter = 190 PrefHashFilter* raw_protected_pref_hash_filter =
305 protected_pref_hash_filter.get(); 191 protected_pref_hash_filter.get();
306 192
307 scoped_refptr<JsonPrefStore> unprotected_pref_store( 193 scoped_refptr<JsonPrefStore> unprotected_pref_store(
308 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 194 new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
309 io_task_runner, 195 io_task_runner,
310 unprotected_pref_hash_filter.PassAs<PrefFilter>())); 196 unprotected_pref_hash_filter.PassAs<PrefFilter>()));
311 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore( 197 scoped_refptr<JsonPrefStore> protected_pref_store(new JsonPrefStore(
312 profile_path_.Append(chrome::kProtectedPreferencesFilename), 198 profile_path_.Append(chrome::kProtectedPreferencesFilename),
313 io_task_runner, 199 io_task_runner,
314 protected_pref_hash_filter.PassAs<PrefFilter>())); 200 protected_pref_hash_filter.PassAs<PrefFilter>()));
315 201
202 scoped_ptr<HashStoreContents> unprotected_hash_store_contents(
203 new PrefStoreHashStoreContents(unprotected_pref_store));
204 scoped_ptr<HashStoreContents> protected_hash_store_contents(
205 new PrefStoreHashStoreContents(protected_pref_store));
206
207 raw_unprotected_pref_hash_store->SetHashStoreContents(
208 unprotected_hash_store_contents.Pass());
209 raw_protected_pref_hash_store->SetHashStoreContents(
210 protected_hash_store_contents.Pass());
211
316 SetupTrackedPreferencesMigration( 212 SetupTrackedPreferencesMigration(
317 unprotected_pref_names, 213 unprotected_pref_names,
318 protected_pref_names, 214 protected_pref_names,
319 base::Bind(&JsonPrefStore::RemoveValueSilently, 215 scoped_ptr<TrackedPreferencesMigrationDelegate>(
320 unprotected_pref_store->AsWeakPtr()), 216 new MigrationDelegateImpl(unprotected_pref_store->AsWeakPtr(),
321 base::Bind(&JsonPrefStore::RemoveValueSilently, 217 raw_unprotected_pref_hash_filter,
322 protected_pref_store->AsWeakPtr()), 218 raw_unprotected_pref_hash_store)),
323 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, 219 scoped_ptr<TrackedPreferencesMigrationDelegate>(
324 unprotected_pref_store->AsWeakPtr()), 220 new MigrationDelegateImpl(protected_pref_store->AsWeakPtr(),
325 base::Bind(&JsonPrefStore::RegisterOnNextSuccessfulWriteCallback, 221 raw_protected_pref_hash_filter,
326 protected_pref_store->AsWeakPtr()), 222 raw_protected_pref_hash_store)),
327 raw_unprotected_pref_hash_filter, 223 GetLegacyPrefHashStoreImpl().PassAs<PrefHashStore>());
328 raw_protected_pref_hash_filter);
329 224
330 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, 225 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
331 protected_pref_names); 226 protected_pref_names);
332 } 227 }
333 228
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( 229 bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
361 const base::DictionaryValue& master_prefs) { 230 const base::DictionaryValue& master_prefs) {
362 // Create the profile directory if it doesn't exist yet (very possible on 231 // Create the profile directory if it doesn't exist yet (very possible on
363 // first run). 232 // first run).
364 if (!base::CreateDirectory(profile_path_)) 233 if (!base::CreateDirectory(profile_path_))
365 return false; 234 return false;
366 235
236 scoped_ptr<base::DictionaryValue> protected_master_prefs;
237
238 if (kPlatformSupportsPreferenceTracking) {
239 protected_master_prefs.reset(master_prefs.DeepCopy());
240 scoped_refptr<WriteablePrefStore> pref_store(
241 new DictionaryPrefStore(protected_master_prefs.get()));
242 scoped_ptr<PrefHashStoreImpl> pref_hash_store(GetPrefHashStoreImpl(true));
243 pref_hash_store->SetHashStoreContents(scoped_ptr<HashStoreContents>(
244 new PrefStoreHashStoreContents(pref_store)));
245 PrefHashFilter(pref_hash_store.PassAs<PrefHashStore>(),
246 tracking_configuration_,
247 NULL,
248 reporting_ids_count_).Initialize(*pref_store);
249 }
250
367 // This will write out to a single combined file which will be immediately 251 // This will write out to a single combined file which will be immediately
368 // migrated to two files on load. 252 // migrated to two files on load.
369 JSONFileValueSerializer serializer( 253 JSONFileValueSerializer serializer(
370 GetPrefFilePathFromProfilePath(profile_path_)); 254 GetPrefFilePathFromProfilePath(profile_path_));
371 255
372 // Call Serialize (which does IO) on the main thread, which would _normally_ 256 // 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 257 // be verboten. In this case however, we require this IO to synchronously
374 // complete before Chrome can start (as master preferences seed the Local 258 // complete before Chrome can start (as master preferences seed the Local
375 // State and Preferences files). This won't trip ThreadIORestrictions as they 259 // State and Preferences files). This won't trip ThreadIORestrictions as they
376 // won't have kicked in yet on the main thread. 260 // won't have kicked in yet on the main thread.
377 bool success = serializer.Serialize(master_prefs); 261 bool success = serializer.Serialize(
378 262 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 263
388 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success); 264 UMA_HISTOGRAM_BOOLEAN("Settings.InitializedFromMasterPrefs", success);
389 return success; 265 return success;
390 } 266 }
391 267
392 PersistentPrefStore* 268 PersistentPrefStore*
393 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore( 269 ProfilePrefStoreManager::CreateDeprecatedCombinedProfilePrefStore(
394 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) { 270 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
395 scoped_ptr<PrefFilter> pref_filter; 271 scoped_ptr<PrefFilter> pref_filter;
396 if (kPlatformSupportsPreferenceTracking) { 272 if (kPlatformSupportsPreferenceTracking) {
397 pref_filter.reset( 273 pref_filter.reset(
398 new PrefHashFilter(GetPrefHashStoreImpl().PassAs<PrefHashStore>(), 274 new PrefHashFilter(GetLegacyPrefHashStoreImpl().PassAs<PrefHashStore>(),
399 tracking_configuration_, 275 tracking_configuration_,
400 NULL, 276 NULL,
401 reporting_ids_count_)); 277 reporting_ids_count_));
402 } 278 }
403 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_), 279 return new JsonPrefStore(GetPrefFilePathFromProfilePath(profile_path_),
404 io_task_runner, 280 io_task_runner,
405 pref_filter.Pass()); 281 pref_filter.Pass());
406 } 282 }
407 283
408 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl() { 284 scoped_ptr<PrefHashStoreImpl> ProfilePrefStoreManager::GetPrefHashStoreImpl(
285 bool use_super_mac) {
409 DCHECK(kPlatformSupportsPreferenceTracking); 286 DCHECK(kPlatformSupportsPreferenceTracking);
410 287
411 return make_scoped_ptr(new PrefHashStoreImpl( 288 return make_scoped_ptr(
412 seed_, 289 new PrefHashStoreImpl(seed_, device_id_, use_super_mac));
413 device_id_, 290 }
291
292 scoped_ptr<PrefHashStoreImpl>
293 ProfilePrefStoreManager::GetLegacyPrefHashStoreImpl() {
294 DCHECK(kPlatformSupportsPreferenceTracking);
295
296 scoped_ptr<PrefHashStoreImpl> instance(
297 new PrefHashStoreImpl(seed_, device_id_, false));
298 instance->SetHashStoreContents(
414 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents( 299 scoped_ptr<HashStoreContents>(new PrefServiceHashStoreContents(
415 profile_path_.AsUTF8Unsafe(), local_state_)))); 300 profile_path_.AsUTF8Unsafe(), local_state_)));
301 return instance.Pass();
416 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698