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

Side by Side Diff: components/user_prefs/tracked/tracked_preference_helper.cc

Issue 1519043002: Putting histogram names of tracked prefs in tracked_preference_histogram_name file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Putting tracked namespace under user_prefs namespace. Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/user_prefs/tracked/tracked_preference_helper.h" 5 #include "components/user_prefs/tracked/tracked_preference_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h"
9 10
10 TrackedPreferenceHelper::TrackedPreferenceHelper( 11 TrackedPreferenceHelper::TrackedPreferenceHelper(
11 const std::string& pref_path, 12 const std::string& pref_path,
12 size_t reporting_id, 13 size_t reporting_id,
13 size_t reporting_ids_count, 14 size_t reporting_ids_count,
14 PrefHashFilter::EnforcementLevel enforcement_level, 15 PrefHashFilter::EnforcementLevel enforcement_level,
15 PrefHashFilter::ValueType value_type) 16 PrefHashFilter::ValueType value_type)
16 : pref_path_(pref_path), 17 : pref_path_(pref_path),
17 reporting_id_(reporting_id), 18 reporting_id_(reporting_id),
18 reporting_ids_count_(reporting_ids_count), 19 reporting_ids_count_(reporting_ids_count),
19 enforce_(enforcement_level == PrefHashFilter::ENFORCE_ON_LOAD), 20 enforce_(enforcement_level == PrefHashFilter::ENFORCE_ON_LOAD),
20 personal_(value_type == PrefHashFilter::VALUE_PERSONAL) { 21 personal_(value_type == PrefHashFilter::VALUE_PERSONAL) {
21 } 22 }
22 23
23 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction( 24 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction(
24 PrefHashStoreTransaction::ValueState value_state) const { 25 PrefHashStoreTransaction::ValueState value_state) const {
25 switch (value_state) { 26 switch (value_state) {
26 case PrefHashStoreTransaction::UNCHANGED: 27 case PrefHashStoreTransaction::UNCHANGED: // Desired case, nothing to do.
27 // Desired case, nothing to do. 28 case PrefHashStoreTransaction::CLEARED: // Unfortunate case, nothing to do.
28 return DONT_RESET;
29 case PrefHashStoreTransaction::CLEARED:
30 // Unfortunate case, but there is nothing we can do.
31 return DONT_RESET;
32 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: // Falls through. 29 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: // Falls through.
33 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: 30 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: // Seed the hash.
34 // It is okay to seed the hash in this case.
35 return DONT_RESET;
gab 2015/12/14 19:29:27 I preferred this format as it groups things that a
Deepak 2015/12/15 04:39:36 Done.
36 case PrefHashStoreTransaction::SECURE_LEGACY: 31 case PrefHashStoreTransaction::SECURE_LEGACY:
37 // Accept secure legacy device ID based hashes. 32 // Accept secure legacy device ID based hashes.
38 return DONT_RESET; 33 return DONT_RESET;
39 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through. 34 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through.
40 case PrefHashStoreTransaction::CHANGED: 35 case PrefHashStoreTransaction::CHANGED:
41 return enforce_ ? DO_RESET : WANTED_RESET; 36 return enforce_ ? DO_RESET : WANTED_RESET;
42 } 37 }
43 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " 38 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
44 << value_state; 39 << value_state;
45 return DONT_RESET; 40 return DONT_RESET;
46 } 41 }
47 42
48 bool TrackedPreferenceHelper::IsPersonal() const { 43 bool TrackedPreferenceHelper::IsPersonal() const {
49 return personal_; 44 return personal_;
50 } 45 }
51 46
52 void TrackedPreferenceHelper::ReportValidationResult( 47 void TrackedPreferenceHelper::ReportValidationResult(
53 PrefHashStoreTransaction::ValueState value_state) const { 48 PrefHashStoreTransaction::ValueState value_state) const {
54 switch (value_state) { 49 switch (value_state) {
55 case PrefHashStoreTransaction::UNCHANGED: 50 case PrefHashStoreTransaction::UNCHANGED:
56 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged", 51 UMA_HISTOGRAM_ENUMERATION(
57 reporting_id_, reporting_ids_count_); 52 user_prefs::tracked::kTrackedPrefHistogramUnchanged, reporting_id_,
53 reporting_ids_count_);
58 return; 54 return;
59 case PrefHashStoreTransaction::CLEARED: 55 case PrefHashStoreTransaction::CLEARED:
60 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared", 56 UMA_HISTOGRAM_ENUMERATION(
61 reporting_id_, reporting_ids_count_); 57 user_prefs::tracked::kTrackedPrefHistogramCleared, reporting_id_,
58 reporting_ids_count_);
62 return; 59 return;
63 case PrefHashStoreTransaction::SECURE_LEGACY: 60 case PrefHashStoreTransaction::SECURE_LEGACY:
64 UMA_HISTOGRAM_ENUMERATION( 61 UMA_HISTOGRAM_ENUMERATION(
65 "Settings.TrackedPreferenceMigratedLegacyDeviceId", reporting_id_, 62 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId,
63 reporting_id_, reporting_ids_count_);
64 return;
65 case PrefHashStoreTransaction::CHANGED:
66 UMA_HISTOGRAM_ENUMERATION(
67 user_prefs::tracked::kTrackedPrefHistogramChanged, reporting_id_,
66 reporting_ids_count_); 68 reporting_ids_count_);
67 return; 69 return;
68 case PrefHashStoreTransaction::CHANGED:
69 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
70 reporting_id_, reporting_ids_count_);
71 return;
72 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: 70 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE:
73 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", 71 UMA_HISTOGRAM_ENUMERATION(
74 reporting_id_, reporting_ids_count_); 72 user_prefs::tracked::kTrackedPrefHistogramInitialized, reporting_id_,
73 reporting_ids_count_);
75 return; 74 return;
76 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: 75 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE:
77 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized", 76 UMA_HISTOGRAM_ENUMERATION(
78 reporting_id_, reporting_ids_count_); 77 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized,
78 reporting_id_, reporting_ids_count_);
79 return; 79 return;
80 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: 80 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE:
81 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceNullInitialized", 81 UMA_HISTOGRAM_ENUMERATION(
82 reporting_id_, reporting_ids_count_); 82 user_prefs::tracked::kTrackedPrefHistogramNullInitialized,
83 reporting_id_, reporting_ids_count_);
83 return; 84 return;
84 } 85 }
85 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " 86 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
86 << value_state; 87 << value_state;
87 } 88 }
88 89
89 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const { 90 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const {
90 switch (reset_action) { 91 switch (reset_action) {
91 case DONT_RESET: 92 case DONT_RESET:
92 // No report for DONT_RESET. 93 // No report for DONT_RESET.
93 break; 94 break;
94 case WANTED_RESET: 95 case WANTED_RESET:
95 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset", 96 UMA_HISTOGRAM_ENUMERATION(
96 reporting_id_, reporting_ids_count_); 97 user_prefs::tracked::kTrackedPrefHistogramWantedReset, reporting_id_,
98 reporting_ids_count_);
97 break; 99 break;
98 case DO_RESET: 100 case DO_RESET:
99 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset", 101 UMA_HISTOGRAM_ENUMERATION(user_prefs::tracked::kTrackedPrefHistogramReset,
100 reporting_id_, reporting_ids_count_); 102 reporting_id_, reporting_ids_count_);
101 break; 103 break;
102 } 104 }
103 } 105 }
104 106
105 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount( 107 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount(
106 size_t count) const { 108 size_t count) const {
107 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro 109 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
108 // adapted to allow for a dynamically suffixed histogram name. 110 // adapted to allow for a dynamically suffixed histogram name.
109 // Note: The factory creates and owns the histogram. 111 // Note: The factory creates and owns the histogram.
110 base::HistogramBase* histogram = 112 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet(
111 base::LinearHistogram::FactoryGet( 113 user_prefs::tracked::kTrackedSplitPrefHistogramChanged + pref_path_, 1,
112 "Settings.TrackedSplitPreferenceChanged." + pref_path_, 114 100, // Allow counts up to 100.
113 1, 115 101, base::HistogramBase::kUmaTargetedHistogramFlag);
114 100, // Allow counts up to 100.
115 101,
116 base::HistogramBase::kUmaTargetedHistogramFlag);
117 histogram->Add(count); 116 histogram->Add(count);
118 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698