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_split_preference.h" | 5 #include "components/user_prefs/tracked/tracked_split_preference.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | 11 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
12 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" | 12 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" |
13 | 13 |
14 TrackedSplitPreference::TrackedSplitPreference( | 14 TrackedSplitPreference::TrackedSplitPreference( |
15 const std::string& pref_path, | 15 const std::string& pref_path, |
16 size_t reporting_id, | 16 size_t reporting_id, |
17 size_t reporting_ids_count, | 17 size_t reporting_ids_count, |
18 PrefHashFilter::EnforcementLevel enforcement_level, | 18 PrefHashFilter::EnforcementLevel enforcement_level, |
19 PrefHashFilter::ValueType value_type, | 19 PrefHashFilter::ValueType value_type, |
20 TrackedPreferenceValidationDelegate* delegate) | 20 TrackedPreferenceValidationDelegate* delegate) |
21 : pref_path_(pref_path), | 21 : pref_path_(pref_path), |
22 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level, | 22 helper_(pref_path, |
| 23 reporting_id, |
| 24 reporting_ids_count, |
| 25 enforcement_level, |
23 value_type), | 26 value_type), |
24 delegate_(delegate) { | 27 delegate_(delegate) { |
25 } | 28 } |
26 | 29 |
27 void TrackedSplitPreference::OnNewValue( | 30 void TrackedSplitPreference::OnNewValue( |
28 const base::Value* value, | 31 const base::Value* value, |
29 PrefHashStoreTransaction* transaction) const { | 32 PrefHashStoreTransaction* transaction) const { |
30 const base::DictionaryValue* dict_value = NULL; | 33 const base::DictionaryValue* dict_value = NULL; |
31 if (value && !value->GetAsDictionary(&dict_value)) { | 34 if (value && !value->GetAsDictionary(&dict_value)) { |
32 NOTREACHED(); | 35 NOTREACHED(); |
(...skipping 28 matching lines...) Expand all Loading... |
61 delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys, | 64 delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys, |
62 value_state, helper_.IsPersonal()); | 65 value_state, helper_.IsPersonal()); |
63 } | 66 } |
64 helper_.ReportAction(reset_action); | 67 helper_.ReportAction(reset_action); |
65 | 68 |
66 bool was_reset = false; | 69 bool was_reset = false; |
67 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 70 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
68 if (value_state == PrefHashStoreTransaction::CHANGED) { | 71 if (value_state == PrefHashStoreTransaction::CHANGED) { |
69 DCHECK(!invalid_keys.empty()); | 72 DCHECK(!invalid_keys.empty()); |
70 | 73 |
71 for (std::vector<std::string>::const_iterator it = | 74 for (std::vector<std::string>::const_iterator it = invalid_keys.begin(); |
72 invalid_keys.begin(); it != invalid_keys.end(); ++it) { | 75 it != invalid_keys.end(); ++it) { |
73 dict_value->Remove(*it, NULL); | 76 dict_value->Remove(*it, NULL); |
74 } | 77 } |
75 } else { | 78 } else { |
76 pref_store_contents->RemovePath(pref_path_, NULL); | 79 pref_store_contents->RemovePath(pref_path_, NULL); |
77 } | 80 } |
78 was_reset = true; | 81 was_reset = true; |
79 } | 82 } |
80 | 83 |
81 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | 84 if (value_state != PrefHashStoreTransaction::UNCHANGED) { |
82 // Store the hash for the new value (whether it was reset or not). | 85 // Store the hash for the new value (whether it was reset or not). |
83 const base::DictionaryValue* new_dict_value = NULL; | 86 const base::DictionaryValue* new_dict_value = NULL; |
84 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | 87 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); |
85 transaction->StoreSplitHash(pref_path_, new_dict_value); | 88 transaction->StoreSplitHash(pref_path_, new_dict_value); |
86 } | 89 } |
87 | 90 |
88 return was_reset; | 91 return was_reset; |
89 } | 92 } |
OLD | NEW |