| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "services/preferences/tracked/dictionary_hash_store_contents.h" | 5 #include "services/preferences/tracked/dictionary_hash_store_contents.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "components/pref_registry/pref_registry_syncable.h" | 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 12 #include "components/prefs/persistent_pref_store.h" | 13 #include "components/prefs/persistent_pref_store.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 const char kPreferenceMACs[] = "protection.macs"; | 16 const char kPreferenceMACs[] = "protection.macs"; |
| 16 const char kSuperMACPref[] = "protection.super_mac"; | 17 const char kSuperMACPref[] = "protection.super_mac"; |
| 17 } | 18 } |
| 18 | 19 |
| 19 DictionaryHashStoreContents::DictionaryHashStoreContents( | 20 DictionaryHashStoreContents::DictionaryHashStoreContents( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void DictionaryHashStoreContents::SetSplitMac(const std::string& path, | 88 void DictionaryHashStoreContents::SetSplitMac(const std::string& path, |
| 88 const std::string& split_path, | 89 const std::string& split_path, |
| 89 const std::string& value) { | 90 const std::string& value) { |
| 90 // DictionaryValue handles a '.' delimiter. | 91 // DictionaryValue handles a '.' delimiter. |
| 91 SetMac(path + '.' + split_path, value); | 92 SetMac(path + '.' + split_path, value); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void DictionaryHashStoreContents::ImportEntry(const std::string& path, | 95 void DictionaryHashStoreContents::ImportEntry(const std::string& path, |
| 95 const base::Value* in_value) { | 96 const base::Value* in_value) { |
| 96 base::DictionaryValue* macs_dict = GetMutableContents(true); | 97 base::DictionaryValue* macs_dict = GetMutableContents(true); |
| 97 macs_dict->Set(path, in_value->DeepCopy()); | 98 macs_dict->Set(path, base::MakeUnique<base::Value>(*in_value)); |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool DictionaryHashStoreContents::RemoveEntry(const std::string& path) { | 101 bool DictionaryHashStoreContents::RemoveEntry(const std::string& path) { |
| 101 base::DictionaryValue* macs_dict = GetMutableContents(false); | 102 base::DictionaryValue* macs_dict = GetMutableContents(false); |
| 102 if (macs_dict) | 103 if (macs_dict) |
| 103 return macs_dict->RemovePath(path, NULL); | 104 return macs_dict->RemovePath(path, NULL); |
| 104 | 105 |
| 105 return false; | 106 return false; |
| 106 } | 107 } |
| 107 | 108 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 const base::DictionaryValue* macs_dict = NULL; | 120 const base::DictionaryValue* macs_dict = NULL; |
| 120 storage_->GetDictionary(kPreferenceMACs, &macs_dict); | 121 storage_->GetDictionary(kPreferenceMACs, &macs_dict); |
| 121 return macs_dict; | 122 return macs_dict; |
| 122 } | 123 } |
| 123 | 124 |
| 124 base::DictionaryValue* DictionaryHashStoreContents::GetMutableContents( | 125 base::DictionaryValue* DictionaryHashStoreContents::GetMutableContents( |
| 125 bool create_if_null) { | 126 bool create_if_null) { |
| 126 base::DictionaryValue* macs_dict = NULL; | 127 base::DictionaryValue* macs_dict = NULL; |
| 127 storage_->GetDictionary(kPreferenceMACs, &macs_dict); | 128 storage_->GetDictionary(kPreferenceMACs, &macs_dict); |
| 128 if (!macs_dict && create_if_null) { | 129 if (!macs_dict && create_if_null) { |
| 129 macs_dict = new base::DictionaryValue; | 130 macs_dict = storage_->SetDictionary( |
| 130 storage_->Set(kPreferenceMACs, macs_dict); | 131 kPreferenceMACs, base::MakeUnique<base::DictionaryValue>()); |
| 131 } | 132 } |
| 132 return macs_dict; | 133 return macs_dict; |
| 133 } | 134 } |
| OLD | NEW |