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 "chrome/utility/chrome_content_utility_process_impl.h" |
| 6 |
| 7 #include <list> |
| 8 #include <string> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
| 17 #include "base/stl_util.h" |
| 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/threading/thread.h" |
| 20 #include "chrome/common/application_urls.h" |
| 21 #include "components/proxy_resolver/proxy_resolver_app.h" |
| 22 #include "content/public/common/static_mojo_application_loader.h" |
| 23 #include "mojo/common/message_pump_mojo.h" |
| 24 #include "mojo/shell/application_loader.h" |
| 25 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.
h" |
| 26 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" |
| 27 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
| 28 #include "third_party/mojo/src/mojo/public/interfaces/application/application.mo
jom.h" |
| 29 |
| 30 namespace { |
| 31 |
| 32 template <typename DelegateType> |
| 33 scoped_ptr<mojo::ApplicationDelegate> CreateDelegate() { |
| 34 return scoped_ptr<mojo::ApplicationDelegate>(new DelegateType); |
| 35 } |
| 36 |
| 37 template <typename DelegateType> |
| 38 content::StaticMojoApplicationLoader::ApplicationFactory MakeStaticFactory() { |
| 39 return base::Bind(&CreateDelegate<DelegateType>); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 44 ChromeContentUtilityProcessImpl::ChromeContentUtilityProcessImpl() { |
| 45 RegisterApplication( |
| 46 GURL(application_urls::kProxyResolver), |
| 47 new content::StaticMojoApplicationLoader( |
| 48 application_urls::kProxyResolver, |
| 49 MakeStaticFactory<proxy_resolver::ProxyResolverApp>())); |
| 50 } |
| 51 |
| 52 ChromeContentUtilityProcessImpl::~ChromeContentUtilityProcessImpl() { |
| 53 STLDeleteValues(&url_to_loader_map_); |
| 54 } |
| 55 |
| 56 void ChromeContentUtilityProcessImpl::LoadApplication( |
| 57 const mojo::String& url, |
| 58 mojo::InterfaceRequest<mojo::Application> request, |
| 59 const LoadApplicationCallback& callback) { |
| 60 GURL application_url = GURL(url.To<std::string>()); |
| 61 auto it = url_to_loader_map_.find(application_url); |
| 62 if (it == url_to_loader_map_.end()) { |
| 63 callback.Run(content::LAUNCH_RESULT_NOT_FOUND); |
| 64 return; |
| 65 } |
| 66 it->second->Load(application_url, request.Pass()); |
| 67 callback.Run(content::LAUNCH_RESULT_OK); |
| 68 } |
| 69 |
| 70 void ChromeContentUtilityProcessImpl::RegisterApplication( |
| 71 const GURL& url, |
| 72 mojo::shell::ApplicationLoader* loader) { |
| 73 auto result = url_to_loader_map_.insert(std::make_pair(url, loader)); |
| 74 DCHECK(result.second); |
| 75 } |
OLD | NEW |