Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / prefs / tracked / tracked_preference_helper.cc
blobb3b528e56063e67d8614d26605903263afc3d842
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 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.
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.
33 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE:
34 // It is okay to seed the hash in this case.
35 return DONT_RESET;
36 case PrefHashStoreTransaction::SECURE_LEGACY:
37 // Accept secure legacy device ID based hashes.
38 return DONT_RESET;
39 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through.
40 case PrefHashStoreTransaction::CHANGED:
41 return enforce_ ? DO_RESET : WANTED_RESET;
43 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
44 << value_state;
45 return DONT_RESET;
48 bool TrackedPreferenceHelper::IsPersonal() const {
49 return personal_;
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_);
58 return;
59 case PrefHashStoreTransaction::CLEARED:
60 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared",
61 reporting_id_, reporting_ids_count_);
62 return;
63 case PrefHashStoreTransaction::SECURE_LEGACY:
64 UMA_HISTOGRAM_ENUMERATION(
65 "Settings.TrackedPreferenceMigratedLegacyDeviceId", reporting_id_,
66 reporting_ids_count_);
67 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:
73 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized",
74 reporting_id_, reporting_ids_count_);
75 return;
76 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE:
77 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized",
78 reporting_id_, reporting_ids_count_);
79 return;
80 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE:
81 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceNullInitialized",
82 reporting_id_, reporting_ids_count_);
83 return;
85 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: "
86 << value_state;
89 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const {
90 switch (reset_action) {
91 case DONT_RESET:
92 // No report for DONT_RESET.
93 break;
94 case WANTED_RESET:
95 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset",
96 reporting_id_, reporting_ids_count_);
97 break;
98 case DO_RESET:
99 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset",
100 reporting_id_, reporting_ids_count_);
101 break;
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.
115 101,
116 base::HistogramBase::kUmaTargetedHistogramFlag);
117 histogram->Add(count);