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/base_switches.h" | 11 #include "base/base_switches.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
18 #include "base/trace_event/trace_event.h" | |
19 #include "components/tracing/trace_config_file.h" | |
20 #include "mojo/runner/context.h" | 18 #include "mojo/runner/context.h" |
21 #include "mojo/runner/switches.h" | 19 #include "mojo/runner/switches.h" |
22 #include "mojo/shell/switches.h" | 20 #include "mojo/shell/switches.h" |
23 | 21 |
24 namespace mojo { | 22 namespace mojo { |
25 namespace runner { | 23 namespace runner { |
26 | 24 |
27 int LauncherProcessMain(int argc, char** argv) { | 25 int LauncherProcessMain(const GURL& mojo_url, const base::Closure& callback) { |
28 mojo::runner::Tracer tracer; | |
29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 26 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
30 if (!command_line->HasSwitch(switches::kMojoSingleProcess) && | 27 if (!command_line->HasSwitch(switches::kMojoSingleProcess) && |
31 !command_line->HasSwitch("gtest_list_tests")) | 28 !command_line->HasSwitch("gtest_list_tests")) |
32 command_line->AppendSwitch(switches::kEnableMultiprocess); | 29 command_line->AppendSwitch(switches::kEnableMultiprocess); |
33 command_line->AppendSwitch("use-new-edk"); | 30 command_line->AppendSwitch("use-new-edk"); |
34 // http://crbug.com/546644 | 31 // http://crbug.com/546644 |
35 command_line->AppendSwitch(switches::kMojoNoSandbox); | 32 command_line->AppendSwitch(switches::kMojoNoSandbox); |
36 | 33 |
37 // We want the shell::Context to outlive the MessageLoop so that pipes are | 34 // We want the shell::Context to outlive the MessageLoop so that pipes are |
38 // all gracefully closed / error-out before we try to shut the Context down. | 35 // all gracefully closed / error-out before we try to shut the Context down. |
39 Context shell_context; | 36 Context shell_context; |
40 { | 37 { |
41 base::MessageLoop message_loop; | 38 base::MessageLoop message_loop; |
42 base::FilePath shell_dir; | 39 base::FilePath shell_dir; |
43 PathService::Get(base::DIR_MODULE, &shell_dir); | 40 PathService::Get(base::DIR_MODULE, &shell_dir); |
44 if (!shell_context.Init(shell_dir)) { | 41 if (!shell_context.Init(shell_dir)) |
45 return 0; | 42 return 0; |
| 43 |
| 44 if (mojo_url.is_empty()) { |
| 45 message_loop.PostTask( |
| 46 FROM_HERE, |
| 47 base::Bind(&Context::RunCommandLineApplication, |
| 48 base::Unretained(&shell_context), base::Closure())); |
| 49 } else { |
| 50 message_loop.PostTask(FROM_HERE, |
| 51 base::Bind(&mojo::runner::Context::Run, |
| 52 base::Unretained(&shell_context), |
| 53 mojo_url)); |
46 } | 54 } |
47 | |
48 message_loop.PostTask( | |
49 FROM_HERE, | |
50 base::Bind(&Context::RunCommandLineApplication, | |
51 base::Unretained(&shell_context), base::Closure())); | |
52 message_loop.Run(); | 55 message_loop.Run(); |
53 | 56 |
54 // Must be called before |message_loop| is destroyed. | 57 // Must be called before |message_loop| is destroyed. |
55 shell_context.Shutdown(); | 58 shell_context.Shutdown(); |
56 } | 59 } |
57 | 60 |
58 return 0; | 61 return 0; |
59 } | 62 } |
60 | 63 |
61 } // namespace runner | 64 } // namespace runner |
62 } // namespace mojo | 65 } // namespace mojo |
OLD | NEW |