Skip to content

Commit

Permalink
Remove deprecated extension notification from AppLoadService
Browse files Browse the repository at this point in the history
BUG=354046

Review URL: https://codereview.chromium.org/441553002

Cr-Commit-Position: refs/heads/master@{#295186}
  • Loading branch information
sunglim authored and Commit bot committed Sep 17, 2014
1 parent 4164405 commit d379175
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 57 deletions.
102 changes: 49 additions & 53 deletions apps/app_load_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/notification_types.h"
#include "extensions/common/extension.h"
Expand All @@ -36,12 +37,12 @@ AppLoadService::AppLoadService(Profile* profile)
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::NotificationService::AllSources());
extensions::ExtensionRegistry::Get(profile_)->AddObserver(this);
}

AppLoadService::~AppLoadService() {}
AppLoadService::~AppLoadService() {
extensions::ExtensionRegistry::Get(profile_)->RemoveObserver(this);
}

void AppLoadService::RestartApplication(const std::string& extension_id) {
post_reload_actions_[extension_id].action_type = RESTART;
Expand Down Expand Up @@ -84,64 +85,59 @@ AppLoadService* AppLoadService::Get(Profile* profile) {
void AppLoadService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
extensions::ExtensionHost* host =
content::Details<extensions::ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
// It is possible for an extension to be unloaded before it stops loading.
if (!extension)
break;
std::map<std::string, PostReloadAction>::iterator it =
post_reload_actions_.find(extension->id());
if (it == post_reload_actions_.end())
break;

switch (it->second.action_type) {
case LAUNCH:
LaunchPlatformApp(profile_, extension);
break;
case RESTART:
RestartPlatformApp(profile_, extension);
break;
case LAUNCH_WITH_COMMAND_LINE:
LaunchPlatformAppWithCommandLine(
profile_, extension, it->second.command_line,
it->second.current_dir);
break;
default:
NOTREACHED();
}

post_reload_actions_.erase(it);
DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING);
extensions::ExtensionHost* host =
content::Details<extensions::ExtensionHost>(details).ptr();
const Extension* extension = host->extension();
// It is possible for an extension to be unloaded before it stops loading.
if (!extension)
return;
std::map<std::string, PostReloadAction>::iterator it =
post_reload_actions_.find(extension->id());
if (it == post_reload_actions_.end())
return;

switch (it->second.action_type) {
case LAUNCH:
LaunchPlatformApp(profile_, extension);
break;
case RESTART:
RestartPlatformApp(profile_, extension);
break;
}
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const extensions::UnloadedExtensionInfo* unload_info =
content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
if (!unload_info->extension->is_platform_app())
break;

extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(profile_);
if (WasUnloadedForReload(*unload_info) &&
extension_prefs->IsActive(unload_info->extension->id()) &&
!HasPostReloadAction(unload_info->extension->id())) {
post_reload_actions_[unload_info->extension->id()].action_type = LAUNCH;
}
case LAUNCH_WITH_COMMAND_LINE:
LaunchPlatformAppWithCommandLine(
profile_, extension, it->second.command_line, it->second.current_dir);
break;
}
default:
NOTREACHED();
}

post_reload_actions_.erase(it);
}

void AppLoadService::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (!extension->is_platform_app())
return;

extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(browser_context);
if (WasUnloadedForReload(extension->id(), reason) &&
extension_prefs->IsActive(extension->id()) &&
!HasPostReloadAction(extension->id())) {
post_reload_actions_[extension->id()].action_type = LAUNCH;
}
}

bool AppLoadService::WasUnloadedForReload(
const extensions::UnloadedExtensionInfo& unload_info) {
if (unload_info.reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) {
const extensions::ExtensionId& extension_id,
const extensions::UnloadedExtensionInfo::Reason reason) {
if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) {
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
return (prefs->GetDisableReasons(unload_info.extension->id()) &
Extension::DISABLE_RELOAD) != 0;
return (prefs->GetDisableReasons(extension_id) &
Extension::DISABLE_RELOAD) != 0;
}
return false;
}
Expand Down
13 changes: 11 additions & 2 deletions apps/app_load_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#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;

Expand All @@ -25,7 +26,8 @@ namespace apps {
// Monitors apps being reloaded and performs app specific actions (like launch
// or restart) on them. Also provides an interface to schedule these actions.
class AppLoadService : public KeyedService,
public content::NotificationObserver {
public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
enum PostReloadActionType {
LAUNCH,
Expand Down Expand Up @@ -67,8 +69,15 @@ class AppLoadService : public KeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;

// extensions::ExtensionRegistryObserver.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;

bool WasUnloadedForReload(
const extensions::UnloadedExtensionInfo& unload_info);
const extensions::ExtensionId& extension_id,
const extensions::UnloadedExtensionInfo::Reason reason);
bool HasPostReloadAction(const std::string& extension_id);

// Map of extension id to reload action. Absence from the map implies
Expand Down
6 changes: 4 additions & 2 deletions apps/app_load_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h"

Expand All @@ -28,10 +29,11 @@ AppLoadServiceFactory::AppLoadServiceFactory()
: BrowserContextKeyedServiceFactory(
"AppLoadService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(extensions::AppWindowRegistry::Factory::GetInstance());
DependsOn(extensions::ExtensionPrefsFactory::GetInstance());
DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
DependsOn(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
DependsOn(extensions::ExtensionPrefsFactory::GetInstance());
DependsOn(extensions::AppWindowRegistry::Factory::GetInstance());
}

AppLoadServiceFactory::~AppLoadServiceFactory() {
Expand Down

0 comments on commit d379175

Please sign in to comment.