| 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 "chrome/browser/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 "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | 8 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
| 9 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" | 9 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.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 TrackedPreferenceValidationDelegate* delegate) |
| 18 : pref_path_(pref_path), | 18 : pref_path_(pref_path), |
| 19 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level, | 19 helper_(pref_path, |
| 20 reporting_id, |
| 21 reporting_ids_count, |
| 22 enforcement_level, |
| 20 value_type), | 23 value_type), |
| 21 delegate_(delegate) { | 24 delegate_(delegate) { |
| 22 } | 25 } |
| 23 | 26 |
| 24 void TrackedAtomicPreference::OnNewValue( | 27 void TrackedAtomicPreference::OnNewValue( |
| 25 const base::Value* value, | 28 const base::Value* value, |
| 26 PrefHashStoreTransaction* transaction) const { | 29 PrefHashStoreTransaction* transaction) const { |
| 27 transaction->StoreHash(pref_path_, value); | 30 transaction->StoreHash(pref_path_, value); |
| 28 } | 31 } |
| 29 | 32 |
| 30 bool TrackedAtomicPreference::EnforceAndReport( | 33 bool TrackedAtomicPreference::EnforceAndReport( |
| 31 base::DictionaryValue* pref_store_contents, | 34 base::DictionaryValue* pref_store_contents, |
| 32 PrefHashStoreTransaction* transaction) const { | 35 PrefHashStoreTransaction* transaction) const { |
| 33 const base::Value* value = NULL; | 36 const base::Value* value = NULL; |
| 34 pref_store_contents->Get(pref_path_, &value); | 37 pref_store_contents->Get(pref_path_, &value); |
| 35 PrefHashStoreTransaction::ValueState value_state = | 38 PrefHashStoreTransaction::ValueState value_state = |
| 36 transaction->CheckValue(pref_path_, value); | 39 transaction->CheckValue(pref_path_, value); |
| 37 | 40 |
| 38 helper_.ReportValidationResult(value_state); | 41 helper_.ReportValidationResult(value_state); |
| 39 | 42 |
| 40 TrackedPreferenceHelper::ResetAction reset_action = | 43 TrackedPreferenceHelper::ResetAction reset_action = |
| 41 helper_.GetAction(value_state); | 44 helper_.GetAction(value_state); |
| 42 if (delegate_) { | 45 if (delegate_) { |
| 43 delegate_->OnAtomicPreferenceValidation( | 46 delegate_->OnAtomicPreferenceValidation(pref_path_, value, value_state, |
| 44 pref_path_, value, value_state, helper_.IsPersonal()); | 47 helper_.IsPersonal()); |
| 45 } | 48 } |
| 46 helper_.ReportAction(reset_action); | 49 helper_.ReportAction(reset_action); |
| 47 | 50 |
| 48 bool was_reset = false; | 51 bool was_reset = false; |
| 49 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 52 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
| 50 pref_store_contents->RemovePath(pref_path_, NULL); | 53 pref_store_contents->RemovePath(pref_path_, NULL); |
| 51 was_reset = true; | 54 was_reset = true; |
| 52 } | 55 } |
| 53 | 56 |
| 54 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | 57 if (value_state != PrefHashStoreTransaction::UNCHANGED) { |
| 55 // Store the hash for the new value (whether it was reset or not). | 58 // Store the hash for the new value (whether it was reset or not). |
| 56 const base::Value* new_value = NULL; | 59 const base::Value* new_value = NULL; |
| 57 pref_store_contents->Get(pref_path_, &new_value); | 60 pref_store_contents->Get(pref_path_, &new_value); |
| 58 transaction->StoreHash(pref_path_, new_value); | 61 transaction->StoreHash(pref_path_, new_value); |
| 59 } | 62 } |
| 60 | 63 |
| 61 return was_reset; | 64 return was_reset; |
| 62 } | 65 } |
| OLD | NEW |