| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "content/utility/utility_process_control_impl.h" | 5 #include "content/utility/utility_process_control_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | |
| 9 #include "content/public/common/content_client.h" | 8 #include "content/public/common/content_client.h" |
| 10 #include "content/public/utility/content_utility_client.h" | 9 #include "content/public/utility/content_utility_client.h" |
| 11 #include "content/public/utility/utility_thread.h" | 10 #include "content/public/utility/utility_thread.h" |
| 12 #include "mojo/shell/static_application_loader.h" | 11 #include "mojo/shell/static_application_loader.h" |
| 13 #include "url/gurl.h" | |
| 14 | 12 |
| 15 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS) | 13 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS) |
| 16 #include "media/mojo/services/mojo_media_application.h" | 14 #include "media/mojo/services/mojo_media_application.h" |
| 17 #endif | 15 #endif |
| 18 | 16 |
| 19 namespace content { | 17 namespace content { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 // Called when a static application terminates. | 21 // Called when a static application terminates. |
| 24 void QuitProcess() { | 22 void QuitProcess() { |
| 25 UtilityThread::Get()->ReleaseProcessIfNeeded(); | 23 UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 26 } | 24 } |
| 27 | 25 |
| 28 } // namespace | 26 } // namespace |
| 29 | 27 |
| 30 UtilityProcessControlImpl::UtilityProcessControlImpl() { | 28 UtilityProcessControlImpl::UtilityProcessControlImpl() {} |
| 29 |
| 30 UtilityProcessControlImpl::~UtilityProcessControlImpl() {} |
| 31 |
| 32 void UtilityProcessControlImpl::RegisterApplicationLoaders( |
| 33 URLToLoaderMap* url_to_loader_map) { |
| 34 URLToLoaderMap& map_ref = *url_to_loader_map; |
| 35 |
| 31 ContentUtilityClient::StaticMojoApplicationMap apps; | 36 ContentUtilityClient::StaticMojoApplicationMap apps; |
| 32 GetContentClient()->utility()->RegisterMojoApplications(&apps); | 37 GetContentClient()->utility()->RegisterMojoApplications(&apps); |
| 38 |
| 33 for (const auto& entry : apps) { | 39 for (const auto& entry : apps) { |
| 34 url_to_loader_map_[entry.first] = new mojo::shell::StaticApplicationLoader( | 40 map_ref[entry.first] = new mojo::shell::StaticApplicationLoader( |
| 35 entry.second, base::Bind(&QuitProcess)); | 41 entry.second, base::Bind(&QuitProcess)); |
| 36 } | 42 } |
| 37 | 43 |
| 38 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS) | 44 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS) |
| 39 url_to_loader_map_[media::MojoMediaApplication::AppUrl()] = | 45 map_ref[media::MojoMediaApplication::AppUrl()] = |
| 40 new mojo::shell::StaticApplicationLoader( | 46 new mojo::shell::StaticApplicationLoader( |
| 41 base::Bind(&media::MojoMediaApplication::CreateApp), | 47 base::Bind(&media::MojoMediaApplication::CreateApp), |
| 42 base::Bind(&QuitProcess)); | 48 base::Bind(&QuitProcess)); |
| 43 #endif | 49 #endif |
| 44 } | 50 } |
| 45 | 51 |
| 46 UtilityProcessControlImpl::~UtilityProcessControlImpl() { | |
| 47 STLDeleteValues(&url_to_loader_map_); | |
| 48 } | |
| 49 | |
| 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()) { | |
| 57 callback.Run(false); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 callback.Run(true); | |
| 62 it->second->Load(application_url, request.Pass()); | |
| 63 } | |
| 64 | |
| 65 } // namespace content | 52 } // namespace content |
| OLD | NEW |