Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / prefs / tracked / tracked_preference_helper.cc
blob0cede17c590677ad6a8ccd4b061a0223a515544d
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,
12 size_t reporting_id,
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.
25 return DONT_RESET;
26 case PrefHashStoreTransaction::CLEARED:
27 // Unfortunate case, but there is nothing we can do.
28 return DONT_RESET;
29 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE:
30 // It is okay to seed the hash in this case.
31 return DONT_RESET;
32 case PrefHashStoreTransaction::SECURE_LEGACY:
33 // Accept secure legacy device ID based hashes.
34 return DONT_RESET;
35 case PrefHashStoreTransaction::WEAK_LEGACY: // Falls through.
36 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through.
37 case PrefHashStoreTransaction::CHANGED:
38 return enforce_ ? DO_RESET : WANTED_RESET;
40 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
41 << value_state;
42 return DONT_RESET;
45 void TrackedPreferenceHelper::ReportValidationResult(
46 PrefHashStoreTransaction::ValueState value_state) const {
47 switch (value_state) {
48 case PrefHashStoreTransaction::UNCHANGED:
49 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged",
50 reporting_id_, reporting_ids_count_);
51 return;
52 case PrefHashStoreTransaction::CLEARED:
53 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
54 reporting_id_, reporting_ids_count_);
55 return;
56 case PrefHashStoreTransaction::WEAK_LEGACY:
57 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceMigrated",
58 reporting_id_, reporting_ids_count_);
59 return;
60 case PrefHashStoreTransaction::SECURE_LEGACY:
61 UMA_HISTOGRAM_ENUMERATION(
62 "Settings.TrackedPreferenceMigratedLegacyDeviceId", reporting_id_,
63 reporting_ids_count_);
64 return;
65 case PrefHashStoreTransaction::CHANGED:
66 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged",
67 reporting_id_, reporting_ids_count_);
68 return;
69 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE:
70 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
71 reporting_id_, reporting_ids_count_);
72 return;
73 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE:
74 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
75 reporting_id_, reporting_ids_count_);
76 return;
78 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
79 << value_state;
82 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const {
83 switch (reset_action) {
84 case DONT_RESET:
85 // No report for DONT_RESET.
86 break;
87 case WANTED_RESET:
88 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
89 reporting_id_, reporting_ids_count_);
90 break;
91 case DO_RESET:
92 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
93 reporting_id_, reporting_ids_count_);
94 break;
98 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount(
99 size_t count) const {
100 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro
101 // adapted to allow for a dynamically suffixed histogram name.
102 // Note: The factory creates and owns the histogram.
103 base::HistogramBase* histogram =
104 base::LinearHistogram::FactoryGet(
105 "Settings.TrackedSplitPreferenceChanged." + pref_path_,
107 100, // Allow counts up to 100.
108 101,
109 base::HistogramBase::kUmaTargetedHistogramFlag);
110 histogram->Add(count);