OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stdio.h> | |
6 #include <string.h> | |
7 | |
8 #include <algorithm> | |
9 #include <iostream> | |
10 | |
11 #include "base/base_switches.h" | |
12 #include "base/bind.h" | |
13 #include "base/command_line.h" | |
14 #include "base/debug/stack_trace.h" | |
15 #include "base/files/file_util.h" | |
16 #include "base/message_loop/message_loop.h" | |
17 #include "base/path_service.h" | |
18 #include "base/synchronization/waitable_event.h" | |
19 #include "base/threading/platform_thread.h" | |
20 #include "mojo/runner/context.h" | |
21 #include "mojo/runner/switches.h" | |
22 #include "mojo/shell/switches.h" | |
23 | |
24 namespace mojo { | |
25 namespace runner { | |
26 | |
27 int LauncherProcessMain(const GURL& mojo_url, const base::Closure& callback) { | |
28 #if !defined(OFFICIAL_BUILD) | |
29 base::debug::EnableInProcessStackDumping(); | |
30 #endif | |
31 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
32 if (!command_line->HasSwitch(switches::kMojoSingleProcess) && | |
33 !command_line->HasSwitch("gtest_list_tests")) | |
34 command_line->AppendSwitch(switches::kEnableMultiprocess); | |
35 command_line->AppendSwitch("use-new-edk"); | |
36 // http://crbug.com/546644 | |
37 command_line->AppendSwitch(switches::kMojoNoSandbox); | |
38 | |
39 base::PlatformThread::SetName("mojo_runner"); | |
40 | |
41 // We want the shell::Context to outlive the MessageLoop so that pipes are | |
42 // all gracefully closed / error-out before we try to shut the Context down. | |
43 Context shell_context; | |
44 { | |
45 base::MessageLoop message_loop; | |
46 base::FilePath shell_dir; | |
47 PathService::Get(base::DIR_MODULE, &shell_dir); | |
48 if (!shell_context.Init(shell_dir)) | |
49 return 0; | |
50 | |
51 if (mojo_url.is_empty()) { | |
52 message_loop.PostTask( | |
53 FROM_HERE, | |
54 base::Bind(&Context::RunCommandLineApplication, | |
55 base::Unretained(&shell_context), base::Closure())); | |
56 } else { | |
57 message_loop.PostTask(FROM_HERE, | |
58 base::Bind(&mojo::runner::Context::Run, | |
59 base::Unretained(&shell_context), | |
60 mojo_url)); | |
61 } | |
62 message_loop.Run(); | |
63 | |
64 // Must be called before |message_loop| is destroyed. | |
65 shell_context.Shutdown(); | |
66 } | |
67 | |
68 return 0; | |
69 } | |
70 | |
71 } // namespace runner | |
72 } // namespace mojo | |
OLD | NEW |