Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Unified Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 12674028: Report text output and exit code for command-line operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Line endings. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/startup/startup_browser_creator.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc
index 250048b6d00e2b12e26647f2a52ff7c11587b0fc..4e594e840935b27477c136de9545eb8c6f1c303b 100644
--- a/chrome/browser/ui/startup/startup_browser_creator.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc
@@ -36,6 +36,7 @@
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/operation_output.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
@@ -239,6 +240,17 @@ void StartupBrowserCreator::AddFirstRunTab(const GURL& url) {
first_run_tabs_.push_back(url);
}
+bool StartupBrowserCreator::Start(
+ const CommandLine& cmd_line,
+ const base::FilePath& cur_dir,
+ Profile* last_used_profile,
+ const Profiles& last_opened_profiles,
+ scoped_ptr<OperationOutput> operation_output) {
+ return ProcessCmdLineImpl(cmd_line, cur_dir, true, last_used_profile,
+ last_opened_profiles, this,
+ operation_output.Pass());
+}
+
// static
bool StartupBrowserCreator::InSynchronousProfileLaunch() {
return in_synchronous_profile_launch_;
@@ -429,14 +441,24 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
bool process_startup,
Profile* last_used_profile,
const Profiles& last_opened_profiles,
- int* return_code,
- StartupBrowserCreator* browser_creator) {
+ StartupBrowserCreator* browser_creator,
+ scoped_ptr<OperationOutput> operation_output) {
DCHECK(last_used_profile);
if (process_startup) {
if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
content::NavigationController::DisablePromptOnRepost();
}
+ if (command_line.HasSwitch("greetings")) {
+ if (operation_output) {
+ std::string hello_world("hello world!");
+ operation_output->Write(hello_world.c_str(), hello_world.length());
+ OperationOutput::Complete(operation_output.Pass(), 42);
+ }
robertshield 2013/03/28 14:31:48 Is the greetings flag still useful?
+
+ return false;
+ }
+
bool silent_launch = false;
#if defined(ENABLE_AUTOMATION)
@@ -608,9 +630,12 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
// |last_used_profile| is the last used incognito profile. Restoring it will
// create a browser window for the corresponding original profile.
if (last_opened_profiles.empty()) {
+ int return_code = 0;
if (!browser_creator->LaunchBrowser(command_line, last_used_profile,
cur_dir, is_process_startup,
- is_first_run, return_code)) {
+ is_first_run, &return_code)) {
+ if (operation_output)
+ OperationOutput::Complete(operation_output.Pass(), return_code);
return false;
}
} else {
@@ -635,10 +660,14 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
startup_pref.type == SessionStartupPref::DEFAULT &&
!HasPendingUncleanExit(*it))
continue;
+ int return_code = 0;
if (!browser_creator->LaunchBrowser((*it == last_used_profile) ?
command_line : command_line_without_urls, *it, cur_dir,
- is_process_startup, is_first_run, return_code))
+ is_process_startup, is_first_run, &return_code)) {
+ if (operation_output)
+ OperationOutput::Complete(operation_output.Pass(), return_code);
return false;
+ }
// We've launched at least one browser.
is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP;
}
@@ -646,6 +675,10 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
// knows about all profiles to wait for before activating this one.
profile_launch_observer.Get().set_profile_to_activate(last_used_profile);
}
+ if (operation_output) {
+ OperationOutput::Complete(operation_output.Pass(),
+ content::RESULT_CODE_NORMAL_EXIT);
+ }
return true;
}
@@ -673,31 +706,39 @@ bool StartupBrowserCreator::CreateAutomationProvider(
void StartupBrowserCreator::ProcessCommandLineOnProfileCreated(
const CommandLine& command_line,
const base::FilePath& cur_dir,
+ scoped_ptr<OperationOutput> operation_output,
Profile* profile,
Profile::CreateStatus status) {
- if (status == Profile::CREATE_STATUS_INITIALIZED)
+ if (status == Profile::CREATE_STATUS_INITIALIZED) {
ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
- NULL);
+ operation_output.Pass());
+ } else {
+ // Signal failure on operation_output?
+ }
}
// static
void StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
const CommandLine& command_line,
const base::FilePath& cur_dir,
- const base::FilePath& profile_path) {
+ const base::FilePath& profile_path,
+ scoped_ptr<OperationOutput> operation_output) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile = profile_manager->GetProfileByPath(profile_path);
// The profile isn't loaded yet and so needs to be loaded asynchronously.
if (!profile) {
- profile_manager->CreateProfileAsync(profile_path,
- base::Bind(&StartupBrowserCreator::ProcessCommandLineOnProfileCreated,
- command_line, cur_dir), string16(), string16(), false);
+ profile_manager->CreateProfileAsync(
+ profile_path,
+ base::Bind(
+ &StartupBrowserCreator::ProcessCommandLineOnProfileCreated,
+ command_line, cur_dir, base::Passed(operation_output.Pass())),
+ string16(), string16(), false);
return;
}
ProcessCmdLineImpl(command_line, cur_dir, false, profile, Profiles(), NULL,
- NULL);
+ operation_output.Pass());
}
// static

Powered by Google App Engine
This is Rietveld 408576698