| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions/extension_pref_store.h" | 5 #include "chrome/browser/extensions/extension_pref_store.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util-inl.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "chrome/browser/pref_service.h" | 10 #include "chrome/browser/pref_service.h" |
| 10 | 11 |
| 11 ExtensionPrefStore::ExtensionPrefStore(PrefService* pref_service) | 12 ExtensionPrefStore::ExtensionPrefStore(PrefService* pref_service) |
| 12 : pref_service_(pref_service), | 13 : pref_service_(pref_service), |
| 13 prefs_(new DictionaryValue()) { | 14 prefs_(new DictionaryValue()) { |
| 14 } | 15 } |
| 15 | 16 |
| 17 ExtensionPrefStore::~ExtensionPrefStore() { |
| 18 STLDeleteElements(&extension_stack_); |
| 19 } |
| 20 |
| 16 // This could be sped up by keeping track of which extension currently controls | 21 // This could be sped up by keeping track of which extension currently controls |
| 17 // a given preference, among other optimizations. But we estimate that fewer | 22 // a given preference, among other optimizations. But we estimate that fewer |
| 18 // than 10 installed extensions will be trying to control any preferences, so | 23 // than 10 installed extensions will be trying to control any preferences, so |
| 19 // stick with this simpler algorithm until it causes a problem. | 24 // stick with this simpler algorithm until it causes a problem. |
| 20 void ExtensionPrefStore::UpdateOnePref(const wchar_t* path) { | 25 void ExtensionPrefStore::UpdateOnePref(const wchar_t* path) { |
| 21 // Query the PrefService to find the current value for this pref. | 26 // Query the PrefService to find the current value for this pref. |
| 22 // pref_service_ might be null in unit tests. | 27 // pref_service_ might be null in unit tests. |
| 23 scoped_ptr<Value> old_value; | 28 scoped_ptr<Value> old_value; |
| 24 if (pref_service_) { | 29 if (pref_service_) { |
| 25 old_value.reset( | 30 old_value.reset( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 UpdateOnePref(pref_path); | 85 UpdateOnePref(pref_path); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void ExtensionPrefStore::UninstallExtension(std::string extension_id) { | 88 void ExtensionPrefStore::UninstallExtension(std::string extension_id) { |
| 84 // Remove this extension from the stack. | 89 // Remove this extension from the stack. |
| 85 scoped_ptr<PrefValueMap> pref_values; | 90 scoped_ptr<PrefValueMap> pref_values; |
| 86 for (ExtensionStack::iterator i = extension_stack_.begin(); | 91 for (ExtensionStack::iterator i = extension_stack_.begin(); |
| 87 i != extension_stack_.end(); ++i) { | 92 i != extension_stack_.end(); ++i) { |
| 88 if ((*i)->extension_id == extension_id) { | 93 if ((*i)->extension_id == extension_id) { |
| 89 pref_values.reset((*i)->pref_values); | 94 pref_values.reset((*i)->pref_values); |
| 95 delete *i; |
| 90 extension_stack_.erase(i); | 96 extension_stack_.erase(i); |
| 91 break; | 97 break; |
| 92 } | 98 } |
| 93 } | 99 } |
| 94 if (!pref_values.get()) | 100 if (!pref_values.get()) |
| 95 return; | 101 return; |
| 96 | 102 |
| 97 UpdatePrefs(pref_values.get()); | 103 UpdatePrefs(pref_values.get()); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void ExtensionPrefStore::GetExtensionIDs(std::vector<std::string>* result) { | 106 void ExtensionPrefStore::GetExtensionIDs(std::vector<std::string>* result) { |
| 101 for (ExtensionStack::iterator i = extension_stack_.begin(); | 107 for (ExtensionStack::iterator i = extension_stack_.begin(); |
| 102 i != extension_stack_.end(); ++i) { | 108 i != extension_stack_.end(); ++i) { |
| 103 (*result).push_back((*i)->extension_id); | 109 (*result).push_back((*i)->extension_id); |
| 104 } | 110 } |
| 105 } | 111 } |
| OLD | NEW |