| Index: chrome/browser/prefs/tracked_preference.cc
|
| diff --git a/chrome/browser/prefs/tracked_preference.cc b/chrome/browser/prefs/tracked_preference.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f5e2d5795d5cae1bbff5faeffd9c690fa9db2972
|
| --- /dev/null
|
| +++ b/chrome/browser/prefs/tracked_preference.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/prefs/tracked_preference.h"
|
| +
|
| +#include "base/metrics/histogram.h"
|
| +
|
| +TrackedPreference::TrackedPreference(size_t reporting_id,
|
| + size_t reporting_ids_count,
|
| + EnforcementLevel enforcement_level)
|
| + : reporting_id_(reporting_id), reporting_ids_count_(reporting_ids_count),
|
| + allow_changes_(enforcement_level < ENFORCE),
|
| + allow_seeding_(enforcement_level < ENFORCE_NO_SEEDING),
|
| + allow_migration_(enforcement_level < ENFORCE_NO_SEEDING_NO_MIGRATION) {
|
| +}
|
| +
|
| +TrackedPreference::ResetAction TrackedPreference::GetAction(
|
| + PrefHashStore::ValueState value_state) const {
|
| + switch (value_state) {
|
| + case PrefHashStore::UNCHANGED:
|
| + // Desired case, nothing to do.
|
| + return DONT_RESET;
|
| + case PrefHashStore::CLEARED:
|
| + // Unfortunate case, but there is nothing we can do.
|
| + return DONT_RESET;
|
| + case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
|
| + // It is okay to seed the hash in this case.
|
| + return DONT_RESET;
|
| + case PrefHashStore::MIGRATED:
|
| + return allow_migration_ ? WANTED_RESET : DO_RESET;
|
| + case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
|
| + return allow_seeding_ ? WANTED_RESET : DO_RESET;
|
| + case PrefHashStore::CHANGED:
|
| + return allow_changes_ ? WANTED_RESET : DO_RESET;
|
| + }
|
| + NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state;
|
| + return DONT_RESET;
|
| +}
|
| +
|
| +void TrackedPreference::ReportValidationResult(
|
| + PrefHashStore::ValueState value_state) const {
|
| + switch (value_state) {
|
| + case PrefHashStore::UNCHANGED:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + case PrefHashStore::CLEARED:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + case PrefHashStore::MIGRATED:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceMigrated",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + case PrefHashStore::CHANGED:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
|
| + reporting_id_, reporting_ids_count_);
|
| + return;
|
| + }
|
| + NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state;
|
| +}
|
| +
|
| +void TrackedPreference::ReportAction(ResetAction reset_action) const {
|
| + switch (reset_action) {
|
| + case DONT_RESET:
|
| + // No report for DONT_RESET.
|
| + break;
|
| + case WANTED_RESET:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
|
| + reporting_id_, reporting_ids_count_);
|
| + break;
|
| + case DO_RESET:
|
| + UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
|
| + reporting_id_, reporting_ids_count_);
|
| + break;
|
| + }
|
| +}
|
|
|