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