diff options
author | cylee <cylee@chromium.org> | 2014-11-04 08:39:16 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-04 16:39:38 +0000 |
commit | 988a9bb5eebf30245ab1150d94bca22fc1c9c89e (patch) | |
tree | 57d77c58a0239f9fd87d67d49fe701122540ba2d /apps | |
parent | 84dc546d15b57632feb2ec00a133f6c2935b74a7 (diff) | |
download | chromium_src-988a9bb5eebf30245ab1150d94bca22fc1c9c89e.zip chromium_src-988a9bb5eebf30245ab1150d94bca22fc1c9c89e.tar.gz chromium_src-988a9bb5eebf30245ab1150d94bca22fc1c9c89e.tar.bz2 |
Add a new field "source" in launchData of chrome.app.runtime.onLaunched() to trace launch source.
BUG=chromium:400619
Review URL: https://codereview.chromium.org/657023008
Cr-Commit-Position: refs/heads/master@{#302617}
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_load_service.cc | 19 | ||||
-rw-r--r-- | apps/app_load_service.h | 4 | ||||
-rw-r--r-- | apps/launcher.cc | 40 | ||||
-rw-r--r-- | apps/launcher.h | 12 |
4 files changed, 42 insertions, 33 deletions
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc index 6fff4c4..8f22422 100644 --- a/apps/app_load_service.cc +++ b/apps/app_load_service.cc @@ -28,7 +28,7 @@ using extensions::ExtensionSystem; namespace apps { AppLoadService::PostReloadAction::PostReloadAction() - : action_type(LAUNCH), + : action_type(LAUNCH_FOR_RELOAD), command_line(base::CommandLine::NO_PROGRAM) { } @@ -71,7 +71,7 @@ bool AppLoadService::LoadAndLaunch(const base::FilePath& extension_path, // Schedule the app to be launched once loaded. PostReloadAction& action = post_reload_actions_[extension_id]; - action.action_type = LAUNCH_WITH_COMMAND_LINE; + action.action_type = LAUNCH_FOR_LOAD_AND_LAUNCH; action.command_line = command_line; action.current_dir = current_dir; return true; @@ -98,15 +98,18 @@ void AppLoadService::Observe(int type, return; switch (it->second.action_type) { - case LAUNCH: - LaunchPlatformApp(profile_, extension); + case LAUNCH_FOR_RELOAD: + LaunchPlatformApp(profile_, extension, extensions::SOURCE_RELOAD); break; case RESTART: RestartPlatformApp(profile_, extension); break; - case LAUNCH_WITH_COMMAND_LINE: - LaunchPlatformAppWithCommandLine( - profile_, extension, it->second.command_line, it->second.current_dir); + case LAUNCH_FOR_LOAD_AND_LAUNCH: + LaunchPlatformAppWithCommandLine(profile_, + extension, + it->second.command_line, + it->second.current_dir, + extensions::SOURCE_LOAD_AND_LAUNCH); break; default: NOTREACHED(); @@ -127,7 +130,7 @@ void AppLoadService::OnExtensionUnloaded( if (WasUnloadedForReload(extension->id(), reason) && extension_prefs->IsActive(extension->id()) && !HasPostReloadAction(extension->id())) { - post_reload_actions_[extension->id()].action_type = LAUNCH; + post_reload_actions_[extension->id()].action_type = LAUNCH_FOR_RELOAD; } } diff --git a/apps/app_load_service.h b/apps/app_load_service.h index aa9cc98..bd5d292 100644 --- a/apps/app_load_service.h +++ b/apps/app_load_service.h @@ -30,9 +30,9 @@ class AppLoadService : public KeyedService, public extensions::ExtensionRegistryObserver { public: enum PostReloadActionType { - LAUNCH, + LAUNCH_FOR_RELOAD, RESTART, - LAUNCH_WITH_COMMAND_LINE, + LAUNCH_FOR_LOAD_AND_LAUNCH, }; struct PostReloadAction { diff --git a/apps/launcher.cc b/apps/launcher.cc index aefca4f..f4875aa 100644 --- a/apps/launcher.cc +++ b/apps/launcher.cc @@ -85,14 +85,6 @@ bool DoMakePathAbsolute(const base::FilePath& current_directory, return true; } -// Helper method to launch the platform app |extension| with no data. This -// should be called in the fallback case, where it has been impossible to -// load or obtain file launch data. -void LaunchPlatformAppWithNoData(Profile* profile, const Extension* extension) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - AppRuntimeEventRouter::DispatchOnLaunchedEvent(profile, extension); -} - // Class to handle launching of platform apps to open specific paths. // An instance of this class is created for each launch. The lifetime of these // instances is managed by reference counted pointers. As long as an instance @@ -120,7 +112,7 @@ class PlatformAppPathLauncher void Launch() { DCHECK_CURRENTLY_ON(BrowserThread::UI); if (file_paths_.empty()) { - LaunchPlatformAppWithNoData(profile_, extension_); + LaunchWithNoLaunchData(); return; } @@ -193,7 +185,9 @@ class PlatformAppPathLauncher void LaunchWithNoLaunchData() { // This method is required as an entry point on the UI thread. - LaunchPlatformAppWithNoData(profile_, extension_); + DCHECK_CURRENTLY_ON(BrowserThread::UI); + AppRuntimeEventRouter::DispatchOnLaunchedEvent( + profile_, extension_, extensions::SOURCE_FILE_HANDLER); } void OnMimeTypesCollected(scoped_ptr<std::vector<std::string> > mime_types) { @@ -313,7 +307,8 @@ class PlatformAppPathLauncher void LaunchPlatformAppWithCommandLine(Profile* profile, const Extension* extension, const base::CommandLine& command_line, - const base::FilePath& current_directory) { + const base::FilePath& current_directory, + extensions::AppLaunchSource source) { // An app with "kiosk_only" should not be installed and launched // outside of ChromeOS kiosk mode in the first place. This is a defensive // check in case this scenario does occur. @@ -344,7 +339,7 @@ void LaunchPlatformAppWithCommandLine(Profile* profile, // causes problems on the bots. if (args.empty() || (command_line.HasSwitch(switches::kTestType) && args[0] == about_blank_url)) { - LaunchPlatformAppWithNoData(profile, extension); + AppRuntimeEventRouter::DispatchOnLaunchedEvent(profile, extension, source); return; } @@ -362,12 +357,15 @@ void LaunchPlatformAppWithPath(Profile* profile, launcher->Launch(); } -void LaunchPlatformApp(Profile* profile, const Extension* extension) { - LaunchPlatformAppWithCommandLine(profile, - extension, - base::CommandLine( - base::CommandLine::NO_PROGRAM), - base::FilePath()); +void LaunchPlatformApp(Profile* profile, + const Extension* extension, + extensions::AppLaunchSource source) { + LaunchPlatformAppWithCommandLine( + profile, + extension, + base::CommandLine(base::CommandLine::NO_PROGRAM), + base::FilePath(), + source); } void LaunchPlatformAppWithFileHandler( @@ -399,8 +397,10 @@ void RestartPlatformApp(Profile* profile, const Extension* extension) { ExtensionHasEventListener(extension->id(), app_runtime::OnLaunched::kEventName); - if (listening_to_launch && had_windows) - LaunchPlatformAppWithNoData(profile, extension); + if (listening_to_launch && had_windows) { + AppRuntimeEventRouter::DispatchOnLaunchedEvent( + profile, extension, extensions::SOURCE_RESTART); + } } void LaunchPlatformAppWithUrl(Profile* profile, diff --git a/apps/launcher.h b/apps/launcher.h index eb2d98f..fa6ea15 100644 --- a/apps/launcher.h +++ b/apps/launcher.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#include "extensions/common/constants.h" + class GURL; class Profile; @@ -26,10 +28,12 @@ namespace apps { // the |command_line| fields present. |extension| and |profile| must not be // NULL. An empty |command_line| means there is no launch data. If non-empty, // |current_directory| is used to expand any relative paths on the command line. +// |source| is one of the enumerated values which trace how the app is launched. void LaunchPlatformAppWithCommandLine(Profile* profile, const extensions::Extension* extension, const base::CommandLine& command_line, - const base::FilePath& current_directory); + const base::FilePath& current_directory, + extensions::AppLaunchSource source); // Launches the platform app |extension| by issuing an onLaunched event // with the contents of |file_path| available through the launch data. @@ -37,9 +41,11 @@ void LaunchPlatformAppWithPath(Profile* profile, const extensions::Extension* extension, const base::FilePath& file_path); -// Launches the platform app |extension| with no launch data. +// Launches the platform app |extension|. |source| tells us how the app is +// launched. void LaunchPlatformApp(Profile* profile, - const extensions::Extension* extension); + const extensions::Extension* extension, + extensions::AppLaunchSource source); // Launches the platform app |extension| with |handler_id| and the contents of // |file_paths| available through the launch data. |handler_id| corresponds to |