OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 |
| 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 allow_changes_(enforcement_level < PrefHashFilter::ENFORCE), |
| 18 allow_seeding_(enforcement_level < PrefHashFilter::ENFORCE_NO_SEEDING), |
| 19 allow_migration_(enforcement_level < |
| 20 PrefHashFilter::ENFORCE_NO_SEEDING_NO_MIGRATION) { |
| 21 } |
| 22 |
| 23 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction( |
| 24 PrefHashStore::ValueState value_state) const { |
| 25 switch (value_state) { |
| 26 case PrefHashStore::UNCHANGED: |
| 27 // Desired case, nothing to do. |
| 28 return DONT_RESET; |
| 29 case PrefHashStore::CLEARED: |
| 30 // Unfortunate case, but there is nothing we can do. |
| 31 return DONT_RESET; |
| 32 case PrefHashStore::TRUSTED_UNKNOWN_VALUE: |
| 33 // It is okay to seed the hash in this case. |
| 34 return DONT_RESET; |
| 35 case PrefHashStore::MIGRATED: |
| 36 return allow_migration_ ? WANTED_RESET : DO_RESET; |
| 37 case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE: |
| 38 return allow_seeding_ ? WANTED_RESET : DO_RESET; |
| 39 case PrefHashStore::CHANGED: |
| 40 return allow_changes_ ? WANTED_RESET : DO_RESET; |
| 41 } |
| 42 NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state; |
| 43 return DONT_RESET; |
| 44 } |
| 45 |
| 46 void TrackedPreferenceHelper::ReportValidationResult( |
| 47 PrefHashStore::ValueState value_state) const { |
| 48 switch (value_state) { |
| 49 case PrefHashStore::UNCHANGED: |
| 50 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceUnchanged", |
| 51 reporting_id_, reporting_ids_count_); |
| 52 return; |
| 53 case PrefHashStore::CLEARED: |
| 54 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceCleared", |
| 55 reporting_id_, reporting_ids_count_); |
| 56 return; |
| 57 case PrefHashStore::MIGRATED: |
| 58 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceMigrated", |
| 59 reporting_id_, reporting_ids_count_); |
| 60 return; |
| 61 case PrefHashStore::CHANGED: |
| 62 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceChanged", |
| 63 reporting_id_, reporting_ids_count_); |
| 64 return; |
| 65 case PrefHashStore::UNTRUSTED_UNKNOWN_VALUE: |
| 66 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceInitialized", |
| 67 reporting_id_, reporting_ids_count_); |
| 68 return; |
| 69 case PrefHashStore::TRUSTED_UNKNOWN_VALUE: |
| 70 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceTrustedInitialized", |
| 71 reporting_id_, reporting_ids_count_); |
| 72 return; |
| 73 } |
| 74 NOTREACHED() << "Unexpected PrefHashStore::ValueState: " << value_state; |
| 75 } |
| 76 |
| 77 void TrackedPreferenceHelper::ReportAction(ResetAction reset_action) const { |
| 78 switch (reset_action) { |
| 79 case DONT_RESET: |
| 80 // No report for DONT_RESET. |
| 81 break; |
| 82 case WANTED_RESET: |
| 83 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceWantedReset", |
| 84 reporting_id_, reporting_ids_count_); |
| 85 break; |
| 86 case DO_RESET: |
| 87 UMA_HISTOGRAM_ENUMERATION("Settings.TrackedPreferenceReset", |
| 88 reporting_id_, reporting_ids_count_); |
| 89 break; |
| 90 } |
| 91 } |
| 92 |
| 93 void TrackedPreferenceHelper::ReportSplitPreferenceChangedCount( |
| 94 size_t count) const { |
| 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_, |
| 101 1, |
| 102 100, // Allow counts up to 100. |
| 103 101, |
| 104 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 105 histogram->Add(count); |
| 106 } |
OLD | NEW |