| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iostream> | 9 #include <iostream> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "shell/child_process.h" | 19 #include "shell/child_main.h" |
| 20 #include "shell/command_line_util.h" | 20 #include "shell/command_line_util.h" |
| 21 #include "shell/context.h" | 21 #include "shell/context.h" |
| 22 #include "shell/init.h" | 22 #include "shell/init.h" |
| 23 #include "shell/switches.h" | 23 #include "shell/switches.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 void Usage() { | 27 void Usage() { |
| 28 std::cerr << "Launch Mojo applications.\n"; | 28 std::cerr << "Launch Mojo applications.\n"; |
| 29 std::cerr | 29 std::cerr |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 int main(int argc, char** argv) { | 106 int main(int argc, char** argv) { |
| 107 base::AtExitManager at_exit; | 107 base::AtExitManager at_exit; |
| 108 base::CommandLine::Init(argc, argv); | 108 base::CommandLine::Init(argc, argv); |
| 109 | 109 |
| 110 mojo::shell::InitializeLogging(); | 110 mojo::shell::InitializeLogging(); |
| 111 | 111 |
| 112 const base::CommandLine& command_line = |
| 113 *base::CommandLine::ForCurrentProcess(); |
| 114 |
| 112 // TODO(vtl): Unify parent and child process cases to the extent possible. | 115 // TODO(vtl): Unify parent and child process cases to the extent possible. |
| 113 if (scoped_ptr<mojo::shell::ChildProcess> child_process = | 116 int exit_code = 0; |
| 114 mojo::shell::ChildProcess::Create( | 117 if (command_line.HasSwitch(switches::kChildProcess)) { |
| 115 *base::CommandLine::ForCurrentProcess())) { | 118 exit_code = mojo::shell::ChildMain(); |
| 116 child_process->Main(); | |
| 117 } else { | 119 } else { |
| 118 // Only check the command line for the main process. | 120 // Only check the command line for the main process. |
| 119 const base::CommandLine& command_line = | |
| 120 *base::CommandLine::ForCurrentProcess(); | |
| 121 | |
| 122 const std::set<std::string> all_switches = switches::GetAllSwitches(); | 121 const std::set<std::string> all_switches = switches::GetAllSwitches(); |
| 123 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); | 122 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); |
| 124 bool found_unknown_switch = false; | 123 bool found_unknown_switch = false; |
| 125 for (const auto& s : switches) { | 124 for (const auto& s : switches) { |
| 126 if (all_switches.find(s.first) == all_switches.end()) { | 125 if (all_switches.find(s.first) == all_switches.end()) { |
| 127 std::cerr << "unknown switch: " << s.first << std::endl; | 126 std::cerr << "unknown switch: " << s.first << std::endl; |
| 128 found_unknown_switch = true; | 127 found_unknown_switch = true; |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 | 130 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); | 173 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); |
| 175 message_loop.Run(); | 174 message_loop.Run(); |
| 176 | 175 |
| 177 // Must be called before |message_loop| is destroyed. | 176 // Must be called before |message_loop| is destroyed. |
| 178 shell_context.Shutdown(); | 177 shell_context.Shutdown(); |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 if (g_tracing) | 181 if (g_tracing) |
| 183 StopTracingAndFlushToDisk(); | 182 StopTracingAndFlushToDisk(); |
| 184 return 0; | 183 return exit_code; |
| 185 } | 184 } |
| OLD | NEW |