Index: chrome/browser/extensions/extension_pref_store.cc |
diff --git a/chrome/browser/extensions/extension_pref_store.cc b/chrome/browser/extensions/extension_pref_store.cc |
index 27719ed3a69345009a2b73be9c7c7156c619e99e..762982557fa68e057a01c5547205dc77775955a4 100644 |
--- a/chrome/browser/extensions/extension_pref_store.cc |
+++ b/chrome/browser/extensions/extension_pref_store.cc |
@@ -4,9 +4,13 @@ |
#include "chrome/browser/extensions/extension_pref_store.h" |
+#include <limits> |
+ |
#include "base/logging.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/extensions/extensions_service.h" |
+#include "chrome/browser/extensions/extension_prefs.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profile.h" |
#include "chrome/common/extensions/extension.h" |
@@ -28,9 +32,12 @@ ExtensionPrefStore::~ExtensionPrefStore() { |
void ExtensionPrefStore::InstallExtensionPref(const Extension* extension, |
const char* new_pref_path, |
Value* new_pref_value) { |
+ if (extension_stack_.empty()) |
+ LazyInit(); |
+ |
ExtensionStack::iterator i; |
for (i = extension_stack_.begin(); i != extension_stack_.end(); ++i) { |
- if ((*i)->extension == extension) |
+ if ((*i)->extension_id == extension->id()) |
break; |
} |
@@ -49,9 +56,11 @@ void ExtensionPrefStore::InstallExtensionPref(const Extension* extension, |
if (is_registered_pref) |
(*pref_values)[new_pref_path] = new_pref_value; |
- ExtensionPrefs* extension_prefs = new ExtensionPrefs(extension, |
+ ExtensionPrefs* extension_prefs = new ExtensionPrefs(extension->id(), |
pref_values); |
extension_stack_.push_front(extension_prefs); |
+ AddPrecedence(extension->id()); |
+ |
} else if (is_registered_pref) { |
pref_values = (*i)->pref_values; |
delete (*pref_values)[new_pref_path]; |
@@ -66,9 +75,10 @@ void ExtensionPrefStore::UninstallExtension(const Extension* extension) { |
// Remove this extension from the stack. |
for (ExtensionStack::iterator i = extension_stack_.begin(); |
i != extension_stack_.end(); ++i) { |
- if ((*i)->extension == extension) { |
+ if ((*i)->extension_id == extension->id()) { |
scoped_ptr<ExtensionPrefs> to_be_deleted(*i); |
extension_stack_.erase(i); |
+ RemovePrecedence(to_be_deleted->extension_id); |
UpdatePrefs(to_be_deleted->pref_values); |
return; |
} |
@@ -78,7 +88,7 @@ void ExtensionPrefStore::UninstallExtension(const Extension* extension) { |
void ExtensionPrefStore::GetExtensionIDs(std::vector<std::string>* result) { |
for (ExtensionStack::iterator i = extension_stack_.begin(); |
i != extension_stack_.end(); ++i) { |
- (*result).push_back((*i)->extension->id()); |
+ (*result).push_back((*i)->extension_id); |
} |
} |
@@ -190,8 +200,67 @@ void ExtensionPrefStore::Observe(NotificationType type, |
} |
} |
-ExtensionPrefStore::ExtensionPrefs::ExtensionPrefs(const Extension* extension, |
- PrefValueMap* values) : extension(extension), pref_values(values) {} |
+void ExtensionPrefStore::AddPrecedence(const std::string& extension_id) { |
+ std::vector<std::string> precedence; |
+ GetExtensionPrecedences(&precedence); |
+ |
+ bool already_present = |
+ find(precedence.begin(), precedence.end(), extension_id) != |
+ precedence.end(); |
+ DCHECK(!already_present) << "Precedence for extension " << extension_id |
+ << " was already registered"; |
+ |
+ precedence.push_back(extension_id); |
+ PersistExtensionPrecedences(precedence); |
+} |
+ |
+void ExtensionPrefStore::RemovePrecedence(const std::string& extension_id) { |
+ std::vector<std::string> precedence; |
+ GetExtensionPrecedences(&precedence); |
+ std::vector<std::string>::iterator i = |
+ find(precedence.begin(), precedence.end(), extension_id); |
+ if (i != precedence.end()) |
+ precedence.erase(i); |
+ PersistExtensionPrecedences(precedence); |
+} |
+ |
+void ExtensionPrefStore::LazyInit() { |
+ DCHECK(extension_stack_.empty()) |
+ << "LazyInit called even though extension_stack_ is already initialized"; |
+ |
+ std::vector<std::string> precedence; |
+ GetExtensionPrecedences(&precedence); |
+ std::vector<std::string>::const_iterator i; |
+ for (i = precedence.begin(); i != precedence.end(); ++i) { |
+ ExtensionPrefs* extension_prefs = |
+ new ExtensionPrefs(*i, new PrefValueMap()); |
+ extension_stack_.push_front(extension_prefs); |
+ } |
+} |
+ |
+void ExtensionPrefStore::PersistExtensionPrecedences( |
+ const std::vector<std::string>& precedence) { |
+ DCHECK(profile_); |
+ DCHECK(profile_->GetExtensionsService()); |
+ DCHECK(profile_->GetExtensionsService()->extension_prefs()); |
+ ::ExtensionPrefs* extension_prefs = |
+ profile_->GetExtensionsService()->extension_prefs(); |
+ extension_prefs->PersistExtensionPrecedences(precedence); |
+} |
+ |
+void ExtensionPrefStore::GetExtensionPrecedences( |
+ std::vector<std::string>* precedence) const { |
+ DCHECK(profile_); |
+ DCHECK(profile_->GetExtensionsService()); |
+ DCHECK(profile_->GetExtensionsService()->extension_prefs()); |
+ ::ExtensionPrefs* extension_prefs = |
+ profile_->GetExtensionsService()->extension_prefs(); |
+ extension_prefs->GetExtensionPrecedences(precedence); |
+} |
+ |
+ExtensionPrefStore::ExtensionPrefs::ExtensionPrefs( |
+ const std::string& extension_id, PrefValueMap* values) |
+ : extension_id(extension_id), pref_values(values) {} |
ExtensionPrefStore::ExtensionPrefs::~ExtensionPrefs() { |
STLDeleteValues(pref_values); |