Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / runner / in_process_native_runner.cc
blob04321c06e17e79af81fde0d6c2ea5687010d2c50
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.
5 #include "mojo/runner/in_process_native_runner.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/location.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "base/threading/platform_thread.h"
12 #include "mojo/runner/native_application_support.h"
14 namespace mojo {
15 namespace runner {
17 InProcessNativeRunner::InProcessNativeRunner(Context* context)
18 : cleanup_(shell::NativeApplicationCleanup::DONT_DELETE),
19 app_library_(nullptr) {
22 InProcessNativeRunner::~InProcessNativeRunner() {
23 // It is important to let the thread exit before unloading the DSO (when
24 // app_library_ is destructed), because the library may have registered
25 // thread-local data and destructors to run on thread termination.
26 if (thread_) {
27 DCHECK(thread_->HasBeenStarted());
28 DCHECK(!thread_->HasBeenJoined());
29 thread_->Join();
33 void InProcessNativeRunner::Start(
34 const base::FilePath& app_path,
35 shell::NativeApplicationCleanup cleanup,
36 InterfaceRequest<Application> application_request,
37 const base::Closure& app_completed_callback) {
38 app_path_ = app_path;
39 cleanup_ = cleanup;
41 DCHECK(!application_request_.is_pending());
42 application_request_ = application_request.Pass();
44 DCHECK(app_completed_callback_runner_.is_null());
45 app_completed_callback_runner_ = base::Bind(
46 &base::TaskRunner::PostTask, base::ThreadTaskRunnerHandle::Get(),
47 FROM_HERE, app_completed_callback);
49 DCHECK(!thread_);
50 thread_.reset(new base::DelegateSimpleThread(this, "app_thread"));
51 thread_->Start();
54 void InProcessNativeRunner::Run() {
55 DVLOG(2) << "Loading/running Mojo app in process from library: "
56 << app_path_.value()
57 << " thread id=" << base::PlatformThread::CurrentId();
59 // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method!
60 base::NativeLibrary app_library = LoadNativeApplication(app_path_, cleanup_);
61 app_library_.Reset(app_library);
62 RunNativeApplication(app_library, application_request_.Pass());
63 app_completed_callback_runner_.Run();
64 app_completed_callback_runner_.Reset();
67 scoped_ptr<shell::NativeRunner> InProcessNativeRunnerFactory::Create(
68 const Options& options) {
69 return make_scoped_ptr(new InProcessNativeRunner(context_));
72 } // namespace runner
73 } // namespace mojo