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

Side by Side Diff: chrome/browser/prefs/tracked_split_preference.cc

Issue 114223002: Multi-strategy based tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang compile? 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/prefs/tracked_split_preference.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/metrics/histogram.h"
11 #include "base/values.h"
12
13 TrackedSplitPreference::TrackedSplitPreference(
14 const std::string& pref_path,
15 size_t reporting_id,
16 size_t reporting_ids_count,
17 EnforcementLevel enforcement_level)
18 : TrackedPreference(reporting_id, reporting_ids_count, enforcement_level),
19 pref_path_(pref_path) {
20 }
21
22 void TrackedSplitPreference::StoreHash(const base::Value* value,
23 PrefHashStore* pref_hash_store) const {
24 const base::DictionaryValue* dict_value = NULL;
25 if (value && !value->GetAsDictionary(&dict_value)) {
26 NOTREACHED();
27 return;
28 }
29 pref_hash_store->StoreSplitHash(pref_path_, dict_value);
30 }
31
32 void TrackedSplitPreference::EnforceAndReport(
33 PrefHashStore* pref_hash_store,
34 base::DictionaryValue* pref_store_contents) const {
35 base::DictionaryValue* dict_value = NULL;
36 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
37 pref_store_contents->Get(pref_path_, NULL)) {
38 // There should be a dictionary or nothing at |pref_path_|.
39 NOTREACHED();
40 return;
41 }
42
43 std::vector<std::string> invalid_keys;
44 PrefHashStore::ValueState value_state =
45 pref_hash_store->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
46
47 if (value_state == PrefHashStore::CHANGED)
48 ReportSplitPreferenceChangedCount(invalid_keys.size());
49
50 ReportValidationResult(value_state);
51
52 ResetAction reset_action = GetAction(value_state);
53 ReportAction(reset_action);
54
55 if (reset_action == DO_RESET) {
56 if (value_state == PrefHashStore::CHANGED) {
57 DCHECK(!invalid_keys.empty());
58
59 for (std::vector<std::string>::const_iterator it =
60 invalid_keys.begin(); it != invalid_keys.end(); ++it) {
61 dict_value->Remove(*it, NULL);
62 }
63 } else {
64 pref_store_contents->RemovePath(pref_path_, NULL);
65 }
66 }
67
68 if (value_state != PrefHashStore::UNCHANGED) {
69 // Store the hash for the new value (whether it was reset or not).
70 const base::DictionaryValue* new_dict_value = NULL;
71 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
72 pref_hash_store->StoreSplitHash(pref_path_, new_dict_value);
73 }
74 }
75
76 void TrackedSplitPreference::ReportSplitPreferenceChangedCount(
77 size_t count) const {
78 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
79 // adapted to allow for a dynamically suffixed histogram name.
80 // Note: The factory creates and owns the histogram.
81 base::HistogramBase* histogram =
82 base::LinearHistogram::FactoryGet(
83 "Settings.TrackedSplitPreferenceChanged." + pref_path_,
84 1,
85 100, // Allow counts up to 100.
86 101,
87 base::HistogramBase::kUmaTargetedHistogramFlag);
88 histogram->Add(count);
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698