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

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: Forgotten review responses. Created 7 years, 8 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
« no previous file with comments | « apps/apps.gypi ('k') | chrome/browser/chrome_process_singleton.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_browser_main.cc
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 3bf2352cc97d0cfef273d1420c3377cf74b01627..2e1efe936b6d182aa3498f2937a0c2e5428319b4 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>
#include <string>
#include <vector>
@@ -17,6 +18,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"
@@ -71,6 +73,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"
@@ -415,9 +418,10 @@ void RegisterComponentsForUpdate(const CommandLine& command_line) {
cus->Start();
}
-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;
@@ -451,7 +455,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;
}
@@ -749,7 +756,7 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
// Android's first run is done in Java instead of native.
#if !defined(OS_ANDROID)
process_singleton_.reset(new ChromeProcessSingleton(
- user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback)));
+ user_data_dir_, base::Bind(&ProcessSingletonOperationCallback)));
bool force_first_run =
parsed_command_line().HasSwitch(switches::kForceFirstRun);
@@ -1003,6 +1010,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();
@@ -1453,6 +1507,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.
@@ -1460,7 +1516,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
@@ -1474,8 +1530,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
@@ -1549,7 +1608,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
run_message_loop_ = false;
}
- return result_code_;
+ return capture_output.exit_code();
}
bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
« no previous file with comments | « apps/apps.gypi ('k') | chrome/browser/chrome_process_singleton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698