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

Unified Diff: chrome/browser/prefs/pref_hash_filter.cc

Issue 114223002: Multi-strategy based tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use base::ScopedPtrHashMap Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_hash_filter.cc
diff --git a/chrome/browser/prefs/pref_hash_filter.cc b/chrome/browser/prefs/pref_hash_filter.cc
index 524fbe2aa77e28a232a039f7083286540309a8f7..20c6b24db18dbd29b6966d3c4dd24aaa61a7999a 100644
--- a/chrome/browser/prefs/pref_hash_filter.cc
+++ b/chrome/browser/prefs/pref_hash_filter.cc
@@ -5,62 +5,45 @@
#include "chrome/browser/prefs/pref_hash_filter.h"
#include "base/logging.h"
-#include "base/metrics/histogram.h"
-#include "base/values.h"
-#include "chrome/common/pref_names.h"
+#include "chrome/browser/prefs/tracked_atomic_preference.h"
+#include "chrome/browser/prefs/tracked_split_preference.h"
-namespace {
+PrefHashFilter::PrefHashFilter(
+ scoped_ptr<PrefHashStore> pref_hash_store,
+ const TrackedPreferenceMetadata tracked_preferences[],
+ size_t tracked_preferences_size,
+ size_t reporting_ids_count,
+ TrackedPreferenceHelper::EnforcementLevel enforcement_level)
+ : pref_hash_store_(pref_hash_store.Pass()) {
+ DCHECK(pref_hash_store_);
+ DCHECK_GE(reporting_ids_count, tracked_preferences_size);
-void ReportValidationResult(PrefHashStore::ValueState value_state,
- size_t value_index,
- size_t num_values) {
- switch (value_state) {
- case PrefHashStore::UNCHANGED:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
- value_index, num_values);
- return;
- case PrefHashStore::CLEARED:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
- value_index, num_values);
- return;
- case PrefHashStore::MIGRATED:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceMigrated",
- value_index, num_values);
- return;
- case PrefHashStore::CHANGED:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
- value_index, num_values);
- return;
- case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
- value_index, num_values);
- return;
- case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
- value_index, num_values);
- return;
- }
- NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state;
-}
+ for (size_t i = 0; i < tracked_preferences_size; ++i) {
+ const TrackedPreferenceMetadata& metadata = tracked_preferences[i];
-} // namespace
+ TrackedPreferenceHelper::EnforcementLevel enforcement_level_for_pref =
+ metadata.allow_enforcement ? enforcement_level :
+ TrackedPreferenceHelper::NO_ENFORCEMENT;
-PrefHashFilter::PrefHashFilter(scoped_ptr<PrefHashStore> pref_hash_store,
- const TrackedPreference tracked_preferences[],
- size_t tracked_preferences_size,
- size_t reporting_ids_count,
- EnforcementLevel enforcement_level)
- : pref_hash_store_(pref_hash_store.Pass()),
- reporting_ids_count_(reporting_ids_count),
- enforce_(enforcement_level >= ENFORCE),
- no_seeding_(enforcement_level >= ENFORCE_NO_SEEDING),
- no_migration_(enforcement_level >= ENFORCE_NO_SEEDING_NO_MIGRATION) {
- DCHECK_GE(reporting_ids_count, tracked_preferences_size);
+ scoped_ptr<TrackedPreference> tracked_preference;
+ switch (metadata.strategy) {
+ case TRACKING_STRATEGY_ATOMIC:
+ tracked_preference.reset(
+ new TrackedAtomicPreference(metadata.name, metadata.reporting_id,
+ reporting_ids_count,
+ enforcement_level_for_pref));
+ break;
+ case TRACKING_STRATEGY_SPLIT:
+ tracked_preference.reset(
+ new TrackedSplitPreference(metadata.name, metadata.reporting_id,
+ reporting_ids_count,
+ enforcement_level_for_pref));
+ break;
+ }
+ DCHECK(tracked_preference);
- for (size_t i = 0; i < tracked_preferences_size; ++i) {
- bool is_new = tracked_paths_.insert(std::make_pair(
- std::string(tracked_preferences[i].name),
- tracked_preferences[i])).second;
+ bool is_new = tracked_paths_.add(metadata.name,
+ tracked_preference.Pass()).second;
DCHECK(is_new);
}
}
@@ -70,8 +53,9 @@ PrefHashFilter::~PrefHashFilter() {}
// Updates the stored hash to correspond to the updated preference value.
void PrefHashFilter::FilterUpdate(const std::string& path,
const base::Value* value) {
- if (tracked_paths_.find(path) != tracked_paths_.end())
- pref_hash_store_->StoreHash(path, value);
+ TrackedPreferencesMap::const_iterator it = tracked_paths_.find(path);
+ if (it != tracked_paths_.end())
+ it->second->StoreHash(value, pref_hash_store_.get());
}
// Validates loaded preference values according to stored hashes, reports
@@ -80,60 +64,6 @@ void PrefHashFilter::FilterOnLoad(base::DictionaryValue* pref_store_contents) {
DCHECK(pref_store_contents);
for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin();
it != tracked_paths_.end(); ++it) {
- const std::string& pref_path = it->first;
- const TrackedPreference& metadata = it->second;
- const base::Value* value = NULL;
- pref_store_contents->Get(pref_path, &value);
-
- PrefHashStore::ValueState value_state =
- pref_hash_store_->CheckValue(pref_path, value);
- ReportValidationResult(value_state, metadata.reporting_id,
- reporting_ids_count_);
-
- enum {
- DONT_RESET,
- WANTED_RESET,
- DO_RESET,
- } reset_state = DONT_RESET;
- if (metadata.allow_enforcement) {
- switch (value_state) {
- case PrefHashStore::UNCHANGED:
- // Desired case, nothing to do.
- break;
- case PrefHashStore::CLEARED:
- // Unfortunate case, but there is nothing we can do.
- break;
- case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
- // It is okay to seed the hash in this case.
- break;
- case PrefHashStore::MIGRATED:
- reset_state = no_migration_ ? DO_RESET : WANTED_RESET;
- break;
- case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
- reset_state = no_seeding_ ? DO_RESET : WANTED_RESET;
- break;
- case PrefHashStore::CHANGED:
- reset_state = enforce_ ? DO_RESET : WANTED_RESET;
- break;
- }
- }
-
- if (reset_state == DO_RESET) {
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
- metadata.reporting_id, reporting_ids_count_);
- // TODO(gab): Store the |old_value| to provide an undo UI.
- scoped_ptr<base::Value> old_value;
- pref_store_contents->RemovePath(pref_path, &old_value);
- } else if (reset_state == WANTED_RESET) {
- UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
- metadata.reporting_id, reporting_ids_count_);
- }
-
- if (value_state != PrefHashStore::UNCHANGED) {
- // Store the hash for the new value (whether it was reset or not).
- const base::Value* new_value = NULL;
- pref_store_contents->Get(pref_path, &new_value);
- pref_hash_store_->StoreHash(pref_path, new_value);
- }
+ it->second->EnforceAndReport(pref_hash_store_.get(), pref_store_contents);
}
}

Powered by Google App Engine
This is Rietveld 408576698