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) {
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(
......
......@@ -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_;
......
......@@ -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())
......
......@@ -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);
};
......
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