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
3 // found in the LICENSE file.
5 #include "content/utility/utility_process_control_impl.h"
8 #include "base/stl_util.h"
9 #include "content/public/common/content_client.h"
10 #include "content/public/utility/content_utility_client.h"
11 #include "content/public/utility/utility_thread.h"
12 #include "mojo/shell/static_application_loader.h"
19 // Called when a static application terminates.
21 UtilityThread::Get()->ReleaseProcessIfNeeded();
26 UtilityProcessControlImpl::UtilityProcessControlImpl() {
27 ContentUtilityClient::StaticMojoApplicationMap apps
;
28 GetContentClient()->utility()->RegisterMojoApplications(&apps
);
29 for (const auto& entry
: apps
) {
30 url_to_loader_map_
[entry
.first
] = new mojo::shell::StaticApplicationLoader(
31 entry
.second
, base::Bind(&QuitProcess
));
35 UtilityProcessControlImpl::~UtilityProcessControlImpl() {
36 STLDeleteValues(&url_to_loader_map_
);
39 void UtilityProcessControlImpl::LoadApplication(
40 const mojo::String
& url
,
41 mojo::InterfaceRequest
<mojo::Application
> request
,
42 const LoadApplicationCallback
& callback
) {
43 GURL application_url
= GURL(url
.To
<std::string
>());
44 auto it
= url_to_loader_map_
.find(application_url
);
45 if (it
== url_to_loader_map_
.end()) {
51 it
->second
->Load(application_url
, request
.Pass());
54 } // namespace content