Chromium Code Reviews| 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 "chrome/browser/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" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 void TrackedSplitPreference::OnNewValue(const base::Value* value) const { | 24 void TrackedSplitPreference::OnNewValue(const base::Value* value) const { |
| 25 const base::DictionaryValue* dict_value = NULL; | 25 const base::DictionaryValue* dict_value = NULL; |
| 26 if (value && !value->GetAsDictionary(&dict_value)) { | 26 if (value && !value->GetAsDictionary(&dict_value)) { |
| 27 NOTREACHED(); | 27 NOTREACHED(); |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 pref_hash_store_->StoreSplitHash(pref_path_, dict_value); | 30 pref_hash_store_->StoreSplitHash(pref_path_, dict_value); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TrackedSplitPreference::EnforceAndReport( | 33 bool TrackedSplitPreference::EnforceAndReport( |
| 34 base::DictionaryValue* pref_store_contents) const { | 34 base::DictionaryValue* pref_store_contents) const { |
| 35 base::DictionaryValue* dict_value = NULL; | 35 base::DictionaryValue* dict_value = NULL; |
| 36 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && | 36 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && |
| 37 pref_store_contents->Get(pref_path_, NULL)) { | 37 pref_store_contents->Get(pref_path_, NULL)) { |
| 38 // There should be a dictionary or nothing at |pref_path_|. | 38 // There should be a dictionary or nothing at |pref_path_|. |
| 39 NOTREACHED(); | 39 NOTREACHED(); |
| 40 return; | 40 return false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 std::vector<std::string> invalid_keys; | 43 std::vector<std::string> invalid_keys; |
| 44 PrefHashStore::ValueState value_state = | 44 PrefHashStore::ValueState value_state = |
| 45 pref_hash_store_->CheckSplitValue(pref_path_, dict_value, &invalid_keys); | 45 pref_hash_store_->CheckSplitValue(pref_path_, dict_value, &invalid_keys); |
| 46 | 46 |
| 47 if (value_state == PrefHashStore::CHANGED) | 47 if (value_state == PrefHashStore::CHANGED) |
| 48 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); | 48 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); |
| 49 | 49 |
| 50 helper_.ReportValidationResult(value_state); | 50 helper_.ReportValidationResult(value_state); |
| 51 | 51 |
| 52 TrackedPreferenceHelper::ResetAction reset_action = | 52 TrackedPreferenceHelper::ResetAction reset_action = |
| 53 helper_.GetAction(value_state); | 53 helper_.GetAction(value_state); |
| 54 helper_.ReportAction(reset_action); | 54 helper_.ReportAction(reset_action); |
| 55 | 55 |
| 56 bool was_reset = false; | |
| 56 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 57 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
| 57 if (value_state == PrefHashStore::CHANGED) { | 58 if (value_state == PrefHashStore::CHANGED) { |
| 58 DCHECK(!invalid_keys.empty()); | 59 DCHECK(!invalid_keys.empty()); |
| 59 | 60 |
| 60 for (std::vector<std::string>::const_iterator it = | 61 for (std::vector<std::string>::const_iterator it = |
| 61 invalid_keys.begin(); it != invalid_keys.end(); ++it) { | 62 invalid_keys.begin(); it != invalid_keys.end(); ++it) { |
| 62 dict_value->Remove(*it, NULL); | 63 dict_value->Remove(*it, NULL); |
| 63 } | 64 } |
| 64 } else { | 65 } else { |
| 65 pref_store_contents->RemovePath(pref_path_, NULL); | 66 pref_store_contents->RemovePath(pref_path_, NULL); |
| 66 } | 67 } |
| 68 was_reset = true; | |
| 67 } | 69 } |
| 68 | 70 |
| 69 if (value_state != PrefHashStore::UNCHANGED) { | 71 if (value_state != PrefHashStore::UNCHANGED) { |
| 70 // Store the hash for the new value (whether it was reset or not). | 72 // Store the hash for the new value (whether it was reset or not). |
| 71 const base::DictionaryValue* new_dict_value = NULL; | 73 const base::DictionaryValue* new_dict_value = NULL; |
| 72 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | 74 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); |
| 73 pref_hash_store_->StoreSplitHash(pref_path_, new_dict_value); | 75 pref_hash_store_->StoreSplitHash(pref_path_, new_dict_value); |
| 74 } | 76 } |
| 77 | |
| 78 return was_reset; | |
|
erikwright (departed)
2014/02/06 20:04:03
ditto
robertshield
2014/02/07 04:36:19
ditto
| |
| 75 } | 79 } |
| OLD | NEW |