| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tracked/pref_hash_filter.h" | 5 #include "components/user_prefs/tracked/pref_hash_filter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/pref_store.h" | 12 #include "base/prefs/pref_store.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h" | |
| 17 #include "chrome/browser/prefs/tracked/pref_hash_store.h" | |
| 18 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | |
| 19 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h" | |
| 20 #include "chrome/browser/prefs/tracked/tracked_split_preference.h" | |
| 21 #include "chrome/common/pref_names.h" | |
| 22 #include "components/pref_registry/pref_registry_syncable.h" | 16 #include "components/pref_registry/pref_registry_syncable.h" |
| 17 #include "components/user_prefs/tracked/dictionary_hash_store_contents.h" |
| 18 #include "components/user_prefs/tracked/pref_hash_store.h" |
| 19 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
| 20 #include "components/user_prefs/tracked/pref_names.h" |
| 21 #include "components/user_prefs/tracked/tracked_atomic_preference.h" |
| 22 #include "components/user_prefs/tracked/tracked_split_preference.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 void CleanupDeprecatedTrackedPreferences( | 26 void CleanupDeprecatedTrackedPreferences( |
| 27 base::DictionaryValue* pref_store_contents, | 27 base::DictionaryValue* pref_store_contents, |
| 28 PrefHashStoreTransaction* hash_store_transaction) { | 28 PrefHashStoreTransaction* hash_store_transaction) { |
| 29 // Add deprecated previously tracked preferences below for them to be cleaned | 29 // Add deprecated previously tracked preferences below for them to be cleaned |
| 30 // up from both the pref files and the hash store. | 30 // up from both the pref files and the hash store. |
| 31 static const char* const kDeprecatedTrackedPreferences[] = { | 31 static const char* const kDeprecatedTrackedPreferences[] = { |
| 32 // TODO(grt): Remove in M44+. | 32 // TODO(grt): Remove in M44+. |
| 33 "safebrowsing.incident_report_sent", | 33 "safebrowsing.incident_report_sent", |
| 34 // TODO(mad): Remove in M48+. | 34 // TODO(mad): Remove in M48+. |
| 35 "software_reporter.prompt_reason", | 35 "software_reporter.prompt_reason", |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 for (size_t i = 0; i < arraysize(kDeprecatedTrackedPreferences); ++i) { | 38 for (size_t i = 0; i < arraysize(kDeprecatedTrackedPreferences); ++i) { |
| 39 const char* key = kDeprecatedTrackedPreferences[i]; | 39 const char* key = kDeprecatedTrackedPreferences[i]; |
| 40 pref_store_contents->Remove(key, NULL); | 40 pref_store_contents->Remove(key, NULL); |
| 41 hash_store_transaction->ClearHash(key); | 41 hash_store_transaction->ClearHash(key); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Ensure new values for all |changed_paths_| have been flushed to | 93 // Ensure new values for all |changed_paths_| have been flushed to |
| 94 // |pref_hash_store_| already. | 94 // |pref_hash_store_| already. |
| 95 DCHECK(changed_paths_.empty()); | 95 DCHECK(changed_paths_.empty()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 void PrefHashFilter::RegisterProfilePrefs( | 99 void PrefHashFilter::RegisterProfilePrefs( |
| 100 user_prefs::PrefRegistrySyncable* registry) { | 100 user_prefs::PrefRegistrySyncable* registry) { |
| 101 // See GetResetTime for why this is a StringPref and not Int64Pref. | 101 // See GetResetTime for why this is a StringPref and not Int64Pref. |
| 102 registry->RegisterStringPref( | 102 registry->RegisterStringPref( |
| 103 prefs::kPreferenceResetTime, | 103 user_prefs::kPreferenceResetTime, |
| 104 base::Int64ToString(base::Time().ToInternalValue())); | 104 base::Int64ToString(base::Time().ToInternalValue())); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // static | 107 // static |
| 108 base::Time PrefHashFilter::GetResetTime(PrefService* user_prefs) { | 108 base::Time PrefHashFilter::GetResetTime(PrefService* user_prefs) { |
| 109 // Provide our own implementation (identical to the PrefService::GetInt64) in | 109 // Provide our own implementation (identical to the PrefService::GetInt64) in |
| 110 // order to ensure it remains consistent with the way we store this value | 110 // order to ensure it remains consistent with the way we store this value |
| 111 // (which we do via a PrefStore, preventing us from reusing | 111 // (which we do via a PrefStore, preventing us from reusing |
| 112 // PrefService::SetInt64). | 112 // PrefService::SetInt64). |
| 113 int64 internal_value = base::Time().ToInternalValue(); | 113 int64 internal_value = base::Time().ToInternalValue(); |
| 114 if (!base::StringToInt64( | 114 if (!base::StringToInt64( |
| 115 user_prefs->GetString(prefs::kPreferenceResetTime), | 115 user_prefs->GetString(user_prefs::kPreferenceResetTime), |
| 116 &internal_value)) { | 116 &internal_value)) { |
| 117 // Somehow the value stored on disk is not a valid int64. | 117 // Somehow the value stored on disk is not a valid int64. |
| 118 NOTREACHED(); | 118 NOTREACHED(); |
| 119 return base::Time(); | 119 return base::Time(); |
| 120 } | 120 } |
| 121 return base::Time::FromInternalValue(internal_value); | 121 return base::Time::FromInternalValue(internal_value); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // static | 124 // static |
| 125 void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { | 125 void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { |
| 126 user_prefs->ClearPref(prefs::kPreferenceResetTime); | 126 user_prefs->ClearPref(user_prefs::kPreferenceResetTime); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void PrefHashFilter::Initialize(base::DictionaryValue* pref_store_contents) { | 129 void PrefHashFilter::Initialize(base::DictionaryValue* pref_store_contents) { |
| 130 scoped_ptr<PrefHashStoreTransaction> hash_store_transaction( | 130 scoped_ptr<PrefHashStoreTransaction> hash_store_transaction( |
| 131 pref_hash_store_->BeginTransaction(scoped_ptr<HashStoreContents>( | 131 pref_hash_store_->BeginTransaction(scoped_ptr<HashStoreContents>( |
| 132 new DictionaryHashStoreContents(pref_store_contents)))); | 132 new DictionaryHashStoreContents(pref_store_contents)))); |
| 133 for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); | 133 for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); |
| 134 it != tracked_paths_.end(); ++it) { | 134 it != tracked_paths_.end(); ++it) { |
| 135 const std::string& initialized_path = it->first; | 135 const std::string& initialized_path = it->first; |
| 136 const TrackedPreference* initialized_preference = it->second; | 136 const TrackedPreference* initialized_preference = it->second; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 hash_store_transaction.get())) { | 204 hash_store_transaction.get())) { |
| 205 did_reset = true; | 205 did_reset = true; |
| 206 prefs_altered = true; | 206 prefs_altered = true; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 if (hash_store_transaction->StampSuperMac()) | 209 if (hash_store_transaction->StampSuperMac()) |
| 210 prefs_altered = true; | 210 prefs_altered = true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 if (did_reset) { | 213 if (did_reset) { |
| 214 pref_store_contents->Set(prefs::kPreferenceResetTime, | 214 pref_store_contents->Set(user_prefs::kPreferenceResetTime, |
| 215 new base::StringValue(base::Int64ToString( | 215 new base::StringValue(base::Int64ToString( |
| 216 base::Time::Now().ToInternalValue()))); | 216 base::Time::Now().ToInternalValue()))); |
| 217 FilterUpdate(prefs::kPreferenceResetTime); | 217 FilterUpdate(user_prefs::kPreferenceResetTime); |
| 218 | 218 |
| 219 if (!on_reset_on_load_.is_null()) | 219 if (!on_reset_on_load_.is_null()) |
| 220 on_reset_on_load_.Run(); | 220 on_reset_on_load_.Run(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 // TODO(gab): Remove this histogram by Feb 21 2014; after sufficient timing | 223 // TODO(gab): Remove this histogram by Feb 21 2014; after sufficient timing |
| 224 // data has been gathered from the wild to be confident this doesn't | 224 // data has been gathered from the wild to be confident this doesn't |
| 225 // significantly affect startup. | 225 // significantly affect startup. |
| 226 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", | 226 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", |
| 227 base::TimeTicks::Now() - checkpoint); | 227 base::TimeTicks::Now() - checkpoint); |
| 228 | 228 |
| 229 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | 229 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); |
| 230 } | 230 } |
| OLD | NEW |