OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/utility/utility_process_control_impl.h" |
| 6 |
| 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" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Called when a static application terminates. |
| 20 void QuitProcess() { |
| 21 UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 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)); |
| 32 } |
| 33 } |
| 34 |
| 35 UtilityProcessControlImpl::~UtilityProcessControlImpl() { |
| 36 STLDeleteValues(&url_to_loader_map_); |
| 37 } |
| 38 |
| 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; |
| 48 } |
| 49 |
| 50 callback.Run(true); |
| 51 it->second->Load(application_url, request.Pass()); |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |