summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 02:41:34 +0000
committerlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 02:41:34 +0000
commite04850cae1477c60245ab6c3ba665dcf96bb5dd8 (patch)
treee9d0a3f3709bcf0b1d6331db11b34e0d2ad86bcc
parent567c269bb5cf5e1d4e44ce2b79bfd60520cee0a4 (diff)
downloadchromium_src-e04850cae1477c60245ab6c3ba665dcf96bb5dd8.zip
chromium_src-e04850cae1477c60245ab6c3ba665dcf96bb5dd8.tar.gz
chromium_src-e04850cae1477c60245ab6c3ba665dcf96bb5dd8.tar.bz2
cleanup: Remove NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED from c/b/apps
Use ExtensionRegistry instead. R=kalman@chromium.org BUG=376293 Review URL: https://codereview.chromium.org/298253002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273115 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/apps/ephemeral_app_service.cc48
-rw-r--r--chrome/browser/apps/ephemeral_app_service.h20
-rw-r--r--chrome/browser/apps/shortcut_manager.cc63
-rw-r--r--chrome/browser/apps/shortcut_manager.h25
4 files changed, 93 insertions, 63 deletions
diff --git a/chrome/browser/apps/ephemeral_app_service.cc b/chrome/browser/apps/ephemeral_app_service.cc
index 0e4e117..9ed8a56 100644
--- a/chrome/browser/apps/ephemeral_app_service.cc
+++ b/chrome/browser/apps/ephemeral_app_service.cc
@@ -62,16 +62,14 @@ EphemeralAppService* EphemeralAppService::Get(Profile* profile) {
EphemeralAppService::EphemeralAppService(Profile* profile)
: profile_(profile),
+ extension_registry_observer_(this),
ephemeral_app_count_(-1) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableEphemeralApps))
return;
- 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(
+ extensions::ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
@@ -90,26 +88,6 @@ void EphemeralAppService::Observe(
Init();
break;
}
- case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: {
- const Extension* extension =
- content::Details<const InstalledExtensionInfo>(details)->extension;
- DCHECK(extension);
- if (extensions::util::IsEphemeralApp(extension->id(), profile_)) {
- ++ephemeral_app_count_;
- if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount)
- TriggerGarbageCollect(
- base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay));
- }
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- DCHECK(extension);
- if (extensions::util::IsEphemeralApp(extension->id(), profile_))
- --ephemeral_app_count_;
- break;
- }
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
// Ideally we need to know when the extension system is shutting down.
garbage_collect_apps_timer_.Stop();
@@ -120,6 +98,26 @@ void EphemeralAppService::Observe(
}
}
+void EphemeralAppService::OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ bool is_update,
+ const std::string& old_name) {
+ if (extensions::util::IsEphemeralApp(extension->id(), profile_)) {
+ ++ephemeral_app_count_;
+ if (ephemeral_app_count_ >= kGarbageCollectAppsTriggerCount)
+ TriggerGarbageCollect(
+ base::TimeDelta::FromSeconds(kGarbageCollectAppsInstallDelay));
+ }
+}
+
+void EphemeralAppService::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension) {
+ if (extensions::util::IsEphemeralApp(extension->id(), profile_))
+ --ephemeral_app_count_;
+}
+
void EphemeralAppService::Init() {
InitEphemeralAppCount();
TriggerGarbageCollect(
diff --git a/chrome/browser/apps/ephemeral_app_service.h b/chrome/browser/apps/ephemeral_app_service.h
index a1d4fbb..edad28d 100644
--- a/chrome/browser/apps/ephemeral_app_service.h
+++ b/chrome/browser/apps/ephemeral_app_service.h
@@ -8,20 +8,24 @@
#include <map>
#include <set>
+#include "base/scoped_observer.h"
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "extensions/browser/extension_registry_observer.h"
class Profile;
namespace extensions {
class Extension;
+class ExtensionRegistry;
} // namespace extensions
// Performs the background garbage collection of ephemeral apps.
class EphemeralAppService : public KeyedService,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public extensions::ExtensionRegistryObserver {
public:
// Returns the instance for the given profile. This is a convenience wrapper
// around EphemeralAppServiceFactory::GetForProfile.
@@ -52,6 +56,16 @@ class EphemeralAppService : public KeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // extensions::ExtensionRegistryObserver.
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ bool is_update,
+ const std::string& old_name) OVERRIDE;
+ virtual void OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension) OVERRIDE;
+
void Init();
void InitEphemeralAppCount();
@@ -70,6 +84,10 @@ class EphemeralAppService : public KeyedService,
content::NotificationRegistrar registrar_;
+ ScopedObserver<extensions::ExtensionRegistry,
+ extensions::ExtensionRegistryObserver>
+ extension_registry_observer_;
+
base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_;
base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_;
diff --git a/chrome/browser/apps/shortcut_manager.cc b/chrome/browser/apps/shortcut_manager.cc
index 2e5221a..efb54cc 100644
--- a/chrome/browser/apps/shortcut_manager.cc
+++ b/chrome/browser/apps/shortcut_manager.cc
@@ -25,6 +25,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h"
@@ -64,18 +65,16 @@ void AppShortcutManager::RegisterProfilePrefs(
AppShortcutManager::AppShortcutManager(Profile* profile)
: profile_(profile),
is_profile_info_cache_observer_(false),
- prefs_(profile->GetPrefs()) {
+ prefs_(profile->GetPrefs()),
+ extension_registry_observer_(this) {
// Use of g_browser_process requires that we are either on the UI thread, or
// there are no threads initialized (such as in unit tests).
DCHECK(!content::BrowserThread::IsThreadInitialized(
content::BrowserThread::UI) ||
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- 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(
+ extensions::ExtensionRegistry::Get(profile_));
// Wait for extensions to be ready before running OnceOffCreateShortcuts.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_));
@@ -100,38 +99,32 @@ AppShortcutManager::~AppShortcutManager() {
void AppShortcutManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSIONS_READY: {
- OnceOffCreateShortcuts();
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: {
- const extensions::InstalledExtensionInfo* installed_info =
- content::Details<const extensions::InstalledExtensionInfo>(details)
- .ptr();
- const Extension* extension = installed_info->extension;
- // If the app is being updated, update any existing shortcuts but do not
- // create new ones. If it is being installed, automatically create a
- // shortcut in the applications menu (e.g., Start Menu).
- if (installed_info->is_update) {
- web_app::UpdateAllShortcuts(
- base::UTF8ToUTF16(installed_info->old_name), profile_, extension);
- } else if (ShouldCreateShortcutFor(profile_, extension)) {
- CreateShortcutsInApplicationsMenu(profile_, extension);
- }
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
- const Extension* extension = content::Details<const Extension>(
- details).ptr();
- web_app::DeleteAllShortcuts(profile_, extension);
- break;
- }
- default:
- NOTREACHED();
+ DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type);
+ OnceOffCreateShortcuts();
+}
+
+void AppShortcutManager::OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ const std::string& old_name) {
+ // If the app is being updated, update any existing shortcuts but do not
+ // create new ones. If it is being installed, automatically create a
+ // shortcut in the applications menu (e.g., Start Menu).
+ if (is_update) {
+ web_app::UpdateAllShortcuts(
+ base::UTF8ToUTF16(old_name), profile_, extension);
+ } else if (ShouldCreateShortcutFor(profile_, extension)) {
+ CreateShortcutsInApplicationsMenu(profile_, extension);
}
}
+void AppShortcutManager::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ web_app::DeleteAllShortcuts(profile_, extension);
+}
+
void AppShortcutManager::OnProfileWillBeRemoved(
const base::FilePath& profile_path) {
if (profile_path != profile_->GetPath())
diff --git a/chrome/browser/apps/shortcut_manager.h b/chrome/browser/apps/shortcut_manager.h
index b94101e..63e9112e 100644
--- a/chrome/browser/apps/shortcut_manager.h
+++ b/chrome/browser/apps/shortcut_manager.h
@@ -5,15 +5,21 @@
#ifndef CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
#define CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
+#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
class PrefService;
class Profile;
+namespace extensions {
+class ExtensionRegistry;
+}
+
namespace user_prefs {
class PrefRegistrySyncable;
}
@@ -21,6 +27,7 @@ class PrefRegistrySyncable;
// This class manages the installation of shortcuts for platform apps.
class AppShortcutManager : public KeyedService,
public content::NotificationObserver,
+ public extensions::ExtensionRegistryObserver,
public ProfileInfoCacheObserver {
public:
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
@@ -33,12 +40,22 @@ class AppShortcutManager : public KeyedService,
// creates shortcuts for all apps.
void OnceOffCreateShortcuts();
- // content::NotificationObserver
+ // content::NotificationObserver.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // ProfileInfoCacheObserver
+ // extensions::ExtensionRegistryObserver.
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ bool is_update,
+ const std::string& old_name) OVERRIDE;
+ virtual void OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension) OVERRIDE;
+
+ // ProfileInfoCacheObserver.
virtual void OnProfileWillBeRemoved(
const base::FilePath& profile_path) OVERRIDE;
@@ -50,6 +67,10 @@ class AppShortcutManager : public KeyedService,
bool is_profile_info_cache_observer_;
PrefService* prefs_;
+ ScopedObserver<extensions::ExtensionRegistry,
+ extensions::ExtensionRegistryObserver>
+ extension_registry_observer_;
+
DISALLOW_COPY_AND_ASSIGN(AppShortcutManager);
};