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

Side by Side Diff: content/browser/mojo/mojo_shell_context.cc

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/mojo/mojo_shell_context.h" 5 #include "content/browser/mojo/mojo_shell_context.h"
6 6
7 #include <utility>
8
7 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/path_service.h" 11 #include "base/path_service.h"
10 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
12 #include "content/browser/gpu/gpu_process_host.h" 14 #include "content/browser/gpu/gpu_process_host.h"
13 #include "content/common/gpu/gpu_process_launch_causes.h" 15 #include "content/common/gpu/gpu_process_launch_causes.h"
14 #include "content/common/process_control.mojom.h" 16 #include "content/common/process_control.mojom.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/content_browser_client.h" 18 #include "content/public/browser/content_browser_client.h"
(...skipping 28 matching lines...) Expand all
45 const base::string16& process_name, 47 const base::string16& process_name,
46 bool use_sandbox) { 48 bool use_sandbox) {
47 UtilityProcessHost* process_host = 49 UtilityProcessHost* process_host =
48 UtilityProcessHost::Create(nullptr, nullptr); 50 UtilityProcessHost::Create(nullptr, nullptr);
49 process_host->SetName(process_name); 51 process_host->SetName(process_name);
50 if (!use_sandbox) 52 if (!use_sandbox)
51 process_host->DisableSandbox(); 53 process_host->DisableSandbox();
52 process_host->StartMojoMode(); 54 process_host->StartMojoMode();
53 55
54 ServiceRegistry* services = process_host->GetServiceRegistry(); 56 ServiceRegistry* services = process_host->GetServiceRegistry();
55 services->ConnectToRemoteService(request.Pass()); 57 services->ConnectToRemoteService(std::move(request));
56 } 58 }
57 59
58 void OnApplicationLoaded(const GURL& url, bool success) { 60 void OnApplicationLoaded(const GURL& url, bool success) {
59 if (!success) 61 if (!success)
60 LOG(ERROR) << "Failed to launch Mojo application for " << url.spec(); 62 LOG(ERROR) << "Failed to launch Mojo application for " << url.spec();
61 } 63 }
62 64
63 // The default loader to use for all applications. This does nothing but drop 65 // The default loader to use for all applications. This does nothing but drop
64 // the Application request. 66 // the Application request.
65 class DefaultApplicationLoader : public mojo::shell::ApplicationLoader { 67 class DefaultApplicationLoader : public mojo::shell::ApplicationLoader {
(...skipping 23 matching lines...) Expand all
89 // mojo::shell::ApplicationLoader: 91 // mojo::shell::ApplicationLoader:
90 void Load( 92 void Load(
91 const GURL& url, 93 const GURL& url,
92 mojo::InterfaceRequest<mojo::Application> application_request) override { 94 mojo::InterfaceRequest<mojo::Application> application_request) override {
93 ProcessControlPtr process_control; 95 ProcessControlPtr process_control;
94 auto process_request = mojo::GetProxy(&process_control); 96 auto process_request = mojo::GetProxy(&process_control);
95 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 97 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
96 base::Bind(&StartUtilityProcessOnIOThread, 98 base::Bind(&StartUtilityProcessOnIOThread,
97 base::Passed(&process_request), 99 base::Passed(&process_request),
98 process_name_, use_sandbox_)); 100 process_name_, use_sandbox_));
99 process_control->LoadApplication(url.spec(), application_request.Pass(), 101 process_control->LoadApplication(url.spec(), std::move(application_request),
100 base::Bind(&OnApplicationLoaded, url)); 102 base::Bind(&OnApplicationLoaded, url));
101 } 103 }
102 104
103 const base::string16 process_name_; 105 const base::string16 process_name_;
104 const bool use_sandbox_; 106 const bool use_sandbox_;
105 107
106 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); 108 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader);
107 }; 109 };
108 110
109 // Request ProcessControl from GPU process host. Must be called on IO thread. 111 // Request ProcessControl from GPU process host. Must be called on IO thread.
110 void RequestGpuProcessControl(mojo::InterfaceRequest<ProcessControl> request) { 112 void RequestGpuProcessControl(mojo::InterfaceRequest<ProcessControl> request) {
111 BrowserChildProcessHostDelegate* process_host = 113 BrowserChildProcessHostDelegate* process_host =
112 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, 114 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
113 CAUSE_FOR_GPU_LAUNCH_MOJO_SETUP); 115 CAUSE_FOR_GPU_LAUNCH_MOJO_SETUP);
114 if (!process_host) { 116 if (!process_host) {
115 DLOG(ERROR) << "GPU process host not available."; 117 DLOG(ERROR) << "GPU process host not available.";
116 return; 118 return;
117 } 119 }
118 120
119 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual 121 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual
120 // process is dead. In that case, |request| will be dropped and application 122 // process is dead. In that case, |request| will be dropped and application
121 // load requests through ProcessControl will also fail. Make sure we handle 123 // load requests through ProcessControl will also fail. Make sure we handle
122 // these cases correctly. 124 // these cases correctly.
123 process_host->GetServiceRegistry()->ConnectToRemoteService(request.Pass()); 125 process_host->GetServiceRegistry()->ConnectToRemoteService(
126 std::move(request));
124 } 127 }
125 128
126 // Forwards the load request to the GPU process. 129 // Forwards the load request to the GPU process.
127 class GpuProcessLoader : public mojo::shell::ApplicationLoader { 130 class GpuProcessLoader : public mojo::shell::ApplicationLoader {
128 public: 131 public:
129 GpuProcessLoader() {} 132 GpuProcessLoader() {}
130 ~GpuProcessLoader() override {} 133 ~GpuProcessLoader() override {}
131 134
132 private: 135 private:
133 // mojo::shell::ApplicationLoader: 136 // mojo::shell::ApplicationLoader:
134 void Load( 137 void Load(
135 const GURL& url, 138 const GURL& url,
136 mojo::InterfaceRequest<mojo::Application> application_request) override { 139 mojo::InterfaceRequest<mojo::Application> application_request) override {
137 ProcessControlPtr process_control; 140 ProcessControlPtr process_control;
138 auto process_request = mojo::GetProxy(&process_control); 141 auto process_request = mojo::GetProxy(&process_control);
139 BrowserThread::PostTask( 142 BrowserThread::PostTask(
140 BrowserThread::IO, FROM_HERE, 143 BrowserThread::IO, FROM_HERE,
141 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); 144 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request)));
142 process_control->LoadApplication(url.spec(), application_request.Pass(), 145 process_control->LoadApplication(url.spec(), std::move(application_request),
143 base::Bind(&OnApplicationLoaded, url)); 146 base::Bind(&OnApplicationLoaded, url));
144 } 147 }
145 148
146 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); 149 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader);
147 }; 150 };
148 151
149 } // namespace 152 } // namespace
150 153
151 // Thread-safe proxy providing access to the shell context from any thread. 154 // Thread-safe proxy providing access to the shell context from any thread.
152 class MojoShellContext::Proxy { 155 class MojoShellContext::Proxy {
153 public: 156 public:
154 Proxy(MojoShellContext* shell_context) 157 Proxy(MojoShellContext* shell_context)
155 : shell_context_(shell_context), 158 : shell_context_(shell_context),
156 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 159 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
157 160
158 ~Proxy() {} 161 ~Proxy() {}
159 162
160 void ConnectToApplication( 163 void ConnectToApplication(
161 const GURL& url, 164 const GURL& url,
162 const GURL& requestor_url, 165 const GURL& requestor_url,
163 mojo::InterfaceRequest<mojo::ServiceProvider> request, 166 mojo::InterfaceRequest<mojo::ServiceProvider> request,
164 mojo::ServiceProviderPtr exposed_services, 167 mojo::ServiceProviderPtr exposed_services,
165 const mojo::shell::CapabilityFilter& filter, 168 const mojo::shell::CapabilityFilter& filter,
166 const mojo::Shell::ConnectToApplicationCallback& callback) { 169 const mojo::Shell::ConnectToApplicationCallback& callback) {
167 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { 170 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) {
168 if (shell_context_) { 171 if (shell_context_) {
169 shell_context_->ConnectToApplicationOnOwnThread( 172 shell_context_->ConnectToApplicationOnOwnThread(
170 url, requestor_url, request.Pass(), exposed_services.Pass(), filter, 173 url, requestor_url, std::move(request), std::move(exposed_services),
171 callback); 174 filter, callback);
172 } 175 }
173 } else { 176 } else {
174 // |shell_context_| outlives the main MessageLoop, so it's safe for it to 177 // |shell_context_| outlives the main MessageLoop, so it's safe for it to
175 // be unretained here. 178 // be unretained here.
176 task_runner_->PostTask( 179 task_runner_->PostTask(
177 FROM_HERE, 180 FROM_HERE,
178 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, 181 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread,
179 base::Unretained(shell_context_), url, requestor_url, 182 base::Unretained(shell_context_), url, requestor_url,
180 base::Passed(&request), base::Passed(&exposed_services), 183 base::Passed(&request), base::Passed(&exposed_services),
181 filter, callback)); 184 filter, callback));
(...skipping 17 matching lines...) Expand all
199 } 202 }
200 203
201 MojoShellContext::MojoShellContext() { 204 MojoShellContext::MojoShellContext() {
202 proxy_.Get().reset(new Proxy(this)); 205 proxy_.Get().reset(new Proxy(this));
203 206
204 // Construct with an empty filepath since mojo: urls can't be registered now 207 // Construct with an empty filepath since mojo: urls can't be registered now
205 // the url scheme registry is locked. 208 // the url scheme registry is locked.
206 scoped_ptr<mojo::package_manager::PackageManagerImpl> package_manager( 209 scoped_ptr<mojo::package_manager::PackageManagerImpl> package_manager(
207 new mojo::package_manager::PackageManagerImpl(base::FilePath(), nullptr)); 210 new mojo::package_manager::PackageManagerImpl(base::FilePath(), nullptr));
208 application_manager_.reset( 211 application_manager_.reset(
209 new mojo::shell::ApplicationManager(package_manager.Pass())); 212 new mojo::shell::ApplicationManager(std::move(package_manager)));
210 213
211 application_manager_->set_default_loader( 214 application_manager_->set_default_loader(
212 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader)); 215 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader));
213 216
214 StaticApplicationMap apps; 217 StaticApplicationMap apps;
215 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 218 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
216 if (g_applications_for_test) { 219 if (g_applications_for_test) {
217 // Add testing apps to the map, potentially overwriting whatever the 220 // Add testing apps to the map, potentially overwriting whatever the
218 // browser client registered. 221 // browser client registered.
219 for (const auto& entry : *g_applications_for_test) 222 for (const auto& entry : *g_applications_for_test)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 268 }
266 269
267 // static 270 // static
268 void MojoShellContext::ConnectToApplication( 271 void MojoShellContext::ConnectToApplication(
269 const GURL& url, 272 const GURL& url,
270 const GURL& requestor_url, 273 const GURL& requestor_url,
271 mojo::InterfaceRequest<mojo::ServiceProvider> request, 274 mojo::InterfaceRequest<mojo::ServiceProvider> request,
272 mojo::ServiceProviderPtr exposed_services, 275 mojo::ServiceProviderPtr exposed_services,
273 const mojo::shell::CapabilityFilter& filter, 276 const mojo::shell::CapabilityFilter& filter,
274 const mojo::Shell::ConnectToApplicationCallback& callback) { 277 const mojo::Shell::ConnectToApplicationCallback& callback) {
275 proxy_.Get()->ConnectToApplication(url, requestor_url, 278 proxy_.Get()->ConnectToApplication(url, requestor_url, std::move(request),
276 request.Pass(), exposed_services.Pass(), 279 std::move(exposed_services), filter,
277 filter, callback); 280 callback);
278 } 281 }
279 282
280 void MojoShellContext::ConnectToApplicationOnOwnThread( 283 void MojoShellContext::ConnectToApplicationOnOwnThread(
281 const GURL& url, 284 const GURL& url,
282 const GURL& requestor_url, 285 const GURL& requestor_url,
283 mojo::InterfaceRequest<mojo::ServiceProvider> request, 286 mojo::InterfaceRequest<mojo::ServiceProvider> request,
284 mojo::ServiceProviderPtr exposed_services, 287 mojo::ServiceProviderPtr exposed_services,
285 const mojo::shell::CapabilityFilter& filter, 288 const mojo::shell::CapabilityFilter& filter,
286 const mojo::Shell::ConnectToApplicationCallback& callback) { 289 const mojo::Shell::ConnectToApplicationCallback& callback) {
287 scoped_ptr<mojo::shell::ConnectToApplicationParams> params( 290 scoped_ptr<mojo::shell::ConnectToApplicationParams> params(
288 new mojo::shell::ConnectToApplicationParams); 291 new mojo::shell::ConnectToApplicationParams);
289 params->set_source( 292 params->set_source(
290 mojo::shell::Identity(requestor_url, std::string(), 293 mojo::shell::Identity(requestor_url, std::string(),
291 mojo::shell::GetPermissiveCapabilityFilter())); 294 mojo::shell::GetPermissiveCapabilityFilter()));
292 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); 295 params->SetTarget(mojo::shell::Identity(url, std::string(), filter));
293 params->set_services(request.Pass()); 296 params->set_services(std::move(request));
294 params->set_exposed_services(exposed_services.Pass()); 297 params->set_exposed_services(std::move(exposed_services));
295 params->set_on_application_end(base::Bind(&base::DoNothing)); 298 params->set_on_application_end(base::Bind(&base::DoNothing));
296 params->set_connect_callback(callback); 299 params->set_connect_callback(callback);
297 application_manager_->ConnectToApplication(params.Pass()); 300 application_manager_->ConnectToApplication(std::move(params));
298 } 301 }
299 302
300 } // namespace content 303 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_shell_client_host.cc ('k') | content/browser/mojo/renderer_capability_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698