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 "mojo/shell/app_child_process.h" | 5 #include "mojo/shell/app_child_process.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 }; | 152 }; |
153 | 153 |
154 // AppChildControllerImpl ------------------------------------------------------ | 154 // AppChildControllerImpl ------------------------------------------------------ |
155 | 155 |
156 class AppChildControllerImpl : public InterfaceImpl<AppChildController> { | 156 class AppChildControllerImpl : public InterfaceImpl<AppChildController> { |
157 public: | 157 public: |
158 virtual ~AppChildControllerImpl() { | 158 virtual ~AppChildControllerImpl() { |
159 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
160 | 160 |
161 // TODO(vtl): Pass in the result from |MainMain()|. | 161 // TODO(vtl): Pass in the result from |MainMain()|. |
162 if (controller_client_) | 162 client()->AppCompleted(MOJO_RESULT_UNIMPLEMENTED); |
163 controller_client_->AppCompleted(MOJO_RESULT_UNIMPLEMENTED); | |
164 } | 163 } |
165 | 164 |
166 // To be executed on the controller thread. Creates the |AppChildController|, | 165 // To be executed on the controller thread. Creates the |AppChildController|, |
167 // etc. | 166 // etc. |
168 static void Init( | 167 static void Init( |
169 AppContext* app_context, | 168 AppContext* app_context, |
170 embedder::ScopedPlatformHandle platform_channel, | 169 embedder::ScopedPlatformHandle platform_channel, |
171 const Blocker::Unblocker& unblocker) { | 170 const Blocker::Unblocker& unblocker) { |
172 DCHECK(app_context); | 171 DCHECK(app_context); |
173 DCHECK(platform_channel.is_valid()); | 172 DCHECK(platform_channel.is_valid()); |
(...skipping 13 matching lines...) Expand all Loading... |
187 BindToPipe(impl.get(), host_message_pipe.Pass()); | 186 BindToPipe(impl.get(), host_message_pipe.Pass()); |
188 | 187 |
189 app_context->set_controller(impl.Pass()); | 188 app_context->set_controller(impl.Pass()); |
190 } | 189 } |
191 | 190 |
192 virtual void OnConnectionError() OVERRIDE { | 191 virtual void OnConnectionError() OVERRIDE { |
193 // TODO(darin): How should we handle a connection error here? | 192 // TODO(darin): How should we handle a connection error here? |
194 } | 193 } |
195 | 194 |
196 // |AppChildController| methods: | 195 // |AppChildController| methods: |
197 | |
198 virtual void SetClient(AppChildControllerClient* client) OVERRIDE { | |
199 controller_client_ = client; | |
200 } | |
201 | |
202 virtual void StartApp(const String& app_path, | 196 virtual void StartApp(const String& app_path, |
203 ScopedMessagePipeHandle service) OVERRIDE { | 197 ScopedMessagePipeHandle service) OVERRIDE { |
204 DVLOG(2) << "AppChildControllerImpl::StartApp(" | 198 DVLOG(2) << "AppChildControllerImpl::StartApp(" |
205 << app_path.To<std::string>() << ", ...)"; | 199 << app_path.To<std::string>() << ", ...)"; |
206 DCHECK(thread_checker_.CalledOnValidThread()); | 200 DCHECK(thread_checker_.CalledOnValidThread()); |
207 | 201 |
208 // TODO(darin): Add TypeConverter for FilePath <-> mojo::String. | 202 // TODO(darin): Add TypeConverter for FilePath <-> mojo::String. |
209 unblocker_.Unblock(base::Bind(&AppChildControllerImpl::StartAppOnMainThread, | 203 unblocker_.Unblock(base::Bind(&AppChildControllerImpl::StartAppOnMainThread, |
210 base::FilePath::FromUTF8Unsafe( | 204 base::FilePath::FromUTF8Unsafe( |
211 app_path.To<std::string>()), | 205 app_path.To<std::string>()), |
212 base::Passed(&service))); | 206 base::Passed(&service))); |
213 } | 207 } |
214 | 208 |
215 private: | 209 private: |
216 AppChildControllerImpl(AppContext* app_context, | 210 AppChildControllerImpl(AppContext* app_context, |
217 const Blocker::Unblocker& unblocker) | 211 const Blocker::Unblocker& unblocker) |
218 : app_context_(app_context), | 212 : app_context_(app_context), |
219 unblocker_(unblocker), | 213 unblocker_(unblocker), |
220 controller_client_(NULL), | |
221 channel_info_(NULL) { | 214 channel_info_(NULL) { |
222 } | 215 } |
223 | 216 |
224 // Callback for |embedder::CreateChannel()|. | 217 // Callback for |embedder::CreateChannel()|. |
225 void DidCreateChannel(embedder::ChannelInfo* channel_info) { | 218 void DidCreateChannel(embedder::ChannelInfo* channel_info) { |
226 DVLOG(2) << "AppChildControllerImpl::DidCreateChannel()"; | 219 DVLOG(2) << "AppChildControllerImpl::DidCreateChannel()"; |
227 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
228 channel_info_ = channel_info; | 221 channel_info_ = channel_info; |
229 } | 222 } |
230 | 223 |
(...skipping 29 matching lines...) Expand all Loading... |
260 MojoResult result = main_function(service.release().value()); | 253 MojoResult result = main_function(service.release().value()); |
261 if (result < MOJO_RESULT_OK) | 254 if (result < MOJO_RESULT_OK) |
262 LOG(ERROR) << "MojoMain returned an error: " << result; | 255 LOG(ERROR) << "MojoMain returned an error: " << result; |
263 } while (false); | 256 } while (false); |
264 } | 257 } |
265 | 258 |
266 base::ThreadChecker thread_checker_; | 259 base::ThreadChecker thread_checker_; |
267 AppContext* const app_context_; | 260 AppContext* const app_context_; |
268 Blocker::Unblocker unblocker_; | 261 Blocker::Unblocker unblocker_; |
269 | 262 |
270 AppChildControllerClient* controller_client_; | |
271 embedder::ChannelInfo* channel_info_; | 263 embedder::ChannelInfo* channel_info_; |
272 | 264 |
273 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); | 265 DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); |
274 }; | 266 }; |
275 | 267 |
276 } // namespace | 268 } // namespace |
277 | 269 |
278 // AppChildProcess ------------------------------------------------------------- | 270 // AppChildProcess ------------------------------------------------------------- |
279 | 271 |
280 AppChildProcess::AppChildProcess() { | 272 AppChildProcess::AppChildProcess() { |
(...skipping 14 matching lines...) Expand all Loading... |
295 base::Bind(&AppChildControllerImpl::Init, base::Unretained(&app_context), | 287 base::Bind(&AppChildControllerImpl::Init, base::Unretained(&app_context), |
296 base::Passed(platform_channel()), blocker.GetUnblocker())); | 288 base::Passed(platform_channel()), blocker.GetUnblocker())); |
297 // This will block, then run whatever the controller wants. | 289 // This will block, then run whatever the controller wants. |
298 blocker.Block(); | 290 blocker.Block(); |
299 | 291 |
300 app_context.Shutdown(); | 292 app_context.Shutdown(); |
301 } | 293 } |
302 | 294 |
303 } // namespace shell | 295 } // namespace shell |
304 } // namespace mojo | 296 } // namespace mojo |
OLD | NEW |