summaryrefslogtreecommitdiffstats
path: root/apps/app_load_service.cc
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-31 09:37:53 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-31 09:37:53 +0000
commit2a69b940ba0ce6563ee2de7f08c08f740a79a247 (patch)
tree15d25480404627ce37c51b80b87b319058353e83 /apps/app_load_service.cc
parentb46e1c1d96e9e2e82efaba9dae3acd95559da57d (diff)
downloadchromium_src-2a69b940ba0ce6563ee2de7f08c08f740a79a247.zip
chromium_src-2a69b940ba0ce6563ee2de7f08c08f740a79a247.tar.gz
chromium_src-2a69b940ba0ce6563ee2de7f08c08f740a79a247.tar.bz2
Move application restart and relaunch code out of ExtensionService.
This apps specific code now lives in AppLoadService in the apps/ component. BUG=159366, 159265, 175381 Review URL: https://chromiumcodereview.appspot.com/15947007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203382 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps/app_load_service.cc')
-rw-r--r--apps/app_load_service.cc110
1 files changed, 110 insertions, 0 deletions
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc
new file mode 100644
index 0000000..1d78554
--- /dev/null
+++ b/apps/app_load_service.cc
@@ -0,0 +1,110 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_load_service.h"
+
+#include "apps/app_load_service_factory.h"
+#include "chrome/browser/extensions/extension_prefs.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/platform_app_launcher.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
+
+using extensions::Extension;
+using extensions::ExtensionPrefs;
+
+namespace {
+
+enum PostReloadAction {
+ RELOAD_ACTION_LAUNCH,
+ RELOAD_ACTION_RESTART,
+};
+
+} // namespace
+
+namespace apps {
+
+AppLoadService::AppLoadService(Profile* profile)
+ : profile_(profile) {
+ registrar_.Add(
+ this, chrome::NOTIFICATION_EXTENSION_LOADED,
+ content::NotificationService::AllSources());
+ registrar_.Add(
+ this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::NotificationService::AllSources());
+}
+
+AppLoadService::~AppLoadService() {}
+
+void AppLoadService::RestartApplication(const std::string& extension_id) {
+ reload_actions_[extension_id] = RELOAD_ACTION_RESTART;
+ ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->
+ extension_service();
+ DCHECK(service);
+ service->ReloadExtension(extension_id);
+}
+
+void AppLoadService::ScheduleLaunchOnLoad(const std::string& extension_id) {
+ reload_actions_[extension_id] = RELOAD_ACTION_LAUNCH;
+}
+
+// static
+AppLoadService* AppLoadService::Get(Profile* profile) {
+ return apps::AppLoadServiceFactory::GetForProfile(profile);
+}
+
+void AppLoadService::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_LOADED: {
+ const Extension* extension = content::Details<Extension>(details).ptr();
+ std::map<std::string, int>::iterator it = reload_actions_.find(
+ extension->id());
+ if (it == reload_actions_.end())
+ break;
+
+ switch (it->second) {
+ case RELOAD_ACTION_LAUNCH:
+ extensions::LaunchPlatformApp(profile_, extension);
+ break;
+ case RELOAD_ACTION_RESTART:
+ extensions::RestartPlatformApp(profile_, extension);
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ reload_actions_.erase(it);
+ break;
+ }
+ case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
+ const extensions::UnloadedExtensionInfo* unload_info =
+ content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
+ if (!unload_info->extension->is_platform_app())
+ break;
+
+ if (unload_info->reason == extension_misc::UNLOAD_REASON_DISABLE) {
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
+ if ((prefs->GetDisableReasons(unload_info->extension->id()) &
+ Extension::DISABLE_RELOAD) &&
+ !extensions::ShellWindowRegistry::Get(profile_)->
+ GetShellWindowsForApp(unload_info->extension->id()).empty()) {
+ reload_actions_[unload_info->extension->id()] = RELOAD_ACTION_LAUNCH;
+ }
+ }
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
+
+} // namespace apps