OLD | NEW |
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 "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" | 10 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 case PrefHashStoreTransaction::CLEARED: | 31 case PrefHashStoreTransaction::CLEARED: |
32 // Unfortunate case, but there is nothing we can do. | 32 // Unfortunate case, but there is nothing we can do. |
33 return DONT_RESET; | 33 return DONT_RESET; |
34 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: // Falls through. | 34 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: // Falls through. |
35 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: | 35 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: |
36 // It is okay to seed the hash in this case. | 36 // It is okay to seed the hash in this case. |
37 return DONT_RESET; | 37 return DONT_RESET; |
38 case PrefHashStoreTransaction::SECURE_LEGACY: | 38 case PrefHashStoreTransaction::SECURE_LEGACY: |
39 // Accept secure legacy device ID based hashes. | 39 // Accept secure legacy device ID based hashes. |
40 return DONT_RESET; | 40 return DONT_RESET; |
| 41 case PrefHashStoreTransaction::UNSUPPORTED: |
| 42 NOTREACHED() |
| 43 << "GetAction should not be called with an UNSUPPORTED value state"; |
| 44 return DONT_RESET; |
41 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through. | 45 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through. |
42 case PrefHashStoreTransaction::CHANGED: | 46 case PrefHashStoreTransaction::CHANGED: |
43 return enforce_ ? DO_RESET : WANTED_RESET; | 47 return enforce_ ? DO_RESET : WANTED_RESET; |
44 } | 48 } |
45 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " | 49 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " |
46 << value_state; | 50 << value_state; |
47 return DONT_RESET; | 51 return DONT_RESET; |
48 } | 52 } |
49 | 53 |
50 bool TrackedPreferenceHelper::IsPersonal() const { | 54 bool TrackedPreferenceHelper::IsPersonal() const { |
51 return personal_; | 55 return personal_; |
52 } | 56 } |
53 | 57 |
54 void TrackedPreferenceHelper::ReportValidationResult( | 58 void TrackedPreferenceHelper::ReportValidationResult( |
55 PrefHashStoreTransaction::ValueState value_state, | 59 PrefHashStoreTransaction::ValueState value_state, |
56 base::StringPiece validation_type_suffix) const { | 60 base::StringPiece validation_type_suffix) const { |
57 const char* histogram_name; | 61 const char* histogram_name = nullptr; |
58 switch (value_state) { | 62 switch (value_state) { |
59 case PrefHashStoreTransaction::UNCHANGED: | 63 case PrefHashStoreTransaction::UNCHANGED: |
60 histogram_name = user_prefs::tracked::kTrackedPrefHistogramUnchanged; | 64 histogram_name = user_prefs::tracked::kTrackedPrefHistogramUnchanged; |
61 break; | 65 break; |
62 case PrefHashStoreTransaction::CLEARED: | 66 case PrefHashStoreTransaction::CLEARED: |
63 histogram_name = user_prefs::tracked::kTrackedPrefHistogramCleared; | 67 histogram_name = user_prefs::tracked::kTrackedPrefHistogramCleared; |
64 break; | 68 break; |
65 case PrefHashStoreTransaction::SECURE_LEGACY: | 69 case PrefHashStoreTransaction::SECURE_LEGACY: |
66 histogram_name = | 70 histogram_name = |
67 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId; | 71 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId; |
68 break; | 72 break; |
69 case PrefHashStoreTransaction::CHANGED: | 73 case PrefHashStoreTransaction::CHANGED: |
70 histogram_name = user_prefs::tracked::kTrackedPrefHistogramChanged; | 74 histogram_name = user_prefs::tracked::kTrackedPrefHistogramChanged; |
71 break; | 75 break; |
72 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: | 76 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: |
73 histogram_name = user_prefs::tracked::kTrackedPrefHistogramInitialized; | 77 histogram_name = user_prefs::tracked::kTrackedPrefHistogramInitialized; |
74 break; | 78 break; |
75 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: | 79 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: |
76 histogram_name = | 80 histogram_name = |
77 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized; | 81 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized; |
78 break; | 82 break; |
79 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: | 83 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: |
80 histogram_name = | 84 histogram_name = |
81 user_prefs::tracked::kTrackedPrefHistogramNullInitialized; | 85 user_prefs::tracked::kTrackedPrefHistogramNullInitialized; |
82 break; | 86 break; |
83 default: | 87 case PrefHashStoreTransaction::UNSUPPORTED: |
84 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " | 88 NOTREACHED() << "ReportValidationResult should not be called with an " |
85 << value_state; | 89 "UNSUPPORTED value state"; |
86 return; | 90 return; |
87 } | 91 } |
| 92 DCHECK(histogram_name); |
88 | 93 |
89 std::string full_histogram_name(histogram_name); | 94 std::string full_histogram_name(histogram_name); |
90 if (!validation_type_suffix.empty()) { | 95 if (!validation_type_suffix.empty()) { |
91 full_histogram_name.push_back('.'); | 96 full_histogram_name.push_back('.'); |
92 validation_type_suffix.AppendToString(&full_histogram_name); | 97 validation_type_suffix.AppendToString(&full_histogram_name); |
93 } | 98 } |
94 | 99 |
95 // Using FactoryGet to allow dynamic histogram names. This is equivalent to | 100 // Using FactoryGet to allow dynamic histogram names. This is equivalent to |
96 // UMA_HISTOGRAM_ENUMERATION(name, reporting_id_, reporting_ids_count_); | 101 // UMA_HISTOGRAM_ENUMERATION(name, reporting_id_, reporting_ids_count_); |
97 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 102 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
(...skipping 23 matching lines...) Expand all Loading... |
121 size_t count) const { | 126 size_t count) const { |
122 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro | 127 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro |
123 // adapted to allow for a dynamically suffixed histogram name. | 128 // adapted to allow for a dynamically suffixed histogram name. |
124 // Note: The factory creates and owns the histogram. | 129 // Note: The factory creates and owns the histogram. |
125 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 130 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
126 user_prefs::tracked::kTrackedSplitPrefHistogramChanged + pref_path_, 1, | 131 user_prefs::tracked::kTrackedSplitPrefHistogramChanged + pref_path_, 1, |
127 100, // Allow counts up to 100. | 132 100, // Allow counts up to 100. |
128 101, base::HistogramBase::kUmaTargetedHistogramFlag); | 133 101, base::HistogramBase::kUmaTargetedHistogramFlag); |
129 histogram->Add(count); | 134 histogram->Add(count); |
130 } | 135 } |
OLD | NEW |