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 "chrome/browser/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 : pref_path_(pref_path
),
16 reporting_id_(reporting_id
), reporting_ids_count_(reporting_ids_count
),
17 enforce_(enforcement_level
== PrefHashFilter::ENFORCE_ON_LOAD
) {
20 TrackedPreferenceHelper::ResetAction
TrackedPreferenceHelper::GetAction(
21 PrefHashStoreTransaction::ValueState value_state
) const {
22 switch (value_state
) {
23 case PrefHashStoreTransaction::UNCHANGED
:
24 // Desired case, nothing to do.
26 case PrefHashStoreTransaction::CLEARED
:
27 // Unfortunate case, but there is nothing we can do.
29 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE
:
30 // It is okay to seed the hash in this case.
32 case PrefHashStoreTransaction::SECURE_LEGACY
:
33 // Accept secure legacy device ID based hashes.
35 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE
: // Falls through.
36 case PrefHashStoreTransaction::CHANGED
:
37 return enforce_
? DO_RESET
: WANTED_RESET
;
39 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
44 void TrackedPreferenceHelper::ReportValidationResult(
45 PrefHashStoreTransaction::ValueState value_state
) const {
46 switch (value_state
) {
47 case PrefHashStoreTransaction::UNCHANGED
:
48 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
49 reporting_id_
, reporting_ids_count_
);
51 case PrefHashStoreTransaction::CLEARED
:
52 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
53 reporting_id_
, reporting_ids_count_
);
55 case PrefHashStoreTransaction::SECURE_LEGACY
:
56 UMA_HISTOGRAM_ENUMERATION(
57 "Settings.TrackedPreferenceMigratedLegacyDeviceId", reporting_id_
,
58 reporting_ids_count_
);
60 case PrefHashStoreTransaction::CHANGED
:
61 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
62 reporting_id_
, reporting_ids_count_
);
64 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE
:
65 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
66 reporting_id_
, reporting_ids_count_
);
68 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE
:
69 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
70 reporting_id_
, reporting_ids_count_
);
73 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
77 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action
) const {
78 switch (reset_action
) {
80 // No report for DONT_RESET.
83 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
84 reporting_id_
, reporting_ids_count_
);
87 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
88 reporting_id_
, reporting_ids_count_
);
93 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount(
95 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
96 // adapted to allow for a dynamically suffixed histogram name.
97 // Note: The factory creates and owns the histogram.
98 base::HistogramBase
* histogram
=
99 base::LinearHistogram::FactoryGet(
100 "Settings.TrackedSplitPreferenceChanged." + pref_path_
,
102 100, // Allow counts up to 100.
104 base::HistogramBase::kUmaTargetedHistogramFlag
);
105 histogram
->Add(count
);