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

Side by Side Diff: chrome/browser/prefs/tracked_preference_helper.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 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_preference_helper.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9
10 TrackedPreferenceHelper::TrackedPreferenceHelper(
11 const std::string& pref_path,
12 size_t reporting_id,
13 size_t reporting_ids_count,
14 EnforcementLevel enforcement_level)
15 : pref_path_(pref_path),
16 reporting_id_(reporting_id), reporting_ids_count_(reporting_ids_count),
17 allow_changes_(enforcement_level < ENFORCE),
18 allow_seeding_(enforcement_level < ENFORCE_NO_SEEDING),
19 allow_migration_(enforcement_level < ENFORCE_NO_SEEDING_NO_MIGRATION) {
20 }
21
22 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction(
23 PrefHashStore::ValueState value_state) const {
24 switch (value_state) {
25 case PrefHashStore::UNCHANGED:
26 // Desired case, nothing to do.
27 return DONT_RESET;
28 case PrefHashStore::CLEARED:
29 // Unfortunate case, but there is nothing we can do.
30 return DONT_RESET;
31 case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
32 // It is okay to seed the hash in this case.
33 return DONT_RESET;
34 case PrefHashStore::MIGRATED:
35 return allow_migration_ ? WANTED_RESET : DO_RESET;
36 case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
37 return allow_seeding_ ? WANTED_RESET : DO_RESET;
38 case PrefHashStore::CHANGED:
39 return allow_changes_ ? WANTED_RESET : DO_RESET;
40 }
41 NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state;
42 return DONT_RESET;
43 }
44
45 void TrackedPreferenceHelper::ReportValidationResult(
46 PrefHashStore::ValueState value_state) const {
47 switch (value_state) {
48 case PrefHashStore::UNCHANGED:
49 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
50 reporting_id_, reporting_ids_count_);
51 return;
52 case PrefHashStore::CLEARED:
53 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
54 reporting_id_, reporting_ids_count_);
55 return;
56 case PrefHashStore::MIGRATED:
57 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceMigrated",
58 reporting_id_, reporting_ids_count_);
59 return;
60 case PrefHashStore::CHANGED:
61 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
62 reporting_id_, reporting_ids_count_);
63 return;
64 case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE:
65 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
66 reporting_id_, reporting_ids_count_);
67 return;
68 case PrefHashStore::TRUSTED_UNKNOWN_VALUE:
69 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
70 reporting_id_, reporting_ids_count_);
71 return;
72 }
73 NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state;
74 }
75
76 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const {
77 switch (reset_action) {
78 case DONT_RESET:
79 // No report for DONT_RESET.
80 break;
81 case WANTED_RESET:
82 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
83 reporting_id_, reporting_ids_count_);
84 break;
85 case DO_RESET:
86 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
87 reporting_id_, reporting_ids_count_);
88 break;
89 }
90 }
91
92 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount(
93 size_t count) const {
94 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
95 // adapted to allow for a dynamically suffixed histogram name.
96 // Note: The factory creates and owns the histogram.
97 base::HistogramBase* histogram =
98 base::LinearHistogram::FactoryGet(
99 "Settings.TrackedSplitPreferenceChanged." + pref_path_,
100 1,
101 100, // Allow counts up to 100.
102 101,
103 base::HistogramBase::kUmaTargetedHistogramFlag);
104 histogram->Add(count);
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698