OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/user_prefs/tracked/tracked_atomic_preference.h" | |
6 | |
7 #include "base/values.h" | |
8 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | |
9 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" | |
10 | |
11 TrackedAtomicPreference::TrackedAtomicPreference( | |
12 const std::string& pref_path, | |
13 size_t reporting_id, | |
14 size_t reporting_ids_count, | |
15 PrefHashFilter::EnforcementLevel enforcement_level, | |
16 PrefHashFilter::ValueType value_type, | |
17 prefs::mojom::TrackedPreferenceValidationDelegate* delegate) | |
18 : pref_path_(pref_path), | |
19 helper_(pref_path, | |
20 reporting_id, | |
21 reporting_ids_count, | |
22 enforcement_level, | |
23 value_type), | |
24 delegate_(delegate) {} | |
25 | |
26 TrackedPreferenceType TrackedAtomicPreference::GetType() const { | |
27 return TrackedPreferenceType::ATOMIC; | |
28 } | |
29 | |
30 void TrackedAtomicPreference::OnNewValue( | |
31 const base::Value* value, | |
32 PrefHashStoreTransaction* transaction) const { | |
33 transaction->StoreHash(pref_path_, value); | |
34 } | |
35 | |
36 bool TrackedAtomicPreference::EnforceAndReport( | |
37 base::DictionaryValue* pref_store_contents, | |
38 PrefHashStoreTransaction* transaction, | |
39 PrefHashStoreTransaction* external_validation_transaction) const { | |
40 const base::Value* value = NULL; | |
41 pref_store_contents->Get(pref_path_, &value); | |
42 PrefHashStoreTransaction::ValueState value_state = | |
43 transaction->CheckValue(pref_path_, value); | |
44 helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix()); | |
45 | |
46 PrefHashStoreTransaction::ValueState external_validation_value_state = | |
47 PrefHashStoreTransaction::UNSUPPORTED; | |
48 if (external_validation_transaction) { | |
49 external_validation_value_state = | |
50 external_validation_transaction->CheckValue(pref_path_, value); | |
51 helper_.ReportValidationResult( | |
52 external_validation_value_state, | |
53 external_validation_transaction->GetStoreUMASuffix()); | |
54 } | |
55 | |
56 if (delegate_) { | |
57 delegate_->OnAtomicPreferenceValidation( | |
58 pref_path_, value ? value->CreateDeepCopy() : nullptr, value_state, | |
59 external_validation_value_state, helper_.IsPersonal()); | |
60 } | |
61 TrackedPreferenceHelper::ResetAction reset_action = | |
62 helper_.GetAction(value_state); | |
63 helper_.ReportAction(reset_action); | |
64 | |
65 bool was_reset = false; | |
66 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | |
67 pref_store_contents->RemovePath(pref_path_, NULL); | |
68 was_reset = true; | |
69 } | |
70 | |
71 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | |
72 // Store the hash for the new value (whether it was reset or not). | |
73 const base::Value* new_value = NULL; | |
74 pref_store_contents->Get(pref_path_, &new_value); | |
75 transaction->StoreHash(pref_path_, new_value); | |
76 } | |
77 | |
78 // Update MACs in the external store if there is one and there either was a | |
79 // reset or external validation failed. | |
80 if (external_validation_transaction && | |
81 (was_reset || | |
82 external_validation_value_state != | |
83 PrefHashStoreTransaction::UNCHANGED)) { | |
84 const base::Value* new_value = nullptr; | |
85 pref_store_contents->Get(pref_path_, &new_value); | |
86 external_validation_transaction->StoreHash(pref_path_, new_value); | |
87 } | |
88 | |
89 return was_reset; | |
90 } | |
OLD | NEW |