Chromium Code Reviews| Index: chrome/browser/extensions/api/storage/managed_value_store_cache.cc |
| diff --git a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc |
| index 5134fd5c62edfcdfc32968e5c4f44ff8e2857cbd..c48eab6cda65fabcf12bcc2a75732cfe8641bf01 100644 |
| --- a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc |
| +++ b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc |
| @@ -10,7 +10,7 @@ |
| #include "base/file_util.h" |
| #include "base/logging.h" |
| #include "base/memory/weak_ptr.h" |
| -#include "chrome/browser/chrome_notification_types.h" |
| +#include "base/scoped_observer.h" |
| #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
| #include "chrome/browser/policy/profile_policy_connector.h" |
| #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| @@ -23,13 +23,10 @@ |
| #include "components/policy/core/common/schema_map.h" |
| #include "components/policy/core/common/schema_registry.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "content/public/browser/notification_details.h" |
| -#include "content/public/browser/notification_observer.h" |
| -#include "content/public/browser/notification_registrar.h" |
| -#include "content/public/browser/notification_source.h" |
| #include "extensions/browser/api/storage/settings_storage_factory.h" |
| #include "extensions/browser/extension_prefs.h" |
| #include "extensions/browser/extension_registry.h" |
| +#include "extensions/browser/extension_registry_observer.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/browser/value_store/value_store_change.h" |
| #include "extensions/common/api/storage.h" |
| @@ -44,6 +41,7 @@ using content::BrowserContext; |
| using content::BrowserThread; |
| namespace extensions { |
| +class ExtensionRegistry; |
| namespace storage = core_api::storage; |
| @@ -67,17 +65,21 @@ const char kLegacyBrowserSupportExtensionId[] = |
| // to fetch cloud policy for those extensions, and allows its providers to |
| // selectively load only extension policy that has users. |
| class ManagedValueStoreCache::ExtensionTracker |
| - : public content::NotificationObserver { |
| + : public ExtensionRegistryObserver { |
| public: |
| explicit ExtensionTracker(Profile* profile); |
| virtual ~ExtensionTracker() {} |
| - // NotificationObserver implementation: |
| - virtual void Observe(int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) OVERRIDE; |
| - |
| private: |
| + // ExtensionRegistryObserver implementation. |
| + virtual void OnExtensionWillBeInstalled( |
| + content::BrowserContext* browser_context, |
| + const Extension* extension, |
| + bool is_update, |
| + const std::string& old_name) OVERRIDE; |
| + virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| + const Extension* extension) OVERRIDE; |
| + |
| // Handler for the signal from ExtensionSystem::ready(). |
| void OnExtensionsReady(); |
| @@ -93,7 +95,8 @@ class ManagedValueStoreCache::ExtensionTracker |
| void Register(const policy::ComponentMap* components); |
| Profile* profile_; |
| - content::NotificationRegistrar registrar_; |
| + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| + extension_registry_observer_; |
| policy::SchemaRegistry* schema_registry_; |
| base::WeakPtrFactory<ExtensionTracker> weak_factory_; |
| @@ -102,16 +105,11 @@ class ManagedValueStoreCache::ExtensionTracker |
| ManagedValueStoreCache::ExtensionTracker::ExtensionTracker(Profile* profile) |
| : profile_(profile), |
| + extension_registry_observer_(this), |
| schema_registry_( |
| policy::SchemaRegistryServiceFactory::GetForContext(profile)), |
| weak_factory_(this) { |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
| - content::Source<Profile>(profile_)); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| - content::Source<Profile>(profile_)); |
| - |
| + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| // Load schemas when the extension system is ready. It might be ready now. |
| ExtensionSystem::Get(profile_)->ready().Post( |
| FROM_HERE, |
| @@ -119,37 +117,27 @@ ManagedValueStoreCache::ExtensionTracker::ExtensionTracker(Profile* profile) |
| weak_factory_.GetWeakPtr())); |
| } |
| -void ManagedValueStoreCache::ExtensionTracker::Observe( |
| - int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| +void ManagedValueStoreCache::ExtensionTracker::OnExtensionWillBeInstalled( |
| + content::BrowserContext* browser_context, |
| + const Extension* extension, |
| + bool is_update, |
| + const std::string& old_name) { |
| // Some extensions are installed on the first run before the ExtensionSystem |
| // becomes ready. Wait until all of them are ready before registering the |
| // schemas of managed extensions, so that the policy loaders are reloaded at |
| // most once. |
| if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) |
| return; |
| - |
| - switch (type) { |
| - case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: { |
| - scoped_ptr<ExtensionSet> added(new ExtensionSet); |
| - added->Insert( |
| - content::Details<InstalledExtensionInfo>(details)->extension); |
| - LoadSchemas(added.Pass()); |
| - break; |
| - } |
| - case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| - const Extension* removed = |
| - content::Details<const Extension>(details).ptr(); |
| - if (removed && UsesManagedStorage(removed)) { |
| - schema_registry_->UnregisterComponent(policy::PolicyNamespace( |
| - policy::POLICY_DOMAIN_EXTENSIONS, removed->id())); |
| - } |
| - break; |
| - } |
| - default: |
| - NOTREACHED(); |
| - return; |
| + scoped_ptr<ExtensionSet> added(new ExtensionSet); |
| + added->Insert(extension); |
| + LoadSchemas(added.Pass()); |
| +} |
| +void ManagedValueStoreCache::ExtensionTracker::OnExtensionUninstalled( |
| + content::BrowserContext* browser_context, |
| + const Extension* extension) { |
|
Devlin
2014/05/28 16:58:34
I don't _think_ this can ever happen, but the if s
limasdf
2014/05/28 17:38:43
Done.
The reason why I removed is the comment says
|
| + if (extension && UsesManagedStorage(extension)) { |
| + schema_registry_->UnregisterComponent(policy::PolicyNamespace( |
| + policy::POLICY_DOMAIN_EXTENSIONS, extension->id())); |
| } |
| } |