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

Unified Diff: chrome/browser/chrome_browser_main.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/chrome_browser_main.cc
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index a85e75694b86ef275f86f60b978e0b951d7e59e6..9d8db819b1930116bc459e61905a5850613deab2 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -8,6 +8,7 @@
#include <gtk/gtk.h>
#endif
+#include <limits.h>
gab 2013/03/28 03:06:06 C-headers come after C++ headers and are usually i
erikwright (departed) 2013/04/18 17:43:04 You so crazy :) C first. http://google-styleguid
gab 2013/04/19 14:37:47 You know who I learnt to code-review from ;)!
#include <string>
#include <vector>
@@ -18,6 +19,7 @@
#include "base/debug/trace_event.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
@@ -72,6 +74,7 @@
#include "chrome/browser/net/crl_set_fetcher.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
+#include "chrome/browser/operation_output.h"
#include "chrome/browser/page_cycler/page_cycler.h"
#include "chrome/browser/performance_monitor/performance_monitor.h"
#include "chrome/browser/performance_monitor/startup_timer.h"
@@ -495,9 +498,10 @@ void RegisterComponentsForUpdate(const CommandLine& command_line) {
}
#if !defined(OS_ANDROID)
-bool ProcessSingletonNotificationCallback(
+bool ProcessSingletonOperationCallback(
const CommandLine& command_line,
- const base::FilePath& current_directory) {
+ const base::FilePath& current_directory,
+ scoped_ptr<OperationOutput> operation_output) {
// Drop the request if the browser process is already in shutdown path.
if (!g_browser_process || g_browser_process->IsShuttingDown())
return false;
@@ -531,7 +535,10 @@ bool ProcessSingletonNotificationCallback(
GetStartupProfilePath(user_data_dir, command_line);
StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
- command_line, current_directory, startup_profile_dir);
+ command_line,
+ current_directory,
+ startup_profile_dir,
+ operation_output.Pass());
return true;
}
#endif
@@ -612,7 +619,7 @@ ChromeBrowserMainParts::ChromeBrowserMainParts(
browser_field_trials_(parameters.command_line),
#if !defined(OS_ANDROID)
process_singleton_lock_(
- base::Bind(&ProcessSingletonNotificationCallback)),
+ base::Bind(&ProcessSingletonOperationCallback)),
modal_dialog_lock_(process_singleton_lock_.AsNotificationCallback()),
#endif
record_search_engine_(false),
@@ -1079,6 +1086,53 @@ void ChromeBrowserMainParts::PostBrowserStart() {
#endif
}
+class CaptureOperationOutput {
+ public:
+ CaptureOperationOutput()
+ : exit_code_(new base::RefCountedData<int>(INT_MAX)) {}
+
+ int exit_code() { return exit_code_->data; }
+
+ scoped_ptr<OperationOutput> Wrap(scoped_ptr<OperationOutput> wrapped) {
+ return scoped_ptr<OperationOutput>(new Wrapper(wrapped.Pass(), exit_code_));
+ }
+
+ private:
+ class Wrapper : public OperationOutput {
+ public:
+ Wrapper(scoped_ptr<OperationOutput> wrapped,
+ const scoped_refptr<base::RefCountedData<int> >& exit_code)
+ : wrapped_(wrapped.Pass()),
+ exit_code_(exit_code) {
+ }
+
+ // OperationOutput implementation.
+ virtual bool Write(const char* data, unsigned int length) OVERRIDE {
+ if (wrapped_)
+ return wrapped_->Write(data, length);
+ return true;
+ }
+
+ private:
+ virtual bool SetExitCode(unsigned int exit_code) OVERRIDE {
+ bool success = true;
+ if (wrapped_)
+ success = OperationOutput::Complete(wrapped_.Pass(), exit_code);
+ if (success)
+ exit_code_->data = exit_code;
+ return success;
+ }
+ scoped_ptr<OperationOutput> wrapped_;
+ scoped_refptr<base::RefCountedData<int> > exit_code_;
+
+ DISALLOW_COPY_AND_ASSIGN(Wrapper);
+ };
+
+ scoped_refptr<base::RefCountedData<int> > exit_code_;
+
+ DISALLOW_COPY_AND_ASSIGN(CaptureOperationOutput);
+};
+
#if !defined(OS_ANDROID)
void ChromeBrowserMainParts::RunPageCycler() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
@@ -1542,6 +1596,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// http://crbug.com/105065.
browser_process_->notification_ui_manager();
+ CaptureOperationOutput capture_output;
+
#if !defined(OS_ANDROID)
// Most general initialization is behind us, but opening a
// tab and/or session restore and such is still to be done.
@@ -1549,7 +1605,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// We are in regular browser boot sequence. Open initial tabs and enter the
// main message loop.
- int result_code;
+
#if defined(OS_CHROMEOS)
// On ChromeOS multiple profiles doesn't apply, and will break if we load
// them this early as the cryptohome hasn't yet been mounted (which happens
@@ -1563,8 +1619,11 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
RegisterComponentsForUpdate(parsed_command_line());
- if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
- profile_, last_opened_profiles, &result_code)) {
+ if (browser_creator_->Start(
+ parsed_command_line(), base::FilePath(),
+ profile_, last_opened_profiles,
+ capture_output.Wrap(
+ OperationOutput::Create(parsed_command_line())))) {
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
// Initialize autoupdate timer. Timer callback costs basically nothing
// when browser is not in persistent mode, so it's OK to let it ride on
@@ -1640,7 +1699,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
run_message_loop_ = false;
}
- return result_code_;
+ return capture_output.exit_code();
}
bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {

Powered by Google App Engine
This is Rietveld 408576698