diff options
author | zork <zork@chromium.org> | 2014-11-25 12:31:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-25 20:32:20 +0000 |
commit | 3ea6ffc52b1c0771295e0ab5949ba00d2335daea (patch) | |
tree | bb9d0ee976657b221808261d825c877e8f6891a2 | |
parent | 81d760e7ce27957a41f4685a37c1d0c3d7c6e5e8 (diff) | |
download | chromium_src-3ea6ffc52b1c0771295e0ab5949ba00d2335daea.zip chromium_src-3ea6ffc52b1c0771295e0ab5949ba00d2335daea.tar.gz chromium_src-3ea6ffc52b1c0771295e0ab5949ba00d2335daea.tar.bz2 |
Add load-app flag support to chrome
BUG=432359
Review URL: https://codereview.chromium.org/718133005
Cr-Commit-Position: refs/heads/master@{#305688}
-rw-r--r-- | apps/app_load_service.cc | 8 | ||||
-rw-r--r-- | apps/app_load_service.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/startup/startup_browser_creator.cc | 53 | ||||
-rw-r--r-- | chrome/browser/ui/startup/startup_browser_creator.h | 10 |
4 files changed, 74 insertions, 1 deletions
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc index 8f22422..c4d308e 100644 --- a/apps/app_load_service.cc +++ b/apps/app_load_service.cc @@ -77,6 +77,14 @@ bool AppLoadService::LoadAndLaunch(const base::FilePath& extension_path, return true; } +bool AppLoadService::Load(const base::FilePath& extension_path) { + ExtensionService* extension_service = + ExtensionSystem::Get(profile_)->extension_service(); + std::string extension_id; + return extensions::UnpackedInstaller::Create(extension_service)-> + LoadFromCommandLine(base::FilePath(extension_path), &extension_id); +} + // static AppLoadService* AppLoadService::Get(Profile* profile) { return apps::AppLoadServiceFactory::GetForProfile(profile); diff --git a/apps/app_load_service.h b/apps/app_load_service.h index bd5d292..1b6fbab 100644 --- a/apps/app_load_service.h +++ b/apps/app_load_service.h @@ -61,6 +61,10 @@ class AppLoadService : public KeyedService, const base::CommandLine& command_line, const base::FilePath& current_dir); + // Loads (or reloads) the app with |extension_path|. Returns true if loading + // the app has begun successfully. + bool Load(const base::FilePath& extension_path); + static AppLoadService* Get(Profile* profile); private: diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc index ca029f9..a2b1bde 100644 --- a/chrome/browser/ui/startup/startup_browser_creator.cc +++ b/chrome/browser/ui/startup/startup_browser_creator.cc @@ -24,6 +24,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "base/strings/string_tokenizer.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "chrome/browser/app_mode/app_mode_utils.h" @@ -63,6 +64,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/navigation_controller.h" +#include "extensions/common/switches.h" #include "net/base/net_util.h" #if defined(USE_ASH) @@ -609,7 +611,23 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( if (silent_launch) return true; - VLOG(2) << "ProcessCmdLineImpl: PLACE 4"; + VLOG(2) << "ProcessCmdLineImpl: PLACE 4.A"; + if (command_line.HasSwitch(extensions::switches::kLoadApps) && + !IncognitoModePrefs::ShouldLaunchIncognito( + command_line, last_used_profile->GetPrefs())) { + if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) + return false; + + // Return early here to avoid opening a browser window. + // The exception is when there are no browser windows, since we don't want + // chrome to shut down. + // TODO(jackhou): Do this properly once keep-alive is handled by the + // background page of apps. Tracked at http://crbug.com/175381 + if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) + return true; + } + + VLOG(2) << "ProcessCmdLineImpl: PLACE 4.B"; // Check for --load-and-launch-app. if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && !IncognitoModePrefs::ShouldLaunchIncognito( @@ -756,6 +774,39 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( } // static +bool StartupBrowserCreator::ProcessLoadApps(const CommandLine& command_line, + const base::FilePath& cur_dir, + Profile* profile) { + CommandLine::StringType path_list = + command_line.GetSwitchValueNative(extensions::switches::kLoadApps); + + base::StringTokenizerT<CommandLine::StringType, + CommandLine::StringType::const_iterator> + tokenizer(path_list, FILE_PATH_LITERAL(",")); + + if (!tokenizer.GetNext()) + return false; + + base::FilePath app_absolute_dir = + base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token())); + if (!apps::AppLoadService::Get(profile)->LoadAndLaunch( + app_absolute_dir, command_line, cur_dir)) { + return false; + } + + while (tokenizer.GetNext()) { + app_absolute_dir = + base::MakeAbsoluteFilePath(base::FilePath(tokenizer.token())); + + if (!apps::AppLoadService::Get(profile)->Load(app_absolute_dir)) { + return false; + } + } + + return true; +} + +// static void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( const CommandLine& command_line, const base::FilePath& cur_dir, diff --git a/chrome/browser/ui/startup/startup_browser_creator.h b/chrome/browser/ui/startup/startup_browser_creator.h index 476dc01..d5d7a9d 100644 --- a/chrome/browser/ui/startup/startup_browser_creator.h +++ b/chrome/browser/ui/startup/startup_browser_creator.h @@ -131,6 +131,16 @@ class StartupBrowserCreator { int* return_code, StartupBrowserCreator* browser_creator); + // This function performs command-line handling and is invoked only after + // start up (for example when we get a start request for another process). + // |command_line| holds the command line being processed. + // |cur_dir| is the current working directory that the original process was + // invoked from. + // |profile| is the profile the apps will be launched in. + static bool ProcessLoadApps(const base::CommandLine& command_line, + const base::FilePath& cur_dir, + Profile* profile); + // Callback after a profile has been created. static void ProcessCommandLineOnProfileCreated( const base::CommandLine& command_line, |