OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "base/at_exit.h" | |
6 #include "base/bind.h" | |
7 #include "base/bind_helpers.h" | |
8 #include "base/command_line.h" | |
9 #include "base/logging.h" | |
10 #include "base/macros.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/run_loop.h" | |
14 #include "base/strings/string_split.h" | |
15 #include "mojo/edk/embedder/embedder.h" | |
16 #include "mojo/edk/embedder/process_delegate.h" | |
17 #include "mojo/edk/embedder/simple_platform_support.h" | |
18 #include "mojo/shell/in_process_native_runner.h" | |
19 #include "mojo/shell/init.h" | |
20 #include "mojo/shell/native_application_support.h" | |
21 #include "url/gurl.h" | |
22 | |
23 namespace mojo { | |
24 namespace shell { | |
25 | |
26 const char kAppArgs[] = "app-args"; | |
27 const char kAppPath[] = "app-path"; | |
28 const char kAppURL[] = "app-url"; | |
29 const char kShellPath[] = "shell-path"; | |
30 | |
31 class Launcher : public embedder::ProcessDelegate { | |
32 public: | |
33 explicit Launcher(const base::CommandLine& command_line) | |
34 : app_path_(command_line.GetSwitchValuePath(kAppPath)), | |
35 app_url_(command_line.GetSwitchValueASCII(kAppURL)), | |
36 loop_(base::MessageLoop::TYPE_IO) { | |
37 // TODO(vtl): I guess this should be SLAVE, not NONE? | |
38 embedder::InitIPCSupport(embedder::ProcessType::NONE, loop_.task_runner(), | |
39 this, loop_.task_runner(), | |
40 embedder::ScopedPlatformHandle()); | |
41 | |
42 base::SplitStringAlongWhitespace(command_line.GetSwitchValueASCII(kAppArgs), | |
43 &app_args_); | |
44 } | |
45 | |
46 ~Launcher() override { | |
47 DCHECK(!application_request_.is_pending()); | |
48 | |
49 embedder::ShutdownIPCSupportOnIOThread(); | |
50 } | |
51 | |
52 bool Connect() { return false; } | |
53 | |
54 bool Register() { | |
55 return application_request_.is_pending(); | |
56 } | |
57 | |
58 void Run() { | |
59 DCHECK(application_request_.is_pending()); | |
60 InProcessNativeRunner service_runner(nullptr); | |
61 base::RunLoop run_loop; | |
62 service_runner.Start(app_path_, NativeApplicationCleanup::DONT_DELETE, | |
63 application_request_.Pass(), run_loop.QuitClosure()); | |
64 run_loop.Run(); | |
65 } | |
66 | |
67 private: | |
68 void OnRegistered(base::RunLoop* run_loop, | |
69 InterfaceRequest<Application> application_request) { | |
70 application_request_ = application_request.Pass(); | |
71 run_loop->Quit(); | |
72 } | |
73 | |
74 // embedder::ProcessDelegate implementation: | |
75 void OnShutdownComplete() override { | |
76 NOTREACHED(); // Not called since we use ShutdownIPCSupportOnIOThread(). | |
77 } | |
78 | |
79 const base::FilePath app_path_; | |
80 const GURL app_url_; | |
81 std::vector<std::string> app_args_; | |
82 base::MessageLoop loop_; | |
83 InterfaceRequest<Application> application_request_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(Launcher); | |
86 }; | |
87 | |
88 } // namespace shell | |
89 } // namespace mojo | |
90 | |
91 int main(int argc, char** argv) { | |
92 base::AtExitManager at_exit; | |
93 mojo::embedder::Init( | |
94 make_scoped_ptr(new mojo::embedder::SimplePlatformSupport())); | |
95 | |
96 base::CommandLine::Init(argc, argv); | |
97 const base::CommandLine* command_line = | |
98 base::CommandLine::ForCurrentProcess(); | |
99 mojo::shell::InitializeLogging(); | |
100 | |
101 mojo::shell::Launcher launcher(*command_line); | |
102 if (!launcher.Connect()) { | |
103 LOG(ERROR) << "Failed to connect on socket " | |
104 << command_line->GetSwitchValueASCII(mojo::shell::kShellPath); | |
105 return 1; | |
106 } | |
107 | |
108 if (!launcher.Register()) { | |
109 LOG(ERROR) << "Error registering " | |
110 << command_line->GetSwitchValueASCII(mojo::shell::kAppURL); | |
111 return 1; | |
112 } | |
113 | |
114 launcher.Run(); | |
115 return 0; | |
116 } | |
OLD | NEW |