| 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 <unistd.h> | 5 #include <unistd.h> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // |mojo::ErrorHandler| methods: | 209 // |mojo::ErrorHandler| methods: |
| 210 void OnConnectionError() override { | 210 void OnConnectionError() override { |
| 211 // A connection error means the connection to the shell is lost. This is not | 211 // A connection error means the connection to the shell is lost. This is not |
| 212 // recoverable. | 212 // recoverable. |
| 213 LOG(ERROR) << "Connection error to the shell."; | 213 LOG(ERROR) << "Connection error to the shell."; |
| 214 _exit(1); | 214 _exit(1); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // |ChildController| methods: | 217 // |ChildController| methods: |
| 218 void StartApp(const mojo::String& app_path, | 218 void StartApp(const mojo::String& app_path, |
| 219 bool clean_app_path, | |
| 220 mojo::InterfaceRequest<mojo::Application> application_request, | 219 mojo::InterfaceRequest<mojo::Application> application_request, |
| 221 const StartAppCallback& on_app_complete) override { | 220 const StartAppCallback& on_app_complete) override { |
| 222 DVLOG(2) << "ChildControllerImpl::StartApp(" << app_path << ", ...)"; | 221 DVLOG(2) << "ChildControllerImpl::StartApp(" << app_path << ", ...)"; |
| 223 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 | 223 |
| 225 on_app_complete_ = on_app_complete; | 224 on_app_complete_ = on_app_complete; |
| 226 unblocker_.Unblock(base::Bind(&ChildControllerImpl::StartAppOnMainThread, | 225 unblocker_.Unblock(base::Bind(&ChildControllerImpl::StartAppOnMainThread, |
| 227 base::FilePath::FromUTF8Unsafe(app_path), | 226 base::FilePath::FromUTF8Unsafe(app_path), |
| 228 clean_app_path | |
| 229 ? NativeApplicationCleanup::DELETE | |
| 230 : NativeApplicationCleanup::DONT_DELETE, | |
| 231 base::Passed(&application_request))); | 227 base::Passed(&application_request))); |
| 232 } | 228 } |
| 233 | 229 |
| 234 void ExitNow(int32_t exit_code) override { | 230 void ExitNow(int32_t exit_code) override { |
| 235 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")"; | 231 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")"; |
| 236 _exit(exit_code); | 232 _exit(exit_code); |
| 237 } | 233 } |
| 238 | 234 |
| 239 private: | 235 private: |
| 240 ChildControllerImpl(AppContext* app_context, | 236 ChildControllerImpl(AppContext* app_context, |
| 241 const Blocker::Unblocker& unblocker) | 237 const Blocker::Unblocker& unblocker) |
| 242 : app_context_(app_context), | 238 : app_context_(app_context), |
| 243 unblocker_(unblocker), | 239 unblocker_(unblocker), |
| 244 channel_info_(nullptr), | 240 channel_info_(nullptr), |
| 245 binding_(this) { | 241 binding_(this) { |
| 246 binding_.set_error_handler(this); | 242 binding_.set_error_handler(this); |
| 247 } | 243 } |
| 248 | 244 |
| 249 // Callback for |mojo::embedder::CreateChannel()|. | 245 // Callback for |mojo::embedder::CreateChannel()|. |
| 250 void DidCreateChannel(mojo::embedder::ChannelInfo* channel_info) { | 246 void DidCreateChannel(mojo::embedder::ChannelInfo* channel_info) { |
| 251 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; | 247 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; |
| 252 DCHECK(thread_checker_.CalledOnValidThread()); | 248 DCHECK(thread_checker_.CalledOnValidThread()); |
| 253 channel_info_ = channel_info; | 249 channel_info_ = channel_info; |
| 254 } | 250 } |
| 255 | 251 |
| 256 static void StartAppOnMainThread( | 252 static void StartAppOnMainThread( |
| 257 const base::FilePath& app_path, | 253 const base::FilePath& app_path, |
| 258 NativeApplicationCleanup cleanup, | |
| 259 mojo::InterfaceRequest<mojo::Application> application_request) { | 254 mojo::InterfaceRequest<mojo::Application> application_request) { |
| 260 // TODO(vtl): This is copied from in_process_native_runner.cc. | 255 // TODO(vtl): This is copied from in_process_native_runner.cc. |
| 261 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() | 256 DVLOG(2) << "Loading/running Mojo app from " << app_path.value() |
| 262 << " out of process"; | 257 << " out of process"; |
| 263 | 258 |
| 264 // We intentionally don't unload the native library as its lifetime is the | 259 // We intentionally don't unload the native library as its lifetime is the |
| 265 // same as that of the process. | 260 // same as that of the process. |
| 266 base::NativeLibrary app_library = LoadNativeApplication(app_path, cleanup); | 261 base::NativeLibrary app_library = LoadNativeApplication(app_path); |
| 267 RunNativeApplication(app_library, application_request.Pass()); | 262 RunNativeApplication(app_library, application_request.Pass()); |
| 268 } | 263 } |
| 269 | 264 |
| 270 base::ThreadChecker thread_checker_; | 265 base::ThreadChecker thread_checker_; |
| 271 AppContext* const app_context_; | 266 AppContext* const app_context_; |
| 272 Blocker::Unblocker unblocker_; | 267 Blocker::Unblocker unblocker_; |
| 273 StartAppCallback on_app_complete_; | 268 StartAppCallback on_app_complete_; |
| 274 | 269 |
| 275 mojo::embedder::ChannelInfo* channel_info_; | 270 mojo::embedder::ChannelInfo* channel_info_; |
| 276 mojo::Binding<ChildController> binding_; | 271 mojo::Binding<ChildController> binding_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 305 base::Bind(&shell::ChildControllerImpl::Init, | 300 base::Bind(&shell::ChildControllerImpl::Init, |
| 306 base::Unretained(&app_context), | 301 base::Unretained(&app_context), |
| 307 base::Passed(&platform_channel), blocker.GetUnblocker())); | 302 base::Passed(&platform_channel), blocker.GetUnblocker())); |
| 308 // This will block, then run whatever the controller wants. | 303 // This will block, then run whatever the controller wants. |
| 309 blocker.Block(); | 304 blocker.Block(); |
| 310 | 305 |
| 311 app_context.Shutdown(); | 306 app_context.Shutdown(); |
| 312 | 307 |
| 313 return 0; | 308 return 0; |
| 314 } | 309 } |
| OLD | NEW |