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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 125 } |
126 | 126 |
127 private: | 127 private: |
128 virtual ~DictionaryPrefStore() {} | 128 virtual ~DictionaryPrefStore() {} |
129 | 129 |
130 const base::DictionaryValue* dictionary_; | 130 const base::DictionaryValue* dictionary_; |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); | 132 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); |
133 }; | 133 }; |
134 | 134 |
135 } // namespace | |
136 | |
137 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved | |
138 // out of Local State. This will resolve a race condition on Android and a | |
139 // privacy issue on ChromeOS. http://crbug.com/349158 | |
140 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = | |
141 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
142 false; | |
143 #else | |
144 true; | |
145 #endif | |
146 | |
147 // Waits for a PrefStore to be initialized and then initializes the | 135 // Waits for a PrefStore to be initialized and then initializes the |
148 // corresponding PrefHashStore. | 136 // corresponding PrefHashStore. |
149 // The observer deletes itself when its work is completed. | 137 // The observer deletes itself when its work is completed. |
150 class ProfilePrefStoreManager::InitializeHashStoreObserver | 138 class InitializeHashStoreObserver : public PrefStore::Observer { |
151 : public PrefStore::Observer { | |
152 public: | 139 public: |
153 // Creates an observer that will initialize |pref_hash_store| with the | 140 // Creates an observer that will initialize |pref_hash_store| with the |
154 // contents of |pref_store| when the latter is fully loaded. | 141 // contents of |pref_store| when the latter is fully loaded. |
155 InitializeHashStoreObserver( | 142 InitializeHashStoreObserver( |
156 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& | 143 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& |
157 tracking_configuration, | 144 tracking_configuration, |
158 size_t reporting_ids_count, | 145 size_t reporting_ids_count, |
159 const scoped_refptr<PrefStore>& pref_store, | 146 const scoped_refptr<PrefStore>& pref_store, |
160 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl) | 147 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl) |
161 : tracking_configuration_(tracking_configuration), | 148 : tracking_configuration_(tracking_configuration), |
(...skipping 10 matching lines...) Expand all Loading... |
172 private: | 159 private: |
173 const std::vector<PrefHashFilter::TrackedPreferenceMetadata> | 160 const std::vector<PrefHashFilter::TrackedPreferenceMetadata> |
174 tracking_configuration_; | 161 tracking_configuration_; |
175 const size_t reporting_ids_count_; | 162 const size_t reporting_ids_count_; |
176 scoped_refptr<PrefStore> pref_store_; | 163 scoped_refptr<PrefStore> pref_store_; |
177 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl_; | 164 scoped_ptr<PrefHashStoreImpl> pref_hash_store_impl_; |
178 | 165 |
179 DISALLOW_COPY_AND_ASSIGN(InitializeHashStoreObserver); | 166 DISALLOW_COPY_AND_ASSIGN(InitializeHashStoreObserver); |
180 }; | 167 }; |
181 | 168 |
182 ProfilePrefStoreManager::InitializeHashStoreObserver:: | 169 InitializeHashStoreObserver::~InitializeHashStoreObserver() {} |
183 ~InitializeHashStoreObserver() {} | |
184 | 170 |
185 void ProfilePrefStoreManager::InitializeHashStoreObserver::OnPrefValueChanged( | 171 void InitializeHashStoreObserver::OnPrefValueChanged(const std::string& key) {} |
186 const std::string& key) {} | |
187 | 172 |
188 void | 173 void InitializeHashStoreObserver::OnInitializationCompleted(bool succeeded) { |
189 ProfilePrefStoreManager::InitializeHashStoreObserver::OnInitializationCompleted( | |
190 bool succeeded) { | |
191 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl | 174 // If we successfully loaded the preferences _and_ the PrefHashStoreImpl |
192 // hasn't been initialized by someone else in the meantime, initialize it now. | 175 // hasn't been initialized by someone else in the meantime, initialize it now. |
193 const PrefHashStoreImpl::StoreVersion pre_update_version = | 176 const PrefHashStoreImpl::StoreVersion pre_update_version = |
194 pref_hash_store_impl_->GetCurrentVersion(); | 177 pref_hash_store_impl_->GetCurrentVersion(); |
195 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) { | 178 if (succeeded && pre_update_version < PrefHashStoreImpl::VERSION_LATEST) { |
196 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(), | 179 PrefHashFilter(pref_hash_store_impl_.PassAs<PrefHashStore>(), |
197 tracking_configuration_, | 180 tracking_configuration_, |
198 reporting_ids_count_).Initialize(*pref_store_); | 181 reporting_ids_count_).Initialize(*pref_store_); |
199 UMA_HISTOGRAM_ENUMERATION( | 182 UMA_HISTOGRAM_ENUMERATION( |
200 "Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom", | 183 "Settings.TrackedPreferencesAlternateStoreVersionUpdatedFrom", |
201 pre_update_version, | 184 pre_update_version, |
202 PrefHashStoreImpl::VERSION_LATEST + 1); | 185 PrefHashStoreImpl::VERSION_LATEST + 1); |
203 } | 186 } |
204 pref_store_->RemoveObserver(this); | 187 pref_store_->RemoveObserver(this); |
205 delete this; | 188 delete this; |
206 } | 189 } |
207 | 190 |
| 191 } // namespace |
| 192 |
| 193 // TODO(erikwright): Enable this on Chrome OS and Android once MACs are moved |
| 194 // out of Local State. This will resolve a race condition on Android and a |
| 195 // privacy issue on ChromeOS. http://crbug.com/349158 |
| 196 const bool ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking = |
| 197 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 198 false; |
| 199 #else |
| 200 true; |
| 201 #endif |
| 202 |
208 ProfilePrefStoreManager::ProfilePrefStoreManager( | 203 ProfilePrefStoreManager::ProfilePrefStoreManager( |
209 const base::FilePath& profile_path, | 204 const base::FilePath& profile_path, |
210 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& | 205 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>& |
211 tracking_configuration, | 206 tracking_configuration, |
212 size_t reporting_ids_count, | 207 size_t reporting_ids_count, |
213 const std::string& seed, | 208 const std::string& seed, |
214 const std::string& device_id, | 209 const std::string& device_id, |
215 PrefService* local_state) | 210 PrefService* local_state) |
216 : profile_path_(profile_path), | 211 : profile_path_(profile_path), |
217 tracking_configuration_(tracking_configuration), | 212 tracking_configuration_(tracking_configuration), |
(...skipping 28 matching lines...) Expand all Loading... |
246 | 241 |
247 // static | 242 // static |
248 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { | 243 base::Time ProfilePrefStoreManager::GetResetTime(PrefService* pref_service) { |
249 // It's a bit of a coincidence that this (and ClearResetTime) work(s). The | 244 // It's a bit of a coincidence that this (and ClearResetTime) work(s). The |
250 // PrefHashFilter attached to the protected pref store will store the reset | 245 // PrefHashFilter attached to the protected pref store will store the reset |
251 // time directly in the protected pref store without going through the | 246 // time directly in the protected pref store without going through the |
252 // SegregatedPrefStore. | 247 // SegregatedPrefStore. |
253 | 248 |
254 // PrefHashFilter::GetResetTime will read the value through the pref service, | 249 // PrefHashFilter::GetResetTime will read the value through the pref service, |
255 // and thus through the SegregatedPrefStore. Even though it's not listed as | 250 // and thus through the SegregatedPrefStore. Even though it's not listed as |
256 // "protected" it will be read from the protected store prefentially to the | 251 // "protected" it will be read from the protected store preferentially to the |
257 // (NULL) value in the unprotected pref store. | 252 // (NULL) value in the unprotected pref store. |
258 return PrefHashFilter::GetResetTime(pref_service); | 253 return PrefHashFilter::GetResetTime(pref_service); |
259 } | 254 } |
260 | 255 |
261 // static | 256 // static |
262 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { | 257 void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) { |
263 // PrefHashFilter::ClearResetTime will clear the value through the pref | 258 // PrefHashFilter::ClearResetTime will clear the value through the pref |
264 // service, and thus through the SegregatedPrefStore. Since it's not listed as | 259 // service, and thus through the SegregatedPrefStore. Since it's not listed as |
265 // "protected" it will be migrated from the protected store to the unprotected | 260 // "protected" it will be migrated from the protected store to the unprotected |
266 // pref store before being deleted from the latter. | 261 // pref store before being deleted from the latter. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 DCHECK(kPlatformSupportsPreferenceTracking); | 413 DCHECK(kPlatformSupportsPreferenceTracking); |
419 | 414 |
420 PrefServiceHashStoreContents real_contents(profile_path_.AsUTF8Unsafe(), | 415 PrefServiceHashStoreContents real_contents(profile_path_.AsUTF8Unsafe(), |
421 local_state_); | 416 local_state_); |
422 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( | 417 return scoped_ptr<PrefHashStore>(new PrefHashStoreImpl( |
423 seed_, | 418 seed_, |
424 device_id_, | 419 device_id_, |
425 scoped_ptr<HashStoreContents>( | 420 scoped_ptr<HashStoreContents>( |
426 new DictionaryHashStoreContents(real_contents)))); | 421 new DictionaryHashStoreContents(real_contents)))); |
427 } | 422 } |
OLD | NEW |