| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 ~ScopedExtensionPrefUpdate() override {} | 196 ~ScopedExtensionPrefUpdate() override {} |
| 197 | 197 |
| 198 // DictionaryPrefUpdate overrides: | 198 // DictionaryPrefUpdate overrides: |
| 199 base::DictionaryValue* Get() override { | 199 base::DictionaryValue* Get() override { |
| 200 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); | 200 base::DictionaryValue* dict = DictionaryPrefUpdate::Get(); |
| 201 base::DictionaryValue* extension = NULL; | 201 base::DictionaryValue* extension = NULL; |
| 202 if (!dict->GetDictionary(extension_id_, &extension)) { | 202 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 203 // Extension pref does not exist, create it. | 203 // Extension pref does not exist, create it. |
| 204 extension = new base::DictionaryValue(); | 204 extension = new base::DictionaryValue(); |
| 205 dict->SetWithoutPathExpansion(extension_id_, extension); | 205 dict->SetWithoutPathExpansion(extension_id_, base::WrapUnique(extension)); |
| 206 } | 206 } |
| 207 return extension; | 207 return extension; |
| 208 } | 208 } |
| 209 | 209 |
| 210 private: | 210 private: |
| 211 const std::string extension_id_; | 211 const std::string extension_id_; |
| 212 | 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); | 213 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionPrefUpdate); |
| 214 }; | 214 }; |
| 215 | 215 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return NULL; | 291 return NULL; |
| 292 } | 292 } |
| 293 return key_value->GetType() == type_enum_value ? | 293 return key_value->GetType() == type_enum_value ? |
| 294 static_cast<T*>(key_value) : | 294 static_cast<T*>(key_value) : |
| 295 NULL; | 295 NULL; |
| 296 } | 296 } |
| 297 | 297 |
| 298 template <typename T, base::Value::Type type_enum_value> | 298 template <typename T, base::Value::Type type_enum_value> |
| 299 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { | 299 T* ExtensionPrefs::ScopedUpdate<T, type_enum_value>::Create() { |
| 300 base::DictionaryValue* dict = update_.Get(); | 300 base::DictionaryValue* dict = update_.Get(); |
| 301 base::DictionaryValue* extension = NULL; | 301 base::DictionaryValue* extension = nullptr; |
| 302 base::Value* key_value = NULL; | 302 base::Value* key_value = nullptr; |
| 303 T* value_as_t = NULL; | 303 T* value_as_t = nullptr; |
| 304 if (!dict->GetDictionary(extension_id_, &extension)) { | 304 if (!dict->GetDictionary(extension_id_, &extension)) { |
| 305 extension = new base::DictionaryValue; | 305 extension = new base::DictionaryValue; |
| 306 dict->SetWithoutPathExpansion(extension_id_, extension); | 306 dict->SetWithoutPathExpansion(extension_id_, base::WrapUnique(extension)); |
| 307 } | 307 } |
| 308 if (!extension->Get(key_, &key_value)) { | 308 if (!extension->Get(key_, &key_value)) { |
| 309 value_as_t = new T; | 309 value_as_t = new T; |
| 310 extension->SetWithoutPathExpansion(key_, value_as_t); | 310 extension->SetWithoutPathExpansion(key_, base::WrapUnique(value_as_t)); |
| 311 } else { | 311 } else { |
| 312 // It would be nice to CHECK that this doesn't happen, but since prefs can | 312 // It would be nice to CHECK that this doesn't happen, but since prefs can |
| 313 // get into a mangled state, we can't really do that. Instead, handle it | 313 // get into a mangled state, we can't really do that. Instead, handle it |
| 314 // gracefully (by overwriting whatever was previously there). | 314 // gracefully (by overwriting whatever was previously there). |
| 315 // TODO(devlin): It's unclear if there's anything we'll ever be able to do | 315 // TODO(devlin): It's unclear if there's anything we'll ever be able to do |
| 316 // here (corrupted prefs are sometimes a fact of life), but the debug info | 316 // here (corrupted prefs are sometimes a fact of life), but the debug info |
| 317 // might be useful. Remove the dumps after we analyze them. | 317 // might be useful. Remove the dumps after we analyze them. |
| 318 if (key_value->GetType() != type_enum_value) { | 318 if (key_value->GetType() != type_enum_value) { |
| 319 NOTREACHED(); | 319 NOTREACHED(); |
| 320 base::debug::SetCrashKeyValue( | 320 base::debug::SetCrashKeyValue( |
| 321 "existing_extension_pref_value_type", | 321 "existing_extension_pref_value_type", |
| 322 base::IntToString(static_cast<int>(key_value->GetType()))); | 322 base::IntToString(static_cast<int>(key_value->GetType()))); |
| 323 base::debug::DumpWithoutCrashing(); | 323 base::debug::DumpWithoutCrashing(); |
| 324 value_as_t = new T(); | 324 value_as_t = new T(); |
| 325 extension->SetWithoutPathExpansion(key_, value_as_t); | 325 extension->SetWithoutPathExpansion(key_, base::WrapUnique(value_as_t)); |
| 326 } else { | 326 } else { |
| 327 value_as_t = static_cast<T*>(key_value); | 327 value_as_t = static_cast<T*>(key_value); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 return value_as_t; | 330 return value_as_t; |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Explicit instantiations for Dictionary and List value types. | 333 // Explicit instantiations for Dictionary and List value types. |
| 334 template class ExtensionPrefs::ScopedUpdate<base::DictionaryValue, | 334 template class ExtensionPrefs::ScopedUpdate<base::DictionaryValue, |
| 335 base::Value::TYPE_DICTIONARY>; | 335 base::Value::TYPE_DICTIONARY>; |
| (...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 extension_pref_value_map_->RegisterExtension( | 1985 extension_pref_value_map_->RegisterExtension( |
| 1986 extension_id, install_time, is_enabled, is_incognito_enabled); | 1986 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 1987 | 1987 |
| 1988 FOR_EACH_OBSERVER( | 1988 FOR_EACH_OBSERVER( |
| 1989 ExtensionPrefsObserver, | 1989 ExtensionPrefsObserver, |
| 1990 observer_list_, | 1990 observer_list_, |
| 1991 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 1991 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 1992 } | 1992 } |
| 1993 | 1993 |
| 1994 } // namespace extensions | 1994 } // namespace extensions |
| OLD | NEW |