| Index: chrome/browser/prefs/tracked_split_preference.cc
|
| diff --git a/chrome/browser/prefs/tracked_split_preference.cc b/chrome/browser/prefs/tracked_split_preference.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b99c706dc9959824a6a431ec037375dd7652c007
|
| --- /dev/null
|
| +++ b/chrome/browser/prefs/tracked_split_preference.cc
|
| @@ -0,0 +1,89 @@
|
| +// 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_split_preference.h"
|
| +
|
| +#include <vector>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/metrics/histogram.h"
|
| +#include "base/values.h"
|
| +
|
| +TrackedSplitPreference::TrackedSplitPreference(
|
| + const std::string& pref_path,
|
| + size_t reporting_id,
|
| + size_t reporting_ids_count,
|
| + EnforcementLevel enforcement_level)
|
| + : TrackedPreference(reporting_id, reporting_ids_count, enforcement_level),
|
| + pref_path_(pref_path) {
|
| +}
|
| +
|
| +void TrackedSplitPreference::StoreHash(const base::Value* value,
|
| + PrefHashStore* pref_hash_store) const {
|
| + const base::DictionaryValue* dict_value = NULL;
|
| + if (value && !value->GetAsDictionary(&dict_value)) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| + pref_hash_store->StoreSplitHash(pref_path_, dict_value);
|
| +}
|
| +
|
| +void TrackedSplitPreference::EnforceAndReport(
|
| + PrefHashStore* pref_hash_store,
|
| + base::DictionaryValue* pref_store_contents) const {
|
| + base::DictionaryValue* dict_value = NULL;
|
| + if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
|
| + pref_store_contents->Get(pref_path_, NULL)) {
|
| + // There should be a dictionary or nothing at |pref_path_|.
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| + std::vector<std::string> invalid_keys;
|
| + PrefHashStore::ValueState value_state =
|
| + pref_hash_store->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
|
| +
|
| + if (value_state == PrefHashStore::CHANGED)
|
| + ReportSplitPreferenceChangedCount(invalid_keys.size());
|
| +
|
| + ReportValidationResult(value_state);
|
| +
|
| + ResetAction reset_action = GetAction(value_state);
|
| + ReportAction(reset_action);
|
| +
|
| + if (reset_action == DO_RESET) {
|
| + if (value_state == PrefHashStore::CHANGED) {
|
| + DCHECK(!invalid_keys.empty());
|
| +
|
| + for (std::vector<std::string>::const_iterator it =
|
| + invalid_keys.begin(); it != invalid_keys.end(); ++it) {
|
| + dict_value->Remove(*it, NULL);
|
| + }
|
| + } else {
|
| + pref_store_contents->RemovePath(pref_path_, NULL);
|
| + }
|
| + }
|
| +
|
| + if (value_state != PrefHashStore::UNCHANGED) {
|
| + // Store the hash for the new value (whether it was reset or not).
|
| + const base::DictionaryValue* new_dict_value = NULL;
|
| + pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
|
| + pref_hash_store->StoreSplitHash(pref_path_, new_dict_value);
|
| + }
|
| +}
|
| +
|
| +void TrackedSplitPreference::ReportSplitPreferenceChangedCount(
|
| + size_t count) const {
|
| + // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
|
| + // adapted to allow for a dynamically suffixed histogram name.
|
| + // Note: The factory creates and owns the histogram.
|
| + base::HistogramBase* histogram =
|
| + base::LinearHistogram::FactoryGet(
|
| + "Settings.TrackedSplitPreferenceChanged." + pref_path_,
|
| + 1,
|
| + 100, // Allow counts up to 100.
|
| + 101,
|
| + base::HistogramBase::kUmaTargetedHistogramFlag);
|
| + histogram->Add(count);
|
| +}
|
|
|