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 762982557fa68e057a01c5547205dc77775955a4..08f51d1f26df88a60e36fa15f798c2af5c3531ff 100644 |
--- a/chrome/browser/extensions/extension_pref_store.cc |
+++ b/chrome/browser/extensions/extension_pref_store.cc |
@@ -14,7 +14,9 @@ |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profile.h" |
#include "chrome/common/extensions/extension.h" |
-#include "chrome/common/notification_service.h" |
+#include "chrome/common/notification_details.h" |
+#include "chrome/common/notification_source.h" |
+#include "chrome/common/notification_type.h" |
ExtensionPrefStore::ExtensionPrefStore(Profile* profile, |
PrefNotifier::PrefStoreType type) |
@@ -43,26 +45,18 @@ void ExtensionPrefStore::InstallExtensionPref(const Extension* extension, |
// If this extension is not already in the stack, add it. Otherwise, update |
// or add the value of this preference, but don't change the extension's |
- // position in the stack. We store the extension even if this preference |
- // isn't registered with our PrefService, so that the ordering of extensions |
- // is consistent among all local-state and user ExtensionPrefStores. |
- PrefService* pref_service = GetPrefService(); |
- // The pref_service may be NULL in unit testing. |
- bool is_registered_pref = (pref_service == NULL || |
- pref_service->FindPreference(new_pref_path) != NULL); |
- PrefValueMap* pref_values; |
+ // position in the stack. |
if (i == extension_stack_.end()) { |
- pref_values = new PrefValueMap(); |
- if (is_registered_pref) |
- (*pref_values)[new_pref_path] = new_pref_value; |
+ PrefValueMap* pref_values = new PrefValueMap(); |
+ (*pref_values)[new_pref_path] = new_pref_value; |
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; |
+ } else { |
+ PrefValueMap* pref_values = (*i)->pref_values; |
delete (*pref_values)[new_pref_path]; |
(*pref_values)[new_pref_path] = new_pref_value; |
} |
@@ -97,16 +91,6 @@ void ExtensionPrefStore::GetExtensionIDs(std::vector<std::string>* result) { |
// installed extensions will be trying to control any preferences, so stick |
// with this simpler algorithm until it causes a problem. |
void ExtensionPrefStore::UpdateOnePref(const char* path) { |
- PrefService* pref_service = GetPrefService(); |
- |
- // There are at least two PrefServices, one for local state and one for |
- // user prefs. (See browser_main.cc.) Different preferences are registered |
- // in each; if this one doesn't have the desired pref registered, we ignore |
- // it and let the other one handle it. |
- // The pref_service may be NULL in unit testing. |
- if (pref_service && !pref_service->FindPreference(path)) |
- return; |
- |
// Save the old value before removing it from the local cache. |
Value* my_old_value_ptr = NULL; |
prefs_->Get(path, &my_old_value_ptr); |
@@ -130,6 +114,8 @@ void ExtensionPrefStore::UpdateOnePref(const char* path) { |
} |
} |
+ // May be null in unit tests. |
+ PrefService* pref_service = GetPrefService(); |
if (pref_service) { |
bool value_changed = true; |
if (!my_old_value.get() && !my_new_value) { |
@@ -156,19 +142,24 @@ void ExtensionPrefStore::UpdatePrefs(const PrefValueMap* pref_values) { |
} |
PrefService* ExtensionPrefStore::GetPrefService() { |
- if (profile_) |
- return profile_->GetPrefs(); |
- return g_browser_process->local_state(); |
+ // May be null in unit tests. |
+ if (!profile_) |
+ return NULL; |
+ return profile_->GetPrefs(); |
} |
void ExtensionPrefStore::RegisterObservers() { |
+ // If profile_==NULL, this ExtensionPrefStore is for local-state. |
+ if (!profile_) |
+ return; |
+ |
notification_registrar_.Add(this, |
NotificationType::EXTENSION_PREF_CHANGED, |
- NotificationService::AllSources()); |
+ Source<Profile>(profile_)); |
notification_registrar_.Add(this, |
NotificationType::EXTENSION_UNLOADED, |
- NotificationService::AllSources()); |
+ Source<Profile>(profile_)); |
} |
void ExtensionPrefStore::Observe(NotificationType type, |
@@ -176,22 +167,15 @@ void ExtensionPrefStore::Observe(NotificationType type, |
const NotificationDetails& details) { |
switch (type.value) { |
case NotificationType::EXTENSION_PREF_CHANGED: { |
- Profile* extension_profile = Source<Profile>(source).ptr(); |
- // The ExtensionPrefStore for the local state watches all profiles. |
- if (!profile_ || profile_ == extension_profile) { |
- ExtensionPrefStore::ExtensionPrefDetails* data = |
- Details<ExtensionPrefStore::ExtensionPrefDetails>(details).ptr(); |
- InstallExtensionPref(data->first, data->second.first, |
- data->second.second); |
- } |
+ ExtensionPrefStore::ExtensionPrefDetails* data = |
+ Details<ExtensionPrefStore::ExtensionPrefDetails>(details).ptr(); |
+ InstallExtensionPref(data->first, data->second.first, |
+ data->second.second); |
break; |
} |
case NotificationType::EXTENSION_UNLOADED: { |
- Profile* extension_profile = Source<Profile>(source).ptr(); |
const Extension* extension = Details<const Extension>(details).ptr(); |
- // The ExtensionPrefStore for the local state watches all profiles. |
- if (profile_ == NULL || profile_ == extension_profile) |
- UninstallExtension(extension); |
+ UninstallExtension(extension); |
break; |
} |
default: { |