Chromium Code Reviews| 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/prefs_tracker/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/prefs_tracker/dictionary_hash_store_contents.h" | |
| 18 #include "components/prefs_tracker/pref_hash_store.h" | |
| 19 #include "components/prefs_tracker/pref_hash_store_transaction.h" | |
| 20 #include "components/prefs_tracker/pref_names.h" | |
| 21 #include "components/prefs_tracker/tracked_atomic_preference.h" | |
| 22 #include "components/prefs_tracker/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[] = { |
|
gab
2015/07/23 21:41:16
These used to move from c/b/prefs/chrome_pref_serv
blundell
2015/07/24 08:26:19
Could you elaborate a bit? Are you saying more blu
Jitu( very slow this week)
2015/07/24 09:09:23
sorry i couldn't get this. Can you please elaborat
| |
| 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 10 matching lines...) Expand all Loading... | |
| 56 report_super_mac_validity_(report_super_mac_validity) { | 56 report_super_mac_validity_(report_super_mac_validity) { |
| 57 DCHECK(pref_hash_store_); | 57 DCHECK(pref_hash_store_); |
| 58 DCHECK_GE(reporting_ids_count, tracked_preferences.size()); | 58 DCHECK_GE(reporting_ids_count, tracked_preferences.size()); |
| 59 | 59 |
| 60 for (size_t i = 0; i < tracked_preferences.size(); ++i) { | 60 for (size_t i = 0; i < tracked_preferences.size(); ++i) { |
| 61 const TrackedPreferenceMetadata& metadata = tracked_preferences[i]; | 61 const TrackedPreferenceMetadata& metadata = tracked_preferences[i]; |
| 62 | 62 |
| 63 scoped_ptr<TrackedPreference> tracked_preference; | 63 scoped_ptr<TrackedPreference> tracked_preference; |
| 64 switch (metadata.strategy) { | 64 switch (metadata.strategy) { |
| 65 case TRACKING_STRATEGY_ATOMIC: | 65 case TRACKING_STRATEGY_ATOMIC: |
| 66 tracked_preference.reset( | 66 tracked_preference.reset(new TrackedAtomicPreference( |
| 67 new TrackedAtomicPreference(metadata.name, | 67 metadata.name, metadata.reporting_id, reporting_ids_count, |
| 68 metadata.reporting_id, | 68 metadata.enforcement_level, metadata.value_type, delegate)); |
| 69 reporting_ids_count, | |
| 70 metadata.enforcement_level, | |
| 71 metadata.value_type, | |
| 72 delegate)); | |
| 73 break; | 69 break; |
| 74 case TRACKING_STRATEGY_SPLIT: | 70 case TRACKING_STRATEGY_SPLIT: |
| 75 tracked_preference.reset( | 71 tracked_preference.reset(new TrackedSplitPreference( |
| 76 new TrackedSplitPreference(metadata.name, | 72 metadata.name, metadata.reporting_id, reporting_ids_count, |
| 77 metadata.reporting_id, | 73 metadata.enforcement_level, metadata.value_type, delegate)); |
| 78 reporting_ids_count, | |
| 79 metadata.enforcement_level, | |
| 80 metadata.value_type, | |
| 81 delegate)); | |
| 82 break; | 74 break; |
| 83 } | 75 } |
| 84 DCHECK(tracked_preference); | 76 DCHECK(tracked_preference); |
| 85 | 77 |
| 86 bool is_new = tracked_paths_.add(metadata.name, | 78 bool is_new = |
| 87 tracked_preference.Pass()).second; | 79 tracked_paths_.add(metadata.name, tracked_preference.Pass()).second; |
| 88 DCHECK(is_new); | 80 DCHECK(is_new); |
| 89 } | 81 } |
| 90 } | 82 } |
| 91 | 83 |
| 92 PrefHashFilter::~PrefHashFilter() { | 84 PrefHashFilter::~PrefHashFilter() { |
| 93 // Ensure new values for all |changed_paths_| have been flushed to | 85 // Ensure new values for all |changed_paths_| have been flushed to |
| 94 // |pref_hash_store_| already. | 86 // |pref_hash_store_| already. |
| 95 DCHECK(changed_paths_.empty()); | 87 DCHECK(changed_paths_.empty()); |
| 96 } | 88 } |
| 97 | 89 |
| 98 // static | 90 // static |
| 99 void PrefHashFilter::RegisterProfilePrefs( | 91 void PrefHashFilter::RegisterProfilePrefs( |
| 100 user_prefs::PrefRegistrySyncable* registry) { | 92 user_prefs::PrefRegistrySyncable* registry) { |
| 101 // See GetResetTime for why this is a StringPref and not Int64Pref. | 93 // See GetResetTime for why this is a StringPref and not Int64Pref. |
| 102 registry->RegisterStringPref( | 94 registry->RegisterStringPref( |
| 103 prefs::kPreferenceResetTime, | 95 prefs::kPreferenceResetTime, |
| 104 base::Int64ToString(base::Time().ToInternalValue())); | 96 base::Int64ToString(base::Time().ToInternalValue())); |
| 105 } | 97 } |
| 106 | 98 |
| 107 // static | 99 // static |
| 108 base::Time PrefHashFilter::GetResetTime(PrefService* user_prefs) { | 100 base::Time PrefHashFilter::GetResetTime(PrefService* user_prefs) { |
| 109 // Provide our own implementation (identical to the PrefService::GetInt64) in | 101 // Provide our own implementation (identical to the PrefService::GetInt64) in |
| 110 // order to ensure it remains consistent with the way we store this value | 102 // order to ensure it remains consistent with the way we store this value |
| 111 // (which we do via a PrefStore, preventing us from reusing | 103 // (which we do via a PrefStore, preventing us from reusing |
| 112 // PrefService::SetInt64). | 104 // PrefService::SetInt64). |
| 113 int64 internal_value = base::Time().ToInternalValue(); | 105 int64 internal_value = base::Time().ToInternalValue(); |
| 114 if (!base::StringToInt64( | 106 if (!base::StringToInt64(user_prefs->GetString(prefs::kPreferenceResetTime), |
| 115 user_prefs->GetString(prefs::kPreferenceResetTime), | 107 &internal_value)) { |
| 116 &internal_value)) { | |
| 117 // Somehow the value stored on disk is not a valid int64. | 108 // Somehow the value stored on disk is not a valid int64. |
| 118 NOTREACHED(); | 109 NOTREACHED(); |
| 119 return base::Time(); | 110 return base::Time(); |
| 120 } | 111 } |
| 121 return base::Time::FromInternalValue(internal_value); | 112 return base::Time::FromInternalValue(internal_value); |
| 122 } | 113 } |
| 123 | 114 |
| 124 // static | 115 // static |
| 125 void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { | 116 void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { |
| 126 user_prefs->ClearPref(prefs::kPreferenceResetTime); | 117 user_prefs->ClearPref(prefs::kPreferenceResetTime); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 bool prefs_altered) { | 174 bool prefs_altered) { |
| 184 DCHECK(pref_store_contents); | 175 DCHECK(pref_store_contents); |
| 185 base::TimeTicks checkpoint = base::TimeTicks::Now(); | 176 base::TimeTicks checkpoint = base::TimeTicks::Now(); |
| 186 | 177 |
| 187 bool did_reset = false; | 178 bool did_reset = false; |
| 188 { | 179 { |
| 189 scoped_ptr<PrefHashStoreTransaction> hash_store_transaction( | 180 scoped_ptr<PrefHashStoreTransaction> hash_store_transaction( |
| 190 pref_hash_store_->BeginTransaction(scoped_ptr<HashStoreContents>( | 181 pref_hash_store_->BeginTransaction(scoped_ptr<HashStoreContents>( |
| 191 new DictionaryHashStoreContents(pref_store_contents.get())))); | 182 new DictionaryHashStoreContents(pref_store_contents.get())))); |
| 192 | 183 |
| 193 CleanupDeprecatedTrackedPreferences( | 184 CleanupDeprecatedTrackedPreferences(pref_store_contents.get(), |
| 194 pref_store_contents.get(), hash_store_transaction.get()); | 185 hash_store_transaction.get()); |
| 195 | 186 |
| 196 if (report_super_mac_validity_) { | 187 if (report_super_mac_validity_) { |
| 197 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", | 188 UMA_HISTOGRAM_BOOLEAN("Settings.HashesDictionaryTrusted", |
| 198 hash_store_transaction->IsSuperMACValid()); | 189 hash_store_transaction->IsSuperMACValid()); |
| 199 } | 190 } |
| 200 | 191 |
| 201 for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); | 192 for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); |
| 202 it != tracked_paths_.end(); ++it) { | 193 it != tracked_paths_.end(); ++it) { |
| 203 if (it->second->EnforceAndReport(pref_store_contents.get(), | 194 if (it->second->EnforceAndReport(pref_store_contents.get(), |
| 204 hash_store_transaction.get())) { | 195 hash_store_transaction.get())) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 221 } | 212 } |
| 222 | 213 |
| 223 // TODO(gab): Remove this histogram by Feb 21 2014; after sufficient timing | 214 // 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 | 215 // data has been gathered from the wild to be confident this doesn't |
| 225 // significantly affect startup. | 216 // significantly affect startup. |
| 226 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", | 217 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", |
| 227 base::TimeTicks::Now() - checkpoint); | 218 base::TimeTicks::Now() - checkpoint); |
| 228 | 219 |
| 229 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | 220 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); |
| 230 } | 221 } |
| OLD | NEW |