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_atomic_preference.h" | 5 #include "components/user_prefs/tracked/tracked_atomic_preference.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 8 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
9 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" | 9 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" |
10 | 10 |
11 TrackedAtomicPreference::TrackedAtomicPreference( | 11 TrackedAtomicPreference::TrackedAtomicPreference( |
12 const std::string& pref_path, | 12 const std::string& pref_path, |
13 size_t reporting_id, | 13 size_t reporting_id, |
14 size_t reporting_ids_count, | 14 size_t reporting_ids_count, |
15 PrefHashFilter::EnforcementLevel enforcement_level, | 15 PrefHashFilter::EnforcementLevel enforcement_level, |
16 PrefHashFilter::ValueType value_type, | 16 PrefHashFilter::ValueType value_type, |
17 TrackedPreferenceValidationDelegate* delegate) | 17 prefs::mojom::TrackedPreferenceValidationDelegate* delegate) |
18 : pref_path_(pref_path), | 18 : pref_path_(pref_path), |
19 helper_(pref_path, | 19 helper_(pref_path, |
20 reporting_id, | 20 reporting_id, |
21 reporting_ids_count, | 21 reporting_ids_count, |
22 enforcement_level, | 22 enforcement_level, |
23 value_type), | 23 value_type), |
24 delegate_(delegate) { | 24 delegate_(delegate) {} |
25 } | |
26 | 25 |
27 TrackedPreferenceType TrackedAtomicPreference::GetType() const { | 26 TrackedPreferenceType TrackedAtomicPreference::GetType() const { |
28 return TrackedPreferenceType::ATOMIC; | 27 return TrackedPreferenceType::ATOMIC; |
29 } | 28 } |
30 | 29 |
31 void TrackedAtomicPreference::OnNewValue( | 30 void TrackedAtomicPreference::OnNewValue( |
32 const base::Value* value, | 31 const base::Value* value, |
33 PrefHashStoreTransaction* transaction) const { | 32 PrefHashStoreTransaction* transaction) const { |
34 transaction->StoreHash(pref_path_, value); | 33 transaction->StoreHash(pref_path_, value); |
35 } | 34 } |
(...skipping 12 matching lines...) Expand all Loading... |
48 PrefHashStoreTransaction::UNSUPPORTED; | 47 PrefHashStoreTransaction::UNSUPPORTED; |
49 if (external_validation_transaction) { | 48 if (external_validation_transaction) { |
50 external_validation_value_state = | 49 external_validation_value_state = |
51 external_validation_transaction->CheckValue(pref_path_, value); | 50 external_validation_transaction->CheckValue(pref_path_, value); |
52 helper_.ReportValidationResult( | 51 helper_.ReportValidationResult( |
53 external_validation_value_state, | 52 external_validation_value_state, |
54 external_validation_transaction->GetStoreUMASuffix()); | 53 external_validation_transaction->GetStoreUMASuffix()); |
55 } | 54 } |
56 | 55 |
57 if (delegate_) { | 56 if (delegate_) { |
58 delegate_->OnAtomicPreferenceValidation(pref_path_, value, value_state, | 57 delegate_->OnAtomicPreferenceValidation( |
59 external_validation_value_state, | 58 pref_path_, value ? value->CreateDeepCopy() : nullptr, value_state, |
60 helper_.IsPersonal()); | 59 external_validation_value_state, helper_.IsPersonal()); |
61 } | 60 } |
62 TrackedPreferenceHelper::ResetAction reset_action = | 61 TrackedPreferenceHelper::ResetAction reset_action = |
63 helper_.GetAction(value_state); | 62 helper_.GetAction(value_state); |
64 helper_.ReportAction(reset_action); | 63 helper_.ReportAction(reset_action); |
65 | 64 |
66 bool was_reset = false; | 65 bool was_reset = false; |
67 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 66 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
68 pref_store_contents->RemovePath(pref_path_, NULL); | 67 pref_store_contents->RemovePath(pref_path_, NULL); |
69 was_reset = true; | 68 was_reset = true; |
70 } | 69 } |
(...skipping 11 matching lines...) Expand all Loading... |
82 (was_reset || | 81 (was_reset || |
83 external_validation_value_state != | 82 external_validation_value_state != |
84 PrefHashStoreTransaction::UNCHANGED)) { | 83 PrefHashStoreTransaction::UNCHANGED)) { |
85 const base::Value* new_value = nullptr; | 84 const base::Value* new_value = nullptr; |
86 pref_store_contents->Get(pref_path_, &new_value); | 85 pref_store_contents->Get(pref_path_, &new_value); |
87 external_validation_transaction->StoreHash(pref_path_, new_value); | 86 external_validation_transaction->StoreHash(pref_path_, new_value); |
88 } | 87 } |
89 | 88 |
90 return was_reset; | 89 return was_reset; |
91 } | 90 } |
OLD | NEW |