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

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

Issue 165414: Disable an extension when it is upgraded to a version that requires more (Closed)
Patch Set: more comments Created 11 years, 4 months 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
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_ui_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_prefs.cc
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index bc88831693d22c79d2466e070c837e13c75def7b..f56fae457d43f2e4499b45a0902046aa6e11a076 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -299,7 +299,7 @@ void ExtensionPrefs::SetShelfToolstripOrder(const URLList& urls) {
}
void ExtensionPrefs::OnExtensionInstalled(Extension* extension) {
- std::string id = extension->id();
+ const std::string& id = extension->id();
UpdateExtensionPref(id, kPrefState,
Value::CreateIntegerValue(Extension::ENABLED));
UpdateExtensionPref(id, kPrefLocation,
@@ -326,12 +326,37 @@ void ExtensionPrefs::OnExtensionUninstalled(const Extension* extension,
}
}
+Extension::State ExtensionPrefs::GetExtensionState(
+ const std::string& extension_id) {
+ DictionaryValue* extension = GetExtensionPref(extension_id);
+
+ // If the extension doesn't have a pref, it's a --load-extension.
+ if (!extension)
+ return Extension::ENABLED;
+
+ int state = -1;
+ if (!extension->GetInteger(kPrefState, &state) ||
+ state < 0 || state >= Extension::NUM_STATES) {
+ LOG(ERROR) << "Bad or missing pref 'state' for extension '"
+ << extension_id << "'";
+ return Extension::ENABLED;
+ }
+ return static_cast<Extension::State>(state);
+}
+
+void ExtensionPrefs::SetExtensionState(Extension* extension,
+ Extension::State state) {
+ UpdateExtensionPref(extension->id(), kPrefState,
+ Value::CreateIntegerValue(state));
+ prefs_->SavePersistentPrefs();
+}
+
bool ExtensionPrefs::UpdateExtensionPref(const std::string& extension_id,
const std::wstring& key,
Value* data_value) {
DictionaryValue* extension = GetOrCreateExtensionPref(extension_id);
if (!extension->Set(key, data_value)) {
- NOTREACHED() << L"Cannot modify key: '" << key.c_str()
+ NOTREACHED() << "Cannot modify key: '" << key.c_str()
<< "' for extension: '" << extension_id.c_str() << "'";
return false;
}
@@ -359,3 +384,12 @@ DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref(
}
return extension;
}
+
+DictionaryValue* ExtensionPrefs::GetExtensionPref(
+ const std::string& extension_id) {
+ const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref);
+ DictionaryValue* extension = NULL;
+ std::wstring id = ASCIIToWide(extension_id);
+ dict->GetDictionary(id, &extension);
+ return extension;
+}
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698