| 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 const base::Value* value, | 23 const base::Value* value, |
| 24 PrefHashStoreTransaction* transaction) const { | 24 PrefHashStoreTransaction* transaction) 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 transaction->StoreSplitHash(pref_path_, dict_value); | 30 transaction->StoreSplitHash(pref_path_, dict_value); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TrackedSplitPreference::EnforceAndReport( | 33 bool TrackedSplitPreference::EnforceAndReport( |
| 34 base::DictionaryValue* pref_store_contents, | 34 base::DictionaryValue* pref_store_contents, |
| 35 PrefHashStoreTransaction* transaction) const { | 35 PrefHashStoreTransaction* transaction) const { |
| 36 base::DictionaryValue* dict_value = NULL; | 36 base::DictionaryValue* dict_value = NULL; |
| 37 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && | 37 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && |
| 38 pref_store_contents->Get(pref_path_, NULL)) { | 38 pref_store_contents->Get(pref_path_, NULL)) { |
| 39 // There should be a dictionary or nothing at |pref_path_|. | 39 // There should be a dictionary or nothing at |pref_path_|. |
| 40 NOTREACHED(); | 40 NOTREACHED(); |
| 41 return; | 41 return false; |
| 42 } | 42 } |
| 43 | 43 |
| 44 std::vector<std::string> invalid_keys; | 44 std::vector<std::string> invalid_keys; |
| 45 PrefHashStoreTransaction::ValueState value_state = | 45 PrefHashStoreTransaction::ValueState value_state = |
| 46 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); | 46 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); |
| 47 | 47 |
| 48 if (value_state == PrefHashStoreTransaction::CHANGED) | 48 if (value_state == PrefHashStoreTransaction::CHANGED) |
| 49 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); | 49 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); |
| 50 | 50 |
| 51 helper_.ReportValidationResult(value_state); | 51 helper_.ReportValidationResult(value_state); |
| 52 | 52 |
| 53 TrackedPreferenceHelper::ResetAction reset_action = | 53 TrackedPreferenceHelper::ResetAction reset_action = |
| 54 helper_.GetAction(value_state); | 54 helper_.GetAction(value_state); |
| 55 helper_.ReportAction(reset_action); | 55 helper_.ReportAction(reset_action); |
| 56 | 56 |
| 57 bool was_reset = false; |
| 57 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 58 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
| 58 if (value_state == PrefHashStoreTransaction::CHANGED) { | 59 if (value_state == PrefHashStoreTransaction::CHANGED) { |
| 59 DCHECK(!invalid_keys.empty()); | 60 DCHECK(!invalid_keys.empty()); |
| 60 | 61 |
| 61 for (std::vector<std::string>::const_iterator it = | 62 for (std::vector<std::string>::const_iterator it = |
| 62 invalid_keys.begin(); it != invalid_keys.end(); ++it) { | 63 invalid_keys.begin(); it != invalid_keys.end(); ++it) { |
| 63 dict_value->Remove(*it, NULL); | 64 dict_value->Remove(*it, NULL); |
| 64 } | 65 } |
| 65 } else { | 66 } else { |
| 66 pref_store_contents->RemovePath(pref_path_, NULL); | 67 pref_store_contents->RemovePath(pref_path_, NULL); |
| 67 } | 68 } |
| 69 was_reset = true; |
| 68 } | 70 } |
| 69 | 71 |
| 70 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | 72 if (value_state != PrefHashStoreTransaction::UNCHANGED) { |
| 71 // Store the hash for the new value (whether it was reset or not). | 73 // Store the hash for the new value (whether it was reset or not). |
| 72 const base::DictionaryValue* new_dict_value = NULL; | 74 const base::DictionaryValue* new_dict_value = NULL; |
| 73 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | 75 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); |
| 74 transaction->StoreSplitHash(pref_path_, new_dict_value); | 76 transaction->StoreSplitHash(pref_path_, new_dict_value); |
| 75 } | 77 } |
| 78 |
| 79 return was_reset; |
| 76 } | 80 } |
| OLD | NEW |