| 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 "extensions/browser/extension_prefs.h" | 5 #include "extensions/browser/extension_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 extension_id_(extension_id) {} | 192 extension_id_(extension_id) {} |
| 193 | 193 |
| 194 ~ScopedExtensionPrefUpdate() override {} | 194 ~ScopedExtensionPrefUpdate() override {} |
| 195 | 195 |
| 196 // DictionaryPrefUpdate overrides: | 196 // DictionaryPrefUpdate overrides: |
| 197 base::DictionaryValue* Get() override { | 197 base::DictionaryValue* Get() override { |
| 198 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); | 198 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); |
| 199 base::DictionaryValue* extension = NULL; | 199 base::DictionaryValue* extension = NULL; |
| 200 if (!dict->GetDictionary(extension_id_, &extension)) { | 200 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 201 // Extension pref does not exist, create it. | 201 // Extension pref does not exist, create it. |
| 202 extension = new base::DictionaryValue(); | 202 dict->SetWithoutPathExpansion(extension_id_, |
| 203 dict->SetWithoutPathExpansion(extension_id_, base::WrapUnique(extension)); | 203 base::MakeUnique<base::DictionaryValue>()); |
| 204 dict->GetDictionaryWithoutPathExpansion(extension_id_, &extension); |
| 204 } | 205 } |
| 205 return extension; | 206 return extension; |
| 206 } | 207 } |
| 207 | 208 |
| 208 private: | 209 private: |
| 209 const std::string extension_id_; | 210 const std::string extension_id_; |
| 210 | 211 |
| 211 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); | 212 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); |
| 212 }; | 213 }; |
| 213 | 214 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return key_value->GetType() == type_enum_value ? | 292 return key_value->GetType() == type_enum_value ? |
| 292 static_cast<T*>(key_value) : | 293 static_cast<T*>(key_value) : |
| 293 NULL; | 294 NULL; |
| 294 } | 295 } |
| 295 | 296 |
| 296 template <typename T, base::Value::Type type_enum_value> | 297 template <typename T, base::Value::Type type_enum_value> |
| 297 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { | 298 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { |
| 298 base::DictionaryValue* dict = update_.Get(); | 299 base::DictionaryValue* dict = update_.Get(); |
| 299 base::DictionaryValue* extension = nullptr; | 300 base::DictionaryValue* extension = nullptr; |
| 300 base::Value* key_value = nullptr; | 301 base::Value* key_value = nullptr; |
| 301 T* value_as_t = nullptr; | |
| 302 if (!dict->GetDictionary(extension_id_, &extension)) { | 302 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 303 extension = new base::DictionaryValue; | 303 dict->SetWithoutPathExpansion(extension_id_, |
| 304 dict->SetWithoutPathExpansion(extension_id_, base::WrapUnique(extension)); | 304 base::MakeUnique<base::DictionaryValue>()); |
| 305 dict->GetDictionaryWithoutPathExpansion(extension_id_, &extension); |
| 305 } | 306 } |
| 306 if (!extension->Get(key_, &key_value)) { | 307 if (!extension->Get(key_, &key_value)) { |
| 307 value_as_t = new T; | 308 extension->SetWithoutPathExpansion(key_, base::MakeUnique<T>()); |
| 308 extension->SetWithoutPathExpansion(key_, base::WrapUnique(value_as_t)); | 309 extension->GetWithoutPathExpansion(key_, &key_value); |
| 309 } else { | 310 } else { |
| 310 // It would be nice to CHECK that this doesn't happen, but since prefs can | 311 // It would be nice to CHECK that this doesn't happen, but since prefs can |
| 311 // get into a mangled state, we can't really do that. Instead, handle it | 312 // get into a mangled state, we can't really do that. Instead, handle it |
| 312 // gracefully (by overwriting whatever was previously there). | 313 // gracefully (by overwriting whatever was previously there). |
| 313 // TODO(devlin): It's unclear if there's anything we'll ever be able to do | 314 // TODO(devlin): It's unclear if there's anything we'll ever be able to do |
| 314 // here (corrupted prefs are sometimes a fact of life), but the debug info | 315 // here (corrupted prefs are sometimes a fact of life), but the debug info |
| 315 // might be useful. Remove the dumps after we analyze them. | 316 // might be useful. Remove the dumps after we analyze them. |
| 316 if (key_value->GetType() != type_enum_value) { | 317 if (key_value->GetType() != type_enum_value) { |
| 317 NOTREACHED(); | 318 NOTREACHED(); |
| 318 value_as_t = new T(); | 319 extension->SetWithoutPathExpansion(key_, base::MakeUnique<T>()); |
| 319 extension->SetWithoutPathExpansion(key_, base::WrapUnique(value_as_t)); | 320 extension->GetWithoutPathExpansion(key_, &key_value); |
| 320 } else { | |
| 321 value_as_t = static_cast<T*>(key_value); | |
| 322 } | 321 } |
| 323 } | 322 } |
| 324 return value_as_t; | 323 return static_cast<T*>(key_value); |
| 325 } | 324 } |
| 326 | 325 |
| 327 // Explicit instantiations for Dictionary and List value types. | 326 // Explicit instantiations for Dictionary and List value types. |
| 328 template class ExtensionPrefs::ScopedUpdate<base::DictionaryValue, | 327 template class ExtensionPrefs::ScopedUpdate<base::DictionaryValue, |
| 329 base::Value::Type::DICTIONARY>; | 328 base::Value::Type::DICTIONARY>; |
| 330 template class ExtensionPrefs::ScopedUpdate<base::ListValue, | 329 template class ExtensionPrefs::ScopedUpdate<base::ListValue, |
| 331 base::Value::Type::LIST>; | 330 base::Value::Type::LIST>; |
| 332 | 331 |
| 333 // | 332 // |
| 334 // ExtensionPrefs | 333 // ExtensionPrefs |
| (...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1960 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 1959 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
| 1961 | 1960 |
| 1962 extension_pref_value_map_->RegisterExtension( | 1961 extension_pref_value_map_->RegisterExtension( |
| 1963 extension_id, install_time, is_enabled, is_incognito_enabled); | 1962 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 1964 | 1963 |
| 1965 for (auto& observer : observer_list_) | 1964 for (auto& observer : observer_list_) |
| 1966 observer.OnExtensionRegistered(extension_id, install_time, is_enabled); | 1965 observer.OnExtensionRegistered(extension_id, install_time, is_enabled); |
| 1967 } | 1966 } |
| 1968 | 1967 |
| 1969 } // namespace extensions | 1968 } // namespace extensions |
| OLD | NEW |