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/child/process_control_impl.h" | 5 #include "content/child/process_control_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/bind.h" |
10 #include "content/common/mojo/static_loader.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "content/public/common/content_client.h" | 11 #include "content/public/common/content_client.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 ProcessControlImpl::ProcessControlImpl() { | 15 ProcessControlImpl::ProcessControlImpl() { |
16 } | 16 } |
17 | 17 |
18 ProcessControlImpl::~ProcessControlImpl() { | 18 ProcessControlImpl::~ProcessControlImpl() { |
19 STLDeleteValues(&name_to_loader_map_); | |
20 } | 19 } |
21 | 20 |
22 void ProcessControlImpl::LoadApplication( | 21 void ProcessControlImpl::LoadApplication( |
23 const mojo::String& name, | 22 const mojo::String& name, |
24 mojo::InterfaceRequest<shell::mojom::ShellClient> request, | 23 shell::mojom::ShellClientRequest request, |
25 const LoadApplicationCallback& callback) { | 24 const LoadApplicationCallback& callback) { |
26 // Only register loaders when we need it. | 25 // Only register apps on first run. |
27 if (!has_registered_loaders_) { | 26 if (!has_registered_apps_) { |
28 DCHECK(name_to_loader_map_.empty()); | 27 DCHECK(apps_.empty()); |
29 RegisterLoaders(&name_to_loader_map_); | 28 ApplicationFactoryMap app_factories; |
30 has_registered_loaders_ = true; | 29 RegisterApplicationFactories(&app_factories); |
| 30 for (const auto& factory : app_factories) { |
| 31 std::unique_ptr<EmbeddedApplicationRunner> runner( |
| 32 new EmbeddedApplicationRunner(factory.second, nullptr)); |
| 33 runner->SetQuitClosure(base::Bind(&ProcessControlImpl::OnApplicationQuit, |
| 34 base::Unretained(this))); |
| 35 apps_.insert(std::make_pair(factory.first, std::move(runner))); |
| 36 } |
| 37 has_registered_apps_ = true; |
31 } | 38 } |
32 | 39 |
33 auto it = name_to_loader_map_.find(name); | 40 auto it = apps_.find(name); |
34 if (it == name_to_loader_map_.end()) { | 41 if (it == apps_.end()) { |
35 callback.Run(false); | 42 callback.Run(false); |
36 OnLoadFailed(); | 43 OnLoadFailed(); |
37 return; | 44 return; |
38 } | 45 } |
39 | 46 |
40 callback.Run(true); | 47 callback.Run(true); |
41 it->second->Load(name, std::move(request)); | 48 it->second->BindShellClientRequest(std::move(request)); |
42 } | 49 } |
43 | 50 |
44 } // namespace content | 51 } // namespace content |
OLD | NEW |