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/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "content/public/common/static_mojo_application_loader.h" |
| 10 #include "content/public/utility/utility_thread.h" |
| 11 #include "mojo/application/public/cpp/application_delegate.h" |
| 12 #include "mojo/shell/application_loader.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Called when a static application terminates. |
| 19 void QuitProcess() { |
| 20 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 UtilityProcessControlImpl::UtilityProcessControlImpl() { |
| 26 } |
| 27 |
| 28 UtilityProcessControlImpl::~UtilityProcessControlImpl() { |
| 29 STLDeleteValues(&url_to_loader_map_); |
| 30 } |
| 31 |
| 32 void UtilityProcessControlImpl::LoadApplication( |
| 33 const mojo::String& url, |
| 34 mojo::InterfaceRequest<mojo::Application> request, |
| 35 const LoadApplicationCallback& callback) { |
| 36 GURL application_url = GURL(url.To<std::string>()); |
| 37 auto it = url_to_loader_map_.find(application_url); |
| 38 if (it == url_to_loader_map_.end()) { |
| 39 callback.Run(LOAD_APPLICATION_RESULT_NOT_FOUND); |
| 40 return; |
| 41 } |
| 42 |
| 43 callback.Run(LOAD_APPLICATION_RESULT_OK); |
| 44 it->second->Load(application_url, request.Pass()); |
| 45 } |
| 46 |
| 47 void UtilityProcessControlImpl::RegisterStaticAppForURL( |
| 48 const GURL& url, |
| 49 const StaticAppFactory& factory) { |
| 50 auto result = url_to_loader_map_.insert(std::make_pair( |
| 51 url, |
| 52 // Cleaned up in ~UtilityProcessControlImp. |
| 53 new StaticMojoApplicationLoader(factory, base::Bind(&QuitProcess)))); |
| 54 DCHECK(result.second); |
| 55 } |
| 56 |
| 57 } // namespace content |
OLD | NEW |