Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: mojo/shell/runner/host/in_process_native_runner.cc

Issue 1801963002: Change primordial pipes to ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase onto catalog CL Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/runner/host/in_process_native_runner.h" 5 #include "mojo/shell/runner/host/in_process_native_runner.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/task_runner.h" 13 #include "base/task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "mojo/public/cpp/bindings/interface_request.h"
16 #include "mojo/shell/runner/host/native_application_support.h" 17 #include "mojo/shell/runner/host/native_application_support.h"
17 #include "mojo/shell/runner/host/out_of_process_native_runner.h" 18 #include "mojo/shell/runner/host/out_of_process_native_runner.h"
18 #include "mojo/shell/runner/init.h" 19 #include "mojo/shell/runner/init.h"
19 20
20 namespace mojo { 21 namespace mojo {
21 namespace shell { 22 namespace shell {
22 23
23 InProcessNativeRunner::InProcessNativeRunner() : app_library_(nullptr) {} 24 InProcessNativeRunner::InProcessNativeRunner() : app_library_(nullptr) {}
24 25
25 InProcessNativeRunner::~InProcessNativeRunner() { 26 InProcessNativeRunner::~InProcessNativeRunner() {
26 // It is important to let the thread exit before unloading the DSO (when 27 // It is important to let the thread exit before unloading the DSO (when
27 // app_library_ is destructed), because the library may have registered 28 // app_library_ is destructed), because the library may have registered
28 // thread-local data and destructors to run on thread termination. 29 // thread-local data and destructors to run on thread termination.
29 if (thread_) { 30 if (thread_) {
30 DCHECK(thread_->HasBeenStarted()); 31 DCHECK(thread_->HasBeenStarted());
31 DCHECK(!thread_->HasBeenJoined()); 32 DCHECK(!thread_->HasBeenJoined());
32 thread_->Join(); 33 thread_->Join();
33 } 34 }
34 } 35 }
35 36
36 void InProcessNativeRunner::Start( 37 mojom::ShellClientPtr InProcessNativeRunner::Start(
37 const base::FilePath& app_path, 38 const base::FilePath& app_path,
38 const Identity& target, 39 const Identity& target,
39 bool start_sandboxed, 40 bool start_sandboxed,
40 mojom::ShellClientRequest request,
41 const base::Callback<void(base::ProcessId)>& pid_available_callback, 41 const base::Callback<void(base::ProcessId)>& pid_available_callback,
42 const base::Closure& app_completed_callback) { 42 const base::Closure& app_completed_callback) {
43 app_path_ = app_path; 43 app_path_ = app_path;
44 44
45 DCHECK(!request_.is_pending()); 45 DCHECK(!request_.is_pending());
46 request_ = std::move(request); 46 mojom::ShellClientPtr client;
47 request_ = GetProxy(&client);
47 48
48 DCHECK(app_completed_callback_runner_.is_null()); 49 DCHECK(app_completed_callback_runner_.is_null());
49 app_completed_callback_runner_ = base::Bind( 50 app_completed_callback_runner_ = base::Bind(
50 &base::TaskRunner::PostTask, base::ThreadTaskRunnerHandle::Get(), 51 &base::TaskRunner::PostTask, base::ThreadTaskRunnerHandle::Get(),
51 FROM_HERE, app_completed_callback); 52 FROM_HERE, app_completed_callback);
52 53
53 DCHECK(!thread_); 54 DCHECK(!thread_);
54 std::string thread_name = "mojo:app_thread"; 55 std::string thread_name = "mojo:app_thread";
55 #if defined(OS_WIN) 56 #if defined(OS_WIN)
56 thread_name = base::WideToUTF8(app_path_.BaseName().value()); 57 thread_name = base::WideToUTF8(app_path_.BaseName().value());
57 #endif 58 #endif
58 thread_.reset(new base::DelegateSimpleThread(this, thread_name)); 59 thread_.reset(new base::DelegateSimpleThread(this, thread_name));
59 thread_->Start(); 60 thread_->Start();
60 pid_available_callback.Run(base::kNullProcessId); 61 pid_available_callback.Run(base::kNullProcessId);
62
63 return client;
61 } 64 }
62 65
63 void InProcessNativeRunner::Run() { 66 void InProcessNativeRunner::Run() {
64 DVLOG(2) << "Loading/running Mojo app in process from library: " 67 DVLOG(2) << "Loading/running Mojo app in process from library: "
65 << app_path_.value() 68 << app_path_.value()
66 << " thread id=" << base::PlatformThread::CurrentId(); 69 << " thread id=" << base::PlatformThread::CurrentId();
67 70
68 // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method! 71 // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method!
69 base::NativeLibrary app_library = LoadNativeApplication(app_path_); 72 base::NativeLibrary app_library = LoadNativeApplication(app_path_);
70 app_library_.Reset(app_library); 73 app_library_.Reset(app_library);
(...skipping 12 matching lines...) Expand all
83 // Non-Mojo apps are always run in a new process. 86 // Non-Mojo apps are always run in a new process.
84 if (!app_path.MatchesExtension(FILE_PATH_LITERAL(".mojo"))) { 87 if (!app_path.MatchesExtension(FILE_PATH_LITERAL(".mojo"))) {
85 return make_scoped_ptr( 88 return make_scoped_ptr(
86 new OutOfProcessNativeRunner(launch_process_runner_, nullptr)); 89 new OutOfProcessNativeRunner(launch_process_runner_, nullptr));
87 } 90 }
88 return make_scoped_ptr(new InProcessNativeRunner); 91 return make_scoped_ptr(new InProcessNativeRunner);
89 } 92 }
90 93
91 } // namespace shell 94 } // namespace shell
92 } // namespace mojo 95 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/host/in_process_native_runner.h ('k') | mojo/shell/runner/host/out_of_process_native_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698