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
3 // found in the LICENSE file.
5 #include "components/user_prefs/tracked/tracked_preference_helper.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
10 TrackedPreferenceHelper::TrackedPreferenceHelper(
11 const std::string
& pref_path
,
13 size_t reporting_ids_count
,
14 PrefHashFilter::EnforcementLevel enforcement_level
,
15 PrefHashFilter::ValueType value_type
)
16 : pref_path_(pref_path
),
17 reporting_id_(reporting_id
),
18 reporting_ids_count_(reporting_ids_count
),
19 enforce_(enforcement_level
== PrefHashFilter::ENFORCE_ON_LOAD
),
20 personal_(value_type
== PrefHashFilter::VALUE_PERSONAL
) {
23 TrackedPreferenceHelper::ResetAction
TrackedPreferenceHelper::GetAction(
24 PrefHashStoreTransaction::ValueState value_state
) const {
25 switch (value_state
) {
26 case PrefHashStoreTransaction::UNCHANGED
:
27 // Desired case, nothing to do.
29 case PrefHashStoreTransaction::CLEARED
:
30 // Unfortunate case, but there is nothing we can do.
32 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE
: // Falls through.
33 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE
:
34 // It is okay to seed the hash in this case.
36 case PrefHashStoreTransaction::SECURE_LEGACY
:
37 // Accept secure legacy device ID based hashes.
39 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE
: // Falls through.
40 case PrefHashStoreTransaction::CHANGED
:
41 return enforce_
? DO_RESET
: WANTED_RESET
;
43 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
48 bool TrackedPreferenceHelper::IsPersonal() const {
52 void TrackedPreferenceHelper::ReportValidationResult(
53 PrefHashStoreTransaction::ValueState value_state
) const {
54 switch (value_state
) {
55 case PrefHashStoreTransaction::UNCHANGED
:
56 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
57 reporting_id_
, reporting_ids_count_
);
59 case PrefHashStoreTransaction::CLEARED
:
60 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
61 reporting_id_
, reporting_ids_count_
);
63 case PrefHashStoreTransaction::SECURE_LEGACY
:
64 UMA_HISTOGRAM_ENUMERATION(
65 "Settings.TrackedPreferenceMigratedLegacyDeviceId", reporting_id_
,
66 reporting_ids_count_
);
68 case PrefHashStoreTransaction::CHANGED
:
69 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
70 reporting_id_
, reporting_ids_count_
);
72 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE
:
73 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
74 reporting_id_
, reporting_ids_count_
);
76 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE
:
77 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
78 reporting_id_
, reporting_ids_count_
);
80 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE
:
81 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceNullInitialized",
82 reporting_id_
, reporting_ids_count_
);
85 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
89 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action
) const {
90 switch (reset_action
) {
92 // No report for DONT_RESET.
95 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
96 reporting_id_
, reporting_ids_count_
);
99 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
100 reporting_id_
, reporting_ids_count_
);
105 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount(
106 size_t count
) const {
107 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
108 // adapted to allow for a dynamically suffixed histogram name.
109 // Note: The factory creates and owns the histogram.
110 base::HistogramBase
* histogram
=
111 base::LinearHistogram::FactoryGet(
112 "Settings.TrackedSplitPreferenceChanged." + pref_path_
,
114 100, // Allow counts up to 100.
116 base::HistogramBase::kUmaTargetedHistogramFlag
);
117 histogram
->Add(count
);