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

Side by Side Diff: mojo/shell/application_manager.cc

Issue 1705323003: ContentHandler -> ShellClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delete
Patch Set: . Created 4 years, 10 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
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/content_handler_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/process/process.h" 15 #include "base/process/process.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "mojo/common/url_type_converters.h" 19 #include "mojo/common/url_type_converters.h"
20 #include "mojo/public/cpp/bindings/binding.h" 20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "mojo/services/package_manager/loader.h" 21 #include "mojo/services/package_manager/loader.h"
22 #include "mojo/shell/application_instance.h" 22 #include "mojo/shell/application_instance.h"
23 #include "mojo/shell/connect_util.h" 23 #include "mojo/shell/connect_util.h"
24 #include "mojo/shell/content_handler_connection.h"
25 #include "mojo/shell/public/cpp/connect.h" 24 #include "mojo/shell/public/cpp/connect.h"
26 #include "mojo/shell/shell_application_loader.h" 25 #include "mojo/shell/shell_application_loader.h"
26 #include "mojo/shell/shell_client_factory_connection.h"
27 #include "mojo/shell/switches.h" 27 #include "mojo/shell/switches.h"
28 #include "mojo/util/filename_util.h" 28 #include "mojo/util/filename_util.h"
29 29
30 namespace mojo { 30 namespace mojo {
31 namespace shell { 31 namespace shell {
32 32
33 namespace { 33 namespace {
34 34
35 // Used by TestAPI. 35 // Used by TestAPI.
36 bool has_created_instance = false; 36 bool has_created_instance = false;
37 37
38 void OnEmptyOnConnectCallback(uint32_t remote_id, uint32_t content_handler_id) { 38 void OnEmptyOnConnectCallback(uint32_t remote_id,
39 uint32_t shell_client_factory_id) {
39 } 40 }
40 41
41 } // namespace 42 } // namespace
42 43
43 // static 44 // static
44 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) 45 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager)
45 : manager_(manager) { 46 : manager_(manager) {
46 } 47 }
47 48
48 ApplicationManager::TestAPI::~TestAPI() { 49 ApplicationManager::TestAPI::~TestAPI() {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 mojom::ApplicationInfoPtr application_info = 228 mojom::ApplicationInfoPtr application_info =
228 CreateApplicationInfoForInstance(instance); 229 CreateApplicationInfoForInstance(instance);
229 listeners_.ForAllPtrs( 230 listeners_.ForAllPtrs(
230 [this, &application_info](mojom::ApplicationManagerListener* listener) { 231 [this, &application_info](mojom::ApplicationManagerListener* listener) {
231 listener->ApplicationInstanceCreated(application_info.Clone()); 232 listener->ApplicationInstanceCreated(application_info.Clone());
232 }); 233 });
233 instance->InitializeApplication(); 234 instance->InitializeApplication();
234 return instance; 235 return instance;
235 } 236 }
236 237
237 uint32_t ApplicationManager::StartContentHandler( 238 uint32_t ApplicationManager::StartShellClientFactory(
238 const Identity& source, 239 const Identity& source,
239 const Identity& content_handler, 240 const Identity& shell_client_factory,
240 const GURL& url, 241 const GURL& url,
241 mojom::ShellClientRequest request) { 242 mojom::ShellClientRequest request) {
242 URLResponsePtr response(URLResponse::New()); 243 ShellClientFactoryConnection* connection =
243 response->url = url.spec(); 244 GetShellClientFactory(shell_client_factory, source);
244 ContentHandlerConnection* connection = 245 connection->CreateShellClient(std::move(request), url);
245 GetContentHandler(content_handler, source);
246 connection->StartApplication(std::move(request), std::move(response));
247 return connection->id(); 246 return connection->id();
248 } 247 }
249 248
250 ContentHandlerConnection* ApplicationManager::GetContentHandler( 249 ShellClientFactoryConnection* ApplicationManager::GetShellClientFactory(
251 const Identity& content_handler_identity, 250 const Identity& shell_client_factory_identity,
252 const Identity& source_identity) { 251 const Identity& source_identity) {
253 auto it = identity_to_content_handler_.find(content_handler_identity); 252 auto it = identity_to_shell_client_factory_.find(
254 if (it != identity_to_content_handler_.end()) 253 shell_client_factory_identity);
254 if (it != identity_to_shell_client_factory_.end())
255 return it->second; 255 return it->second;
256 256
257 ContentHandlerConnection* connection = new ContentHandlerConnection( 257 ShellClientFactoryConnection* connection = new ShellClientFactoryConnection(
258 this, source_identity, 258 this, source_identity,
259 content_handler_identity, 259 shell_client_factory_identity,
260 ++content_handler_id_counter_, 260 ++shell_client_factory_id_counter_,
261 base::Bind(&ApplicationManager::OnContentHandlerConnectionClosed, 261 base::Bind(&ApplicationManager::OnShellClientFactoryConnectionClosed,
262 weak_ptr_factory_.GetWeakPtr())); 262 weak_ptr_factory_.GetWeakPtr()));
263 identity_to_content_handler_[content_handler_identity] = connection; 263 identity_to_shell_client_factory_[shell_client_factory_identity] = connection;
264 return connection; 264 return connection;
265 } 265 }
266 266
267 void ApplicationManager::OnContentHandlerConnectionClosed( 267 void ApplicationManager::OnShellClientFactoryConnectionClosed(
268 ContentHandlerConnection* connection) { 268 ShellClientFactoryConnection* connection) {
269 // Remove the mapping. 269 // Remove the mapping.
270 auto it = identity_to_content_handler_.find(connection->identity()); 270 auto it = identity_to_shell_client_factory_.find(connection->identity());
271 DCHECK(it != identity_to_content_handler_.end()); 271 DCHECK(it != identity_to_shell_client_factory_.end());
272 identity_to_content_handler_.erase(it); 272 identity_to_shell_client_factory_.erase(it);
273 } 273 }
274 274
275 void ApplicationManager::OnGotResolvedURL( 275 void ApplicationManager::OnGotResolvedURL(
276 scoped_ptr<ConnectToApplicationParams> params, 276 scoped_ptr<ConnectToApplicationParams> params,
277 const String& resolved_url, 277 const String& resolved_url,
278 const String& file_url, 278 const String& file_url,
279 const String& application_name, 279 const String& application_name,
280 mojom::CapabilityFilterPtr base_filter) { 280 mojom::CapabilityFilterPtr base_filter) {
281 // It's possible that when this manifest request was issued, another one was 281 // It's possible that when this manifest request was issued, another one was
282 // already in-progress and completed by the time this one did, and so the 282 // already in-progress and completed by the time this one did, and so the
283 // requested application may already be running. 283 // requested application may already be running.
284 if (ConnectToRunningApplication(&params)) 284 if (ConnectToRunningApplication(&params))
285 return; 285 return;
286 286
287 GURL resolved_gurl = resolved_url.To<GURL>(); 287 GURL resolved_gurl = resolved_url.To<GURL>();
288 if (params->target().url().spec() != resolved_url) { 288 if (params->target().url().spec() != resolved_url) {
289 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); 289 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
290 if (!base_filter.is_null()) 290 if (!base_filter.is_null())
291 capability_filter = base_filter->filter.To<CapabilityFilter>(); 291 capability_filter = base_filter->filter.To<CapabilityFilter>();
292 292
293 // TODO(beng): For now, we just use the legacy PackageManagerImpl to manage 293 // TODO(beng): For now, we just use the legacy PackageManagerImpl to manage
294 // the ContentHandler connection. Once we get rid of the 294 // the ShellClientFactory connection. Once we get rid of the
295 // non-remote package manager path we will have to fold this in 295 // non-remote package manager path we will have to fold this in
296 // here. 296 // here.
297 Identity source, target; 297 Identity source, target;
298 mojom::ShellClientRequest request; 298 mojom::ShellClientRequest request;
299 ApplicationInstance* instance = CreateAndConnectToInstance( 299 ApplicationInstance* instance = CreateAndConnectToInstance(
300 std::move(params), &source, &target, application_name, &request); 300 std::move(params), &source, &target, application_name, &request);
301 301
302 uint32_t content_handler_id = StartContentHandler( 302 uint32_t shell_client_factory_id = StartShellClientFactory(
303 source, Identity(resolved_gurl, target.qualifier(), capability_filter), 303 source, Identity(resolved_gurl, target.qualifier(), capability_filter),
304 target.url(), std::move(request)); 304 target.url(), std::move(request));
305 CHECK(content_handler_id != mojom::Shell::kInvalidApplicationID); 305 CHECK(shell_client_factory_id != mojom::Shell::kInvalidApplicationID);
306 instance->set_requesting_content_handler_id(content_handler_id); 306 instance->set_requesting_shell_client_factory_id(shell_client_factory_id);
307 instance->RunConnectCallback(); 307 instance->RunConnectCallback();
308 return; 308 return;
309 } 309 }
310 CreateAndRunLocalApplication(std::move(params), application_name, 310 CreateAndRunLocalApplication(std::move(params), application_name,
311 file_url.To<GURL>()); 311 file_url.To<GURL>());
312 } 312 }
313 313
314 void ApplicationManager::CreateAndRunLocalApplication( 314 void ApplicationManager::CreateAndRunLocalApplication(
315 scoped_ptr<ConnectToApplicationParams> params, 315 scoped_ptr<ConnectToApplicationParams> params,
316 const String& application_name, 316 const String& application_name,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 } 402 }
403 } 403 }
404 404
405 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() { 405 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() {
406 return base::Bind(&OnEmptyOnConnectCallback); 406 return base::Bind(&OnEmptyOnConnectCallback);
407 } 407 }
408 408
409 } // namespace shell 409 } // namespace shell
410 } // namespace mojo 410 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/content_handler_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698