Index: mojo/shell/desktop/launcher_process.cc |
diff --git a/mojo/shell/desktop/main.cc b/mojo/shell/desktop/launcher_process.cc |
similarity index 54% |
copy from mojo/shell/desktop/main.cc |
copy to mojo/shell/desktop/launcher_process.cc |
index 92149858e7e8e244f58570d050cbf9605336d1dc..f6bb6ded053ce0c9a4185c396cd962e1bb0fdba9 100644 |
--- a/mojo/shell/desktop/main.cc |
+++ b/mojo/shell/desktop/launcher_process.cc |
@@ -8,7 +8,6 @@ |
#include <algorithm> |
#include <iostream> |
-#include "base/at_exit.h" |
#include "base/base_switches.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
@@ -16,12 +15,12 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/trace_event/trace_event.h" |
-#include "mojo/shell/child_process.h" |
#include "mojo/shell/command_line_util.h" |
#include "mojo/shell/context.h" |
-#include "mojo/shell/init.h" |
#include "mojo/shell/switches.h" |
+namespace mojo { |
+namespace shell { |
namespace { |
void Usage() { |
@@ -30,7 +29,6 @@ void Usage() { |
<< "Usage: mojo_shell" |
<< " [--" << switches::kArgsFor << "=<mojo-app>]" |
<< " [--" << switches::kContentHandlers << "=<handlers>]" |
- << " [--" << switches::kEnableExternalApplications << "]" |
<< " [--" << switches::kDisableCache << "]" |
<< " [--" << switches::kEnableMultiprocess << "]" |
<< " [--" << switches::kOrigin << "=<url-lib-path>]" |
@@ -103,83 +101,70 @@ void StopTracingAndFlushToDisk() { |
} // namespace |
-int main(int argc, char** argv) { |
- base::AtExitManager at_exit; |
- base::CommandLine::Init(argc, argv); |
- |
- mojo::shell::InitializeLogging(); |
- |
- // TODO(vtl): Unify parent and child process cases to the extent possible. |
- if (scoped_ptr<mojo::shell::ChildProcess> child_process = |
- mojo::shell::ChildProcess::Create( |
- *base::CommandLine::ForCurrentProcess())) { |
- child_process->Main(); |
- } else { |
- // Only check the command line for the main process. |
- const base::CommandLine& command_line = |
- *base::CommandLine::ForCurrentProcess(); |
- |
- const std::set<std::string> all_switches = switches::GetAllSwitches(); |
- const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); |
- bool found_unknown_switch = false; |
- for (const auto& s : switches) { |
- if (all_switches.find(s.first) == all_switches.end()) { |
- std::cerr << "unknown switch: " << s.first << std::endl; |
- found_unknown_switch = true; |
- } |
+int LauncherProcessMain(int argc, char** argv) { |
+ const base::CommandLine& command_line = |
+ *base::CommandLine::ForCurrentProcess(); |
+ |
+ const std::set<std::string> all_switches = switches::GetAllSwitches(); |
+ const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); |
+ bool found_unknown_switch = false; |
+ for (const auto& s : switches) { |
+ if (all_switches.find(s.first) == all_switches.end()) { |
+ std::cerr << "unknown switch: " << s.first << std::endl; |
+ found_unknown_switch = true; |
} |
+ } |
+ |
+ if (found_unknown_switch || command_line.HasSwitch(switches::kHelp) || |
+ command_line.GetArgs().empty()) { |
+ Usage(); |
+ return 0; |
+ } |
+ |
+ if (command_line.HasSwitch(switches::kTraceStartup)) { |
+ g_tracing = true; |
+ base::trace_event::CategoryFilter category_filter( |
+ command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
+ base::trace_event::TraceLog::GetInstance()->SetEnabled( |
+ category_filter, base::trace_event::TraceLog::RECORDING_MODE, |
+ base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); |
+ } |
- if (found_unknown_switch || |
- (!command_line.HasSwitch(switches::kEnableExternalApplications) && |
- (command_line.HasSwitch(switches::kHelp) || |
- command_line.GetArgs().empty()))) { |
+ // We want the shell::Context to outlive the MessageLoop so that pipes are |
+ // all gracefully closed / error-out before we try to shut the Context down. |
+ mojo::shell::Context shell_context; |
+ { |
+ base::MessageLoop message_loop; |
+ if (!shell_context.Init()) { |
Usage(); |
return 0; |
} |
- |
- if (command_line.HasSwitch(switches::kTraceStartup)) { |
- g_tracing = true; |
- base::trace_event::CategoryFilter category_filter( |
- command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
- base::trace_event::TraceLog::GetInstance()->SetEnabled( |
- category_filter, base::trace_event::TraceLog::RECORDING_MODE, |
- base::trace_event::TraceOptions( |
- base::trace_event::RECORD_UNTIL_FULL)); |
+ if (g_tracing) { |
+ message_loop.PostDelayedTask(FROM_HERE, |
+ base::Bind(StopTracingAndFlushToDisk), |
+ base::TimeDelta::FromSeconds(5)); |
} |
- // We want the shell::Context to outlive the MessageLoop so that pipes are |
- // all gracefully closed / error-out before we try to shut the Context down. |
- mojo::shell::Context shell_context; |
- { |
- base::MessageLoop message_loop; |
- if (!shell_context.Init()) { |
- Usage(); |
- return 0; |
- } |
- if (g_tracing) { |
- message_loop.PostDelayedTask(FROM_HERE, |
- base::Bind(StopTracingAndFlushToDisk), |
- base::TimeDelta::FromSeconds(5)); |
- } |
- |
- // The mojo_shell --args-for command-line switch is handled specially |
- // because it can appear more than once. The base::CommandLine class |
- // collapses multiple occurrences of the same switch. |
- for (int i = 1; i < argc; i++) { |
- ApplyApplicationArgs(&shell_context, argv[i]); |
- } |
- |
- message_loop.PostTask( |
- FROM_HERE, |
- base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); |
- message_loop.Run(); |
- |
- // Must be called before |message_loop| is destroyed. |
- shell_context.Shutdown(); |
+ // The mojo_shell --args-for command-line switch is handled specially |
+ // because it can appear more than once. The base::CommandLine class |
+ // collapses multiple occurrences of the same switch. |
+ for (int i = 1; i < argc; i++) { |
+ ApplyApplicationArgs(&shell_context, argv[i]); |
} |
+ |
+ message_loop.PostTask( |
+ FROM_HERE, |
+ base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); |
+ message_loop.Run(); |
+ |
+ // Must be called before |message_loop| is destroyed. |
+ shell_context.Shutdown(); |
} |
if (g_tracing) |
StopTracingAndFlushToDisk(); |
return 0; |
} |
+ |
+} // namespace shell |
+} // namespace mojo |