Commit e04850ca authored by limasdf@gmail.com's avatar limasdf@gmail.com

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
parent 567c269b
...@@ -62,16 +62,14 @@ EphemeralAppService* EphemeralAppService::Get(Profile* profile) { ...@@ -62,16 +62,14 @@ EphemeralAppService* EphemeralAppService::Get(Profile* profile) {
EphemeralAppService::EphemeralAppService(Profile* profile) EphemeralAppService::EphemeralAppService(Profile* profile)
: profile_(profile), : profile_(profile),
extension_registry_observer_(this),
ephemeral_app_count_(-1) { ephemeral_app_count_(-1) {
if (!CommandLine::ForCurrentProcess()->HasSwitch( if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableEphemeralApps)) switches::kEnableEphemeralApps))
return; return;
registrar_.Add(this, extension_registry_observer_.Add(
chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, extensions::ExtensionRegistry::Get(profile_));
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_)); content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
...@@ -90,26 +88,6 @@ void EphemeralAppService::Observe( ...@@ -90,26 +88,6 @@ void EphemeralAppService::Observe(
Init(); Init();
break; 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: { case chrome::NOTIFICATION_PROFILE_DESTROYED: {
// Ideally we need to know when the extension system is shutting down. // Ideally we need to know when the extension system is shutting down.
garbage_collect_apps_timer_.Stop(); garbage_collect_apps_timer_.Stop();
...@@ -120,6 +98,26 @@ void EphemeralAppService::Observe( ...@@ -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() { void EphemeralAppService::Init() {
InitEphemeralAppCount(); InitEphemeralAppCount();
TriggerGarbageCollect( TriggerGarbageCollect(
......
...@@ -8,20 +8,24 @@ ...@@ -8,20 +8,24 @@
#include <map> #include <map>
#include <set> #include <set>
#include "base/scoped_observer.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class Profile; class Profile;
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionRegistry;
} // namespace extensions } // namespace extensions
// Performs the background garbage collection of ephemeral apps. // Performs the background garbage collection of ephemeral apps.
class EphemeralAppService : public KeyedService, class EphemeralAppService : public KeyedService,
public content::NotificationObserver { public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public: public:
// Returns the instance for the given profile. This is a convenience wrapper // Returns the instance for the given profile. This is a convenience wrapper
// around EphemeralAppServiceFactory::GetForProfile. // around EphemeralAppServiceFactory::GetForProfile.
...@@ -52,6 +56,16 @@ class EphemeralAppService : public KeyedService, ...@@ -52,6 +56,16 @@ class EphemeralAppService : public KeyedService,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; 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 Init();
void InitEphemeralAppCount(); void InitEphemeralAppCount();
...@@ -70,6 +84,10 @@ class EphemeralAppService : public KeyedService, ...@@ -70,6 +84,10 @@ class EphemeralAppService : public KeyedService,
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_; base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_;
base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_; base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
...@@ -64,18 +65,16 @@ void AppShortcutManager::RegisterProfilePrefs( ...@@ -64,18 +65,16 @@ void AppShortcutManager::RegisterProfilePrefs(
AppShortcutManager::AppShortcutManager(Profile* profile) AppShortcutManager::AppShortcutManager(Profile* profile)
: profile_(profile), : profile_(profile),
is_profile_info_cache_observer_(false), 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 // 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). // there are no threads initialized (such as in unit tests).
DCHECK(!content::BrowserThread::IsThreadInitialized( DCHECK(!content::BrowserThread::IsThreadInitialized(
content::BrowserThread::UI) || content::BrowserThread::UI) ||
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
registrar_.Add(this, extension_registry_observer_.Add(
chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, extensions::ExtensionRegistry::Get(profile_));
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::Source<Profile>(profile_));
// Wait for extensions to be ready before running OnceOffCreateShortcuts. // Wait for extensions to be ready before running OnceOffCreateShortcuts.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_)); content::Source<Profile>(profile_));
...@@ -100,36 +99,30 @@ AppShortcutManager::~AppShortcutManager() { ...@@ -100,36 +99,30 @@ AppShortcutManager::~AppShortcutManager() {
void AppShortcutManager::Observe(int type, void AppShortcutManager::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type);
case chrome::NOTIFICATION_EXTENSIONS_READY: {
OnceOffCreateShortcuts(); OnceOffCreateShortcuts();
break; }
}
case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: { void AppShortcutManager::OnExtensionWillBeInstalled(
const extensions::InstalledExtensionInfo* installed_info = content::BrowserContext* browser_context,
content::Details<const extensions::InstalledExtensionInfo>(details) const Extension* extension,
.ptr(); bool is_update,
const Extension* extension = installed_info->extension; const std::string& old_name) {
// If the app is being updated, update any existing shortcuts but do not // If the app is being updated, update any existing shortcuts but do not
// create new ones. If it is being installed, automatically create a // create new ones. If it is being installed, automatically create a
// shortcut in the applications menu (e.g., Start Menu). // shortcut in the applications menu (e.g., Start Menu).
if (installed_info->is_update) { if (is_update) {
web_app::UpdateAllShortcuts( web_app::UpdateAllShortcuts(
base::UTF8ToUTF16(installed_info->old_name), profile_, extension); base::UTF8ToUTF16(old_name), profile_, extension);
} else if (ShouldCreateShortcutFor(profile_, extension)) { } else if (ShouldCreateShortcutFor(profile_, extension)) {
CreateShortcutsInApplicationsMenu(profile_, extension); CreateShortcutsInApplicationsMenu(profile_, extension);
} }
break; }
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { void AppShortcutManager::OnExtensionUninstalled(
const Extension* extension = content::Details<const Extension>( content::BrowserContext* browser_context,
details).ptr(); const Extension* extension) {
web_app::DeleteAllShortcuts(profile_, extension); web_app::DeleteAllShortcuts(profile_, extension);
break;
}
default:
NOTREACHED();
}
} }
void AppShortcutManager::OnProfileWillBeRemoved( void AppShortcutManager::OnProfileWillBeRemoved(
......
...@@ -5,15 +5,21 @@ ...@@ -5,15 +5,21 @@
#ifndef CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_ #ifndef CHROME_BROWSER_APPS_SHORTCUT_MANAGER_H_
#define 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 "chrome/browser/profiles/profile_info_cache_observer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
class PrefService; class PrefService;
class Profile; class Profile;
namespace extensions {
class ExtensionRegistry;
}
namespace user_prefs { namespace user_prefs {
class PrefRegistrySyncable; class PrefRegistrySyncable;
} }
...@@ -21,6 +27,7 @@ class PrefRegistrySyncable; ...@@ -21,6 +27,7 @@ class PrefRegistrySyncable;
// This class manages the installation of shortcuts for platform apps. // This class manages the installation of shortcuts for platform apps.
class AppShortcutManager : public KeyedService, class AppShortcutManager : public KeyedService,
public content::NotificationObserver, public content::NotificationObserver,
public extensions::ExtensionRegistryObserver,
public ProfileInfoCacheObserver { public ProfileInfoCacheObserver {
public: public:
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
...@@ -33,12 +40,22 @@ class AppShortcutManager : public KeyedService, ...@@ -33,12 +40,22 @@ class AppShortcutManager : public KeyedService,
// creates shortcuts for all apps. // creates shortcuts for all apps.
void OnceOffCreateShortcuts(); void OnceOffCreateShortcuts();
// content::NotificationObserver // content::NotificationObserver.
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; 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( virtual void OnProfileWillBeRemoved(
const base::FilePath& profile_path) OVERRIDE; const base::FilePath& profile_path) OVERRIDE;
...@@ -50,6 +67,10 @@ class AppShortcutManager : public KeyedService, ...@@ -50,6 +67,10 @@ class AppShortcutManager : public KeyedService,
bool is_profile_info_cache_observer_; bool is_profile_info_cache_observer_;
PrefService* prefs_; PrefService* prefs_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(AppShortcutManager); DISALLOW_COPY_AND_ASSIGN(AppShortcutManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment