Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: chrome/browser/extensions/extension_pref_store.cc

Issue 4438001: First part to fix Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git/@trunk
Patch Set: whitespaces Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
« no previous file with comments | « chrome/browser/extensions/extension_pref_store.h ('k') | chrome/browser/extensions/extension_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698