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

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

Issue 1701933004: Remove the old package manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@am2
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/application_manager_unittest.cc » ('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/fetcher.h" 23 #include "mojo/shell/connect_util.h"
24 #include "mojo/shell/package_manager.h" 24 #include "mojo/shell/content_handler_connection.h"
25 #include "mojo/shell/public/cpp/connect.h" 25 #include "mojo/shell/public/cpp/connect.h"
26 #include "mojo/shell/query_util.h"
27 #include "mojo/shell/shell_application_loader.h" 26 #include "mojo/shell/shell_application_loader.h"
28 #include "mojo/shell/switches.h" 27 #include "mojo/shell/switches.h"
29 #include "mojo/util/filename_util.h" 28 #include "mojo/util/filename_util.h"
30 29
31 namespace mojo { 30 namespace mojo {
32 namespace shell { 31 namespace shell {
33 32
34 namespace { 33 namespace {
35 34
36 // Used by TestAPI. 35 // Used by TestAPI.
(...skipping 16 matching lines...) Expand all
53 return has_created_instance; 52 return has_created_instance;
54 } 53 }
55 54
56 bool ApplicationManager::TestAPI::HasRunningInstanceForURL( 55 bool ApplicationManager::TestAPI::HasRunningInstanceForURL(
57 const GURL& url) const { 56 const GURL& url) const {
58 return manager_->identity_to_instance_.find(Identity(url)) != 57 return manager_->identity_to_instance_.find(Identity(url)) !=
59 manager_->identity_to_instance_.end(); 58 manager_->identity_to_instance_.end();
60 } 59 }
61 60
62 ApplicationManager::ApplicationManager( 61 ApplicationManager::ApplicationManager(
63 scoped_ptr<PackageManager> package_manager,
64 bool register_mojo_url_schemes) 62 bool register_mojo_url_schemes)
65 : ApplicationManager(std::move(package_manager), nullptr, nullptr, 63 : ApplicationManager(nullptr, nullptr, register_mojo_url_schemes) {}
66 register_mojo_url_schemes) {}
67 64
68 ApplicationManager::ApplicationManager( 65 ApplicationManager::ApplicationManager(
69 scoped_ptr<PackageManager> package_manager,
70 scoped_ptr<NativeRunnerFactory> native_runner_factory, 66 scoped_ptr<NativeRunnerFactory> native_runner_factory,
71 base::TaskRunner* task_runner, 67 base::TaskRunner* task_runner,
72 bool register_mojo_url_schemes) 68 bool register_mojo_url_schemes)
73 : use_remote_package_manager_(false), 69 : task_runner_(task_runner),
74 package_manager_(std::move(package_manager)),
75 task_runner_(task_runner),
76 native_runner_factory_(std::move(native_runner_factory)), 70 native_runner_factory_(std::move(native_runner_factory)),
77 weak_ptr_factory_(this) { 71 weak_ptr_factory_(this) {
78 package_manager_->SetApplicationManager(this);
79 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)), 72 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)),
80 GURL("mojo:shell")); 73 GURL("mojo://shell/"));
81 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 74
82 switches::kDontUseRemotePackageManager)) { 75 GURL package_manager_url("mojo://package_manager/");
83 UseRemotePackageManager(register_mojo_url_schemes); 76 SetLoaderForURL(make_scoped_ptr(new package_manager::Loader(
84 } 77 task_runner_, register_mojo_url_schemes)), package_manager_url);
78
79 ConnectToInterface(this, package_manager_url, &shell_resolver_);
85 } 80 }
86 81
87 ApplicationManager::~ApplicationManager() { 82 ApplicationManager::~ApplicationManager() {
88 TerminateShellConnections(); 83 TerminateShellConnections();
89 STLDeleteValues(&url_to_loader_); 84 STLDeleteValues(&url_to_loader_);
90 for (auto& runner : native_runners_) 85 for (auto& runner : native_runners_)
91 runner.reset(); 86 runner.reset();
92 } 87 }
93 88
94 void ApplicationManager::TerminateShellConnections() { 89 void ApplicationManager::TerminateShellConnections() {
95 STLDeleteValues(&identity_to_instance_); 90 STLDeleteValues(&identity_to_instance_);
96 } 91 }
97 92
98 void ApplicationManager::ConnectToApplication( 93 void ApplicationManager::ConnectToApplication(
99 scoped_ptr<ConnectToApplicationParams> params) { 94 scoped_ptr<ConnectToApplicationParams> params) {
100 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", 95 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication",
101 TRACE_EVENT_SCOPE_THREAD, "original_url", 96 TRACE_EVENT_SCOPE_THREAD, "original_url",
102 params->target().url().spec()); 97 params->target().url().spec());
103 DCHECK(params->target().url().is_valid()); 98 DCHECK(params->target().url().is_valid());
104 99
105 // Connect to an existing matching instance, if possible. 100 // Connect to an existing matching instance, if possible.
106 if (ConnectToRunningApplication(&params)) 101 if (ConnectToRunningApplication(&params))
107 return; 102 return;
108 103
109 // TODO(beng): seems like this should be able to move to OnGotResolvedURL(). 104 // TODO(beng): seems like this should be able to move to OnGotResolvedURL().
110 ApplicationLoader* loader = GetLoaderForURL(params->target().url()); 105 ApplicationLoader* loader = GetLoaderForURL(params->target().url());
111 if (loader) { 106 if (loader) {
112 GURL url = params->target().url(); 107 GURL url = params->target().url();
113 package_manager_->BuiltinAppLoaded(url);
114 mojom::ShellClientRequest request; 108 mojom::ShellClientRequest request;
115 std::string application_name = 109 // TODO(beng): move this to OnGotResolvedURL & read from manifest.
116 package_manager_->GetApplicationName(params->target().url().spec()); 110 std::string application_name = url.spec();
117 ApplicationInstance* instance = CreateAndConnectToInstance( 111 ApplicationInstance* instance = CreateAndConnectToInstance(
118 std::move(params), nullptr, nullptr, application_name, &request); 112 std::move(params), nullptr, nullptr, application_name, &request);
119 loader->Load(url, std::move(request)); 113 loader->Load(url, std::move(request));
120 instance->RunConnectCallback(); 114 instance->RunConnectCallback();
121 return; 115 return;
122 } 116 }
123 117
124 if (use_remote_package_manager_) { 118 std::string url = params->target().url().spec();
125 std::string url = params->target().url().spec(); 119 shell_resolver_->ResolveMojoURL(
126 shell_resolver_->ResolveMojoURL( 120 url,
127 url, 121 base::Bind(&ApplicationManager::OnGotResolvedURL,
128 base::Bind(&ApplicationManager::OnGotResolvedURL, 122 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)));
129 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)));
130 } else {
131 URLRequestPtr original_url_request = params->TakeTargetURLRequest();
132 auto callback =
133 base::Bind(&ApplicationManager::HandleFetchCallback,
134 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params));
135 package_manager_->FetchRequest(std::move(original_url_request), callback);
136 }
137 }
138
139 void ApplicationManager::UseRemotePackageManager(
140 bool register_mojo_url_schemes) {
141 use_remote_package_manager_ = true;
142
143 GURL package_manager_url("mojo://package_manager/");
144
145 SetLoaderForURL(make_scoped_ptr(new package_manager::Loader(
146 task_runner_, register_mojo_url_schemes)), package_manager_url);
147
148 shell::mojom::InterfaceProviderPtr interfaces;
149 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
150 params->set_source(Identity(GURL("mojo:shell"), std::string(),
151 GetPermissiveCapabilityFilter()));
152 params->set_remote_interfaces(GetProxy(&interfaces));
153
154 if (false) {
155 GURL file_url =
156 package_manager_->ResolveMojoURL(package_manager_url);
157 params->SetTarget(Identity(file_url, std::string(),
158 GetPermissiveCapabilityFilter()));
159 // TODO(beng): Fish the name out of a manifest. There's a chicken-and-egg
160 // issue here as the package manager reads the manifests. The solution is
161 //probably to defer application name loading.
162 CreateAndRunLocalApplication(std::move(params), "Package Manager",
163 file_url);
164 } else {
165 params->SetTarget(Identity(package_manager_url, std::string(),
166 GetPermissiveCapabilityFilter()));
167 ConnectToApplication(std::move(params));
168 }
169 GetInterface(interfaces.get(), &shell_resolver_);
170 } 123 }
171 124
172 bool ApplicationManager::ConnectToRunningApplication( 125 bool ApplicationManager::ConnectToRunningApplication(
173 scoped_ptr<ConnectToApplicationParams>* params) { 126 scoped_ptr<ConnectToApplicationParams>* params) {
174 ApplicationInstance* instance = GetApplicationInstance((*params)->target()); 127 ApplicationInstance* instance = GetApplicationInstance((*params)->target());
175 if (!instance) 128 if (!instance)
176 return false; 129 return false;
177 130
178 // TODO(beng): CHECK() that the target URL is already in the application 131 // TODO(beng): CHECK() that the target URL is already in the application
179 // catalog. 132 // catalog.
(...skipping 12 matching lines...) Expand all
192 const GURL& url, 145 const GURL& url,
193 mojom::CapabilityFilterPtr filter, 146 mojom::CapabilityFilterPtr filter,
194 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { 147 InterfaceRequest<mojom::PIDReceiver> pid_receiver) {
195 // We don't call ConnectToClient() here since the instance was created 148 // We don't call ConnectToClient() here since the instance was created
196 // manually by other code, not in response to a Connect() request. The newly 149 // manually by other code, not in response to a Connect() request. The newly
197 // created instance is identified by |url| and may be subsequently reached by 150 // created instance is identified by |url| and may be subsequently reached by
198 // client code using this identity. 151 // client code using this identity.
199 CapabilityFilter local_filter = filter->filter.To<CapabilityFilter>(); 152 CapabilityFilter local_filter = filter->filter.To<CapabilityFilter>();
200 Identity target_id(url, std::string(), local_filter); 153 Identity target_id(url, std::string(), local_filter);
201 mojom::ShellClientRequest request; 154 mojom::ShellClientRequest request;
155 // TODO(beng): do better than url.spec() for application name.
202 ApplicationInstance* instance = CreateInstance( 156 ApplicationInstance* instance = CreateInstance(
203 target_id, EmptyConnectCallback(), base::Closure(), 157 target_id, EmptyConnectCallback(), base::Closure(),
204 package_manager_->GetApplicationName(url.spec()), &request); 158 url.spec(), &request);
205 instance->BindPIDReceiver(std::move(pid_receiver)); 159 instance->BindPIDReceiver(std::move(pid_receiver));
206 scoped_ptr<NativeRunner> runner = 160 scoped_ptr<NativeRunner> runner =
207 native_runner_factory_->Create(base::FilePath()); 161 native_runner_factory_->Create(base::FilePath());
208 runner->InitHost(std::move(channel), std::move(request)); 162 runner->InitHost(std::move(channel), std::move(request));
209 instance->SetNativeRunner(runner.get()); 163 instance->SetNativeRunner(runner.get());
210 native_runners_.push_back(std::move(runner)); 164 native_runners_.push_back(std::move(runner));
211 } 165 }
212 166
213 void ApplicationManager::AddListener( 167 void ApplicationManager::AddListener(
214 mojom::ApplicationManagerListenerPtr listener) { 168 mojom::ApplicationManagerListenerPtr listener) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 mojom::ApplicationInfoPtr application_info = 227 mojom::ApplicationInfoPtr application_info =
274 CreateApplicationInfoForInstance(instance); 228 CreateApplicationInfoForInstance(instance);
275 listeners_.ForAllPtrs( 229 listeners_.ForAllPtrs(
276 [this, &application_info](mojom::ApplicationManagerListener* listener) { 230 [this, &application_info](mojom::ApplicationManagerListener* listener) {
277 listener->ApplicationInstanceCreated(application_info.Clone()); 231 listener->ApplicationInstanceCreated(application_info.Clone());
278 }); 232 });
279 instance->InitializeApplication(); 233 instance->InitializeApplication();
280 return instance; 234 return instance;
281 } 235 }
282 236
237 uint32_t ApplicationManager::StartContentHandler(
238 const Identity& source,
239 const Identity& content_handler,
240 const GURL& url,
241 mojom::ShellClientRequest request) {
242 URLResponsePtr response(URLResponse::New());
243 response->url = url.spec();
244 ContentHandlerConnection* connection =
245 GetContentHandler(content_handler, source);
246 connection->StartApplication(std::move(request), std::move(response));
247 return connection->id();
248 }
249
250 ContentHandlerConnection* ApplicationManager::GetContentHandler(
251 const Identity& content_handler_identity,
252 const Identity& source_identity) {
253 auto it = identity_to_content_handler_.find(content_handler_identity);
254 if (it != identity_to_content_handler_.end())
255 return it->second;
256
257 ContentHandlerConnection* connection = new ContentHandlerConnection(
258 this, source_identity,
259 content_handler_identity,
260 ++content_handler_id_counter_,
261 base::Bind(&ApplicationManager::OnContentHandlerConnectionClosed,
262 weak_ptr_factory_.GetWeakPtr()));
263 identity_to_content_handler_[content_handler_identity] = connection;
264 return connection;
265 }
266
267 void ApplicationManager::OnContentHandlerConnectionClosed(
268 ContentHandlerConnection* connection) {
269 // Remove the mapping.
270 auto it = identity_to_content_handler_.find(connection->identity());
271 DCHECK(it != identity_to_content_handler_.end());
272 identity_to_content_handler_.erase(it);
273 }
274
283 void ApplicationManager::OnGotResolvedURL( 275 void ApplicationManager::OnGotResolvedURL(
284 scoped_ptr<ConnectToApplicationParams> params, 276 scoped_ptr<ConnectToApplicationParams> params,
285 const String& resolved_url, 277 const String& resolved_url,
286 const String& file_url, 278 const String& file_url,
287 const String& application_name, 279 const String& application_name,
288 mojom::CapabilityFilterPtr base_filter) { 280 mojom::CapabilityFilterPtr base_filter) {
289 // 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
290 // 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
291 // requested application may already be running. 283 // requested application may already be running.
292 if (ConnectToRunningApplication(&params)) 284 if (ConnectToRunningApplication(&params))
293 return; 285 return;
294 286
295 GURL resolved_gurl = resolved_url.To<GURL>(); 287 GURL resolved_gurl = resolved_url.To<GURL>();
296 if (params->target().url().spec() != resolved_url) { 288 if (params->target().url().spec() != resolved_url) {
297 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); 289 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
298 if (!base_filter.is_null()) 290 if (!base_filter.is_null())
299 capability_filter = base_filter->filter.To<CapabilityFilter>(); 291 capability_filter = base_filter->filter.To<CapabilityFilter>();
300 292
301 // 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
302 // the ContentHandler connection. Once we get rid of the 294 // the ContentHandler connection. Once we get rid of the
303 // 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
304 // here. 296 // here.
305 Identity source, target; 297 Identity source, target;
306 mojom::ShellClientRequest request; 298 mojom::ShellClientRequest request;
307 ApplicationInstance* instance = CreateAndConnectToInstance( 299 ApplicationInstance* instance = CreateAndConnectToInstance(
308 std::move(params), &source, &target, application_name, &request); 300 std::move(params), &source, &target, application_name, &request);
309 301
310 uint32_t content_handler_id = package_manager_->StartContentHandler( 302 uint32_t content_handler_id = StartContentHandler(
311 source, Identity(resolved_gurl, target.qualifier(), capability_filter), 303 source, Identity(resolved_gurl, target.qualifier(), capability_filter),
312 target.url(), std::move(request)); 304 target.url(), std::move(request));
313 CHECK(content_handler_id != mojom::Shell::kInvalidApplicationID); 305 CHECK(content_handler_id != mojom::Shell::kInvalidApplicationID);
314 instance->set_requesting_content_handler_id(content_handler_id); 306 instance->set_requesting_content_handler_id(content_handler_id);
315 instance->RunConnectCallback(); 307 instance->RunConnectCallback();
316 return; 308 return;
317 } 309 }
318 CreateAndRunLocalApplication(std::move(params), application_name, 310 CreateAndRunLocalApplication(std::move(params), application_name,
319 file_url.To<GURL>()); 311 file_url.To<GURL>());
320 } 312 }
321 313
322 void ApplicationManager::CreateAndRunLocalApplication( 314 void ApplicationManager::CreateAndRunLocalApplication(
323 scoped_ptr<ConnectToApplicationParams> params, 315 scoped_ptr<ConnectToApplicationParams> params,
324 const String& application_name, 316 const String& application_name,
325 const GURL& file_url) { 317 const GURL& file_url) {
326 Identity source, target; 318 Identity source, target;
327 mojom::ShellClientRequest request; 319 mojom::ShellClientRequest request;
328 ApplicationInstance* instance = CreateAndConnectToInstance( 320 ApplicationInstance* instance = CreateAndConnectToInstance(
329 std::move(params), &source, &target, application_name, &request); 321 std::move(params), &source, &target, application_name, &request);
330 322
331 scoped_ptr<Fetcher> fetcher;
332 bool start_sandboxed = false; 323 bool start_sandboxed = false;
333 RunNativeApplication(std::move(request), start_sandboxed, std::move(fetcher), 324 RunNativeApplication(std::move(request), start_sandboxed, instance,
334 instance, util::UrlToFilePath(file_url), true); 325 util::UrlToFilePath(file_url));
335 instance->RunConnectCallback();
336 }
337
338 void ApplicationManager::HandleFetchCallback(
339 scoped_ptr<ConnectToApplicationParams> params,
340 scoped_ptr<Fetcher> fetcher) {
341 if (!fetcher) {
342 // Network error. Drop |params| to tell the requestor.
343 params->connect_callback().Run(mojom::Shell::kInvalidApplicationID,
344 mojom::Shell::kInvalidApplicationID);
345 return;
346 }
347
348 GURL redirect_url = fetcher->GetRedirectURL();
349 if (!redirect_url.is_empty()) {
350 // And around we go again... Whee!
351 // TODO(sky): this loses the original URL info.
352 URLRequestPtr new_request = URLRequest::New();
353 new_request->url = redirect_url.spec();
354 HttpHeaderPtr header = HttpHeader::New();
355 header->name = "Referer";
356 header->value = fetcher->GetRedirectReferer().spec();
357 new_request->headers.push_back(std::move(header));
358 params->SetTargetURLRequest(std::move(new_request));
359 ConnectToApplication(std::move(params));
360 return;
361 }
362
363 // We already checked if the application was running before we fetched it, but
364 // it might have started while the fetch was outstanding. We don't want to
365 // have two copies of the app running, so check again.
366 if (ConnectToRunningApplication(&params))
367 return;
368
369 Identity source, target;
370 mojom::ShellClientRequest request;
371 std::string application_name =
372 package_manager_->GetApplicationName(params->target().url().spec());
373 ApplicationInstance* instance = CreateAndConnectToInstance(
374 std::move(params), &source, &target, application_name, &request);
375
376 uint32_t content_handler_id = package_manager_->HandleWithContentHandler(
377 fetcher.get(), source, target.url(), target.filter(), &request);
378 if (content_handler_id != mojom::Shell::kInvalidApplicationID) {
379 instance->set_requesting_content_handler_id(content_handler_id);
380 } else {
381 bool start_sandboxed = false;
382 fetcher->AsPath(
383 task_runner_,
384 base::Bind(&ApplicationManager::RunNativeApplication,
385 weak_ptr_factory_.GetWeakPtr(),
386 base::Passed(std::move(request)), start_sandboxed,
387 base::Passed(std::move(fetcher)),
388 base::Unretained(instance)));
389 }
390 instance->RunConnectCallback(); 326 instance->RunConnectCallback();
391 } 327 }
392 328
393 void ApplicationManager::RunNativeApplication( 329 void ApplicationManager::RunNativeApplication(
394 InterfaceRequest<mojom::ShellClient> request, 330 InterfaceRequest<mojom::ShellClient> request,
395 bool start_sandboxed, 331 bool start_sandboxed,
396 scoped_ptr<Fetcher> fetcher,
397 ApplicationInstance* instance, 332 ApplicationInstance* instance,
398 const base::FilePath& path, 333 const base::FilePath& path) {
399 bool path_exists) {
400 // We only passed fetcher to keep it alive. Done with it now.
401 fetcher.reset();
402
403 DCHECK(request.is_pending()); 334 DCHECK(request.is_pending());
404 335
405 if (!path_exists) {
406 LOG(ERROR) << "Library not started because library path '" << path.value()
407 << "' does not exist.";
408 return;
409 }
410
411 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", 336 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path",
412 path.AsUTF8Unsafe()); 337 path.AsUTF8Unsafe());
413 scoped_ptr<NativeRunner> runner = native_runner_factory_->Create(path); 338 scoped_ptr<NativeRunner> runner = native_runner_factory_->Create(path);
414 runner->Start(path, start_sandboxed, std::move(request), 339 runner->Start(path, start_sandboxed, std::move(request),
415 base::Bind(&ApplicationManager::ApplicationPIDAvailable, 340 base::Bind(&ApplicationManager::ApplicationPIDAvailable,
416 weak_ptr_factory_.GetWeakPtr(), instance->id()), 341 weak_ptr_factory_.GetWeakPtr(), instance->id()),
417 base::Bind(&ApplicationManager::CleanupRunner, 342 base::Bind(&ApplicationManager::CleanupRunner,
418 weak_ptr_factory_.GetWeakPtr(), runner.get())); 343 weak_ptr_factory_.GetWeakPtr(), runner.get()));
419 instance->SetNativeRunner(runner.get()); 344 instance->SetNativeRunner(runner.get());
420 native_runners_.push_back(std::move(runner)); 345 native_runners_.push_back(std::move(runner));
421 } 346 }
422 347
423 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, 348 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
424 const GURL& url) { 349 const GURL& url) {
425 URLToLoaderMap::iterator it = url_to_loader_.find(url); 350 URLToLoaderMap::iterator it = url_to_loader_.find(url);
426 if (it != url_to_loader_.end()) 351 if (it != url_to_loader_.end())
427 delete it->second; 352 delete it->second;
428 url_to_loader_[url] = loader.release(); 353 url_to_loader_[url] = loader.release();
429 } 354 }
430 355
431 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { 356 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
432 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); 357 auto url_it = url_to_loader_.find(url);
433 if (url_it != url_to_loader_.end()) 358 if (url_it != url_to_loader_.end())
434 return url_it->second; 359 return url_it->second;
435 return default_loader_.get(); 360 return default_loader_.get();
436 } 361 }
437 362
438 mojom::ApplicationInfoPtr ApplicationManager::CreateApplicationInfoForInstance( 363 mojom::ApplicationInfoPtr ApplicationManager::CreateApplicationInfoForInstance(
439 ApplicationInstance* instance) const { 364 ApplicationInstance* instance) const {
440 mojom::ApplicationInfoPtr info(mojom::ApplicationInfo::New()); 365 mojom::ApplicationInfoPtr info(mojom::ApplicationInfo::New());
441 info->id = instance->id(); 366 info->id = instance->id();
442 info->url = instance->identity().url().spec(); 367 info->url = instance->identity().url().spec();
443 info->qualifier = instance->identity().qualifier(); 368 info->qualifier = instance->identity().qualifier();
444 if (use_remote_package_manager_) 369 info->name = instance->application_name();
445 info->name = instance->application_name();
446 else
447 info->name = package_manager_->GetApplicationName(info->url);
448 if (instance->identity().url().spec() == "mojo://shell/") 370 if (instance->identity().url().spec() == "mojo://shell/")
449 info->pid = base::Process::Current().Pid(); 371 info->pid = base::Process::Current().Pid();
450 else 372 else
451 info->pid = instance->pid(); 373 info->pid = instance->pid();
452 return info; 374 return info;
453 } 375 }
454 376
455 void ApplicationManager::OnApplicationInstanceError( 377 void ApplicationManager::OnApplicationInstanceError(
456 ApplicationInstance* instance) { 378 ApplicationInstance* instance) {
457 // Called from ~ApplicationInstance, so we do not need to call Destroy here. 379 // Called from ~ApplicationInstance, so we do not need to call Destroy here.
(...skipping 21 matching lines...) Expand all
479 } 401 }
480 } 402 }
481 } 403 }
482 404
483 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() { 405 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() {
484 return base::Bind(&OnEmptyOnConnectCallback); 406 return base::Bind(&OnEmptyOnConnectCallback);
485 } 407 }
486 408
487 } // namespace shell 409 } // namespace shell
488 } // namespace mojo 410 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698