Attempt to clean up logoff/shutdown sad tabs.
[chromium-blink-merge.git] / content / utility / utility_process_control_impl.cc
blob5d12a2e7a714c7a03a775dc15e915f647af3f3e9
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"
7 #include "base/bind.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"
13 #include "url/gurl.h"
15 namespace content {
17 namespace {
19 // Called when a static application terminates.
20 void QuitProcess() {
21 UtilityThread::Get()->ReleaseProcessIfNeeded();
24 } // namespace
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()) {
46 callback.Run(false);
47 return;
50 callback.Run(true);
51 it->second->Load(application_url, request.Pass());
54 } // namespace content