| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/user_prefs/tracked/tracked_preference_helper.h" | 5 #include "services/preferences/tracked/tracked_preference_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" | 10 #include "services/preferences/public/cpp/tracked/tracked_preference_histogram_n
ames.h" |
| 11 |
| 12 using ValueState = |
| 13 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState; |
| 11 | 14 |
| 12 TrackedPreferenceHelper::TrackedPreferenceHelper( | 15 TrackedPreferenceHelper::TrackedPreferenceHelper( |
| 13 const std::string& pref_path, | 16 const std::string& pref_path, |
| 14 size_t reporting_id, | 17 size_t reporting_id, |
| 15 size_t reporting_ids_count, | 18 size_t reporting_ids_count, |
| 16 PrefHashFilter::EnforcementLevel enforcement_level, | 19 prefs::mojom::TrackedPreferenceMetadata::EnforcementLevel enforcement_level, |
| 17 PrefHashFilter::ValueType value_type) | 20 prefs::mojom::TrackedPreferenceMetadata::ValueType value_type) |
| 18 : pref_path_(pref_path), | 21 : pref_path_(pref_path), |
| 19 reporting_id_(reporting_id), | 22 reporting_id_(reporting_id), |
| 20 reporting_ids_count_(reporting_ids_count), | 23 reporting_ids_count_(reporting_ids_count), |
| 21 enforce_(enforcement_level == | 24 enforce_(enforcement_level == prefs::mojom::TrackedPreferenceMetadata:: |
| 22 PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD), | 25 EnforcementLevel::ENFORCE_ON_LOAD), |
| 23 personal_(value_type == PrefHashFilter::ValueType::PERSONAL) {} | 26 personal_(value_type == |
| 27 prefs::mojom::TrackedPreferenceMetadata::ValueType::PERSONAL) {} |
| 24 | 28 |
| 25 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction( | 29 TrackedPreferenceHelper::ResetAction TrackedPreferenceHelper::GetAction( |
| 26 PrefHashStoreTransaction::ValueState value_state) const { | 30 ValueState value_state) const { |
| 27 switch (value_state) { | 31 switch (value_state) { |
| 28 case PrefHashStoreTransaction::UNCHANGED: | 32 case ValueState::UNCHANGED: |
| 29 // Desired case, nothing to do. | 33 // Desired case, nothing to do. |
| 30 return DONT_RESET; | 34 return DONT_RESET; |
| 31 case PrefHashStoreTransaction::CLEARED: | 35 case ValueState::CLEARED: |
| 32 // Unfortunate case, but there is nothing we can do. | 36 // Unfortunate case, but there is nothing we can do. |
| 33 return DONT_RESET; | 37 return DONT_RESET; |
| 34 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: // Falls through. | 38 case ValueState::TRUSTED_NULL_VALUE: // Falls through. |
| 35 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: | 39 case ValueState::TRUSTED_UNKNOWN_VALUE: |
| 36 // It is okay to seed the hash in this case. | 40 // It is okay to seed the hash in this case. |
| 37 return DONT_RESET; | 41 return DONT_RESET; |
| 38 case PrefHashStoreTransaction::SECURE_LEGACY: | 42 case ValueState::SECURE_LEGACY: |
| 39 // Accept secure legacy device ID based hashes. | 43 // Accept secure legacy device ID based hashes. |
| 40 return DONT_RESET; | 44 return DONT_RESET; |
| 41 case PrefHashStoreTransaction::UNSUPPORTED: | 45 case ValueState::UNSUPPORTED: |
| 42 NOTREACHED() | 46 NOTREACHED() |
| 43 << "GetAction should not be called with an UNSUPPORTED value state"; | 47 << "GetAction should not be called with an UNSUPPORTED value state"; |
| 44 return DONT_RESET; | 48 return DONT_RESET; |
| 45 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: // Falls through. | 49 case ValueState::UNTRUSTED_UNKNOWN_VALUE: // Falls through. |
| 46 case PrefHashStoreTransaction::CHANGED: | 50 case ValueState::CHANGED: |
| 47 return enforce_ ? DO_RESET : WANTED_RESET; | 51 return enforce_ ? DO_RESET : WANTED_RESET; |
| 48 } | 52 } |
| 49 NOTREACHED() << "Unexpected PrefHashStoreTransaction::ValueState: " | 53 NOTREACHED() << "Unexpected ValueState: " << value_state; |
| 50 << value_state; | |
| 51 return DONT_RESET; | 54 return DONT_RESET; |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool TrackedPreferenceHelper::IsPersonal() const { | 57 bool TrackedPreferenceHelper::IsPersonal() const { |
| 55 return personal_; | 58 return personal_; |
| 56 } | 59 } |
| 57 | 60 |
| 58 void TrackedPreferenceHelper::ReportValidationResult( | 61 void TrackedPreferenceHelper::ReportValidationResult( |
| 59 PrefHashStoreTransaction::ValueState value_state, | 62 ValueState value_state, |
| 60 base::StringPiece validation_type_suffix) const { | 63 base::StringPiece validation_type_suffix) const { |
| 61 const char* histogram_name = nullptr; | 64 const char* histogram_name = nullptr; |
| 62 switch (value_state) { | 65 switch (value_state) { |
| 63 case PrefHashStoreTransaction::UNCHANGED: | 66 case ValueState::UNCHANGED: |
| 64 histogram_name = user_prefs::tracked::kTrackedPrefHistogramUnchanged; | 67 histogram_name = user_prefs::tracked::kTrackedPrefHistogramUnchanged; |
| 65 break; | 68 break; |
| 66 case PrefHashStoreTransaction::CLEARED: | 69 case ValueState::CLEARED: |
| 67 histogram_name = user_prefs::tracked::kTrackedPrefHistogramCleared; | 70 histogram_name = user_prefs::tracked::kTrackedPrefHistogramCleared; |
| 68 break; | 71 break; |
| 69 case PrefHashStoreTransaction::SECURE_LEGACY: | 72 case ValueState::SECURE_LEGACY: |
| 70 histogram_name = | 73 histogram_name = |
| 71 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId; | 74 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId; |
| 72 break; | 75 break; |
| 73 case PrefHashStoreTransaction::CHANGED: | 76 case ValueState::CHANGED: |
| 74 histogram_name = user_prefs::tracked::kTrackedPrefHistogramChanged; | 77 histogram_name = user_prefs::tracked::kTrackedPrefHistogramChanged; |
| 75 break; | 78 break; |
| 76 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: | 79 case ValueState::UNTRUSTED_UNKNOWN_VALUE: |
| 77 histogram_name = user_prefs::tracked::kTrackedPrefHistogramInitialized; | 80 histogram_name = user_prefs::tracked::kTrackedPrefHistogramInitialized; |
| 78 break; | 81 break; |
| 79 case PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE: | 82 case ValueState::TRUSTED_UNKNOWN_VALUE: |
| 80 histogram_name = | 83 histogram_name = |
| 81 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized; | 84 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized; |
| 82 break; | 85 break; |
| 83 case PrefHashStoreTransaction::TRUSTED_NULL_VALUE: | 86 case ValueState::TRUSTED_NULL_VALUE: |
| 84 histogram_name = | 87 histogram_name = |
| 85 user_prefs::tracked::kTrackedPrefHistogramNullInitialized; | 88 user_prefs::tracked::kTrackedPrefHistogramNullInitialized; |
| 86 break; | 89 break; |
| 87 case PrefHashStoreTransaction::UNSUPPORTED: | 90 case ValueState::UNSUPPORTED: |
| 88 NOTREACHED() << "ReportValidationResult should not be called with an " | 91 NOTREACHED() << "ReportValidationResult should not be called with an " |
| 89 "UNSUPPORTED value state"; | 92 "UNSUPPORTED value state"; |
| 90 return; | 93 return; |
| 91 } | 94 } |
| 92 DCHECK(histogram_name); | 95 DCHECK(histogram_name); |
| 93 | 96 |
| 94 std::string full_histogram_name(histogram_name); | 97 std::string full_histogram_name(histogram_name); |
| 95 if (!validation_type_suffix.empty()) { | 98 if (!validation_type_suffix.empty()) { |
| 96 full_histogram_name.push_back('.'); | 99 full_histogram_name.push_back('.'); |
| 97 validation_type_suffix.AppendToString(&full_histogram_name); | 100 validation_type_suffix.AppendToString(&full_histogram_name); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 126 size_t count) const { | 129 size_t count) const { |
| 127 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro | 130 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_100 macro |
| 128 // adapted to allow for a dynamically suffixed histogram name. | 131 // adapted to allow for a dynamically suffixed histogram name. |
| 129 // Note: The factory creates and owns the histogram. | 132 // Note: The factory creates and owns the histogram. |
| 130 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | 133 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( |
| 131 user_prefs::tracked::kTrackedSplitPrefHistogramChanged + pref_path_, 1, | 134 user_prefs::tracked::kTrackedSplitPrefHistogramChanged + pref_path_, 1, |
| 132 100, // Allow counts up to 100. | 135 100, // Allow counts up to 100. |
| 133 101, base::HistogramBase::kUmaTargetedHistogramFlag); | 136 101, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 134 histogram->Add(count); | 137 histogram->Add(count); |
| 135 } | 138 } |
| OLD | NEW |