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"
15 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS)
16 #include "media/mojo/services/mojo_media_application.h"
23 // Called when a static application terminates.
25 UtilityThread::Get()->ReleaseProcessIfNeeded();
30 UtilityProcessControlImpl::UtilityProcessControlImpl() {
31 ContentUtilityClient::StaticMojoApplicationMap apps
;
32 GetContentClient()->utility()->RegisterMojoApplications(&apps
);
33 for (const auto& entry
: apps
) {
34 url_to_loader_map_
[entry
.first
] = new mojo::shell::StaticApplicationLoader(
35 entry
.second
, base::Bind(&QuitProcess
));
38 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS)
39 url_to_loader_map_
[media::MojoMediaApplication::AppUrl()] =
40 new mojo::shell::StaticApplicationLoader(
41 base::Bind(&media::MojoMediaApplication::CreateApp
),
42 base::Bind(&QuitProcess
));
46 UtilityProcessControlImpl::~UtilityProcessControlImpl() {
47 STLDeleteValues(&url_to_loader_map_
);
50 void UtilityProcessControlImpl::LoadApplication(
51 const mojo::String
& url
,
52 mojo::InterfaceRequest
<mojo::Application
> request
,
53 const LoadApplicationCallback
& callback
) {
54 GURL application_url
= GURL(url
.To
<std::string
>());
55 auto it
= url_to_loader_map_
.find(application_url
);
56 if (it
== url_to_loader_map_
.end()) {
62 it
->second
->Load(application_url
, request
.Pass());
65 } // namespace content