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/browser/service_manager/service_manager_context.h" | 5 #include "content/browser/service_manager/service_manager_context.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS | 109 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
110 | 110 |
111 // A ManifestProvider which resolves application names to builtin manifest | 111 // A ManifestProvider which resolves application names to builtin manifest |
112 // resources for the catalog service to consume. | 112 // resources for the catalog service to consume. |
113 class BuiltinManifestProvider : public catalog::ManifestProvider { | 113 class BuiltinManifestProvider : public catalog::ManifestProvider { |
114 public: | 114 public: |
115 BuiltinManifestProvider() {} | 115 BuiltinManifestProvider() {} |
116 ~BuiltinManifestProvider() override {} | 116 ~BuiltinManifestProvider() override {} |
117 | 117 |
118 void AddManifestValue(const std::string& name, | 118 void AddServiceManifest(std::string name, int resource_id) { |
119 std::unique_ptr<base::Value> manifest_contents) { | 119 std::string contents = |
| 120 GetContentClient() |
| 121 ->GetDataResource(resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE) |
| 122 .as_string(); |
| 123 DCHECK(!contents.empty()); |
| 124 |
| 125 std::unique_ptr<base::Value> manifest_value = |
| 126 base::JSONReader::Read(contents); |
| 127 DCHECK(manifest_value); |
| 128 |
| 129 std::unique_ptr<base::Value> overlay_value = |
| 130 GetContentClient()->browser()->GetServiceManifestOverlay(name); |
| 131 if (overlay_value) { |
| 132 base::DictionaryValue* manifest_dictionary = nullptr; |
| 133 bool result = manifest_value->GetAsDictionary(&manifest_dictionary); |
| 134 DCHECK(result); |
| 135 base::DictionaryValue* overlay_dictionary = nullptr; |
| 136 result = overlay_value->GetAsDictionary(&overlay_dictionary); |
| 137 DCHECK(result); |
| 138 MergeDictionary(manifest_dictionary, overlay_dictionary); |
| 139 } |
| 140 |
120 auto result = manifests_.insert( | 141 auto result = manifests_.insert( |
121 std::make_pair(name, std::move(manifest_contents))); | 142 std::make_pair(std::move(name), std::move(manifest_value))); |
122 DCHECK(result.second) << "Duplicate manifest entry: " << name; | 143 DCHECK(result.second) << "Duplicate manifest entry: " << name; |
123 } | 144 } |
124 | 145 |
125 private: | 146 private: |
126 // catalog::ManifestProvider: | 147 // catalog::ManifestProvider: |
127 std::unique_ptr<base::Value> GetManifest(const std::string& name) override { | 148 std::unique_ptr<base::Value> GetManifest(const std::string& name) override { |
128 auto it = manifests_.find(name); | 149 auto it = manifests_.find(name); |
129 return it != manifests_.end() ? it->second->CreateDeepCopy() : nullptr; | 150 return it != manifests_.end() ? it->second->CreateDeepCopy() : nullptr; |
130 } | 151 } |
131 | 152 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 { mojom::kBrowserServiceName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, | 237 { mojom::kBrowserServiceName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, |
217 { mojom::kGpuServiceName, IDR_MOJO_CONTENT_GPU_MANIFEST }, | 238 { mojom::kGpuServiceName, IDR_MOJO_CONTENT_GPU_MANIFEST }, |
218 { mojom::kPluginServiceName, IDR_MOJO_CONTENT_PLUGIN_MANIFEST }, | 239 { mojom::kPluginServiceName, IDR_MOJO_CONTENT_PLUGIN_MANIFEST }, |
219 { mojom::kRendererServiceName, IDR_MOJO_CONTENT_RENDERER_MANIFEST }, | 240 { mojom::kRendererServiceName, IDR_MOJO_CONTENT_RENDERER_MANIFEST }, |
220 { mojom::kUtilityServiceName, IDR_MOJO_CONTENT_UTILITY_MANIFEST }, | 241 { mojom::kUtilityServiceName, IDR_MOJO_CONTENT_UTILITY_MANIFEST }, |
221 { catalog::mojom::kServiceName, IDR_MOJO_CATALOG_MANIFEST }, | 242 { catalog::mojom::kServiceName, IDR_MOJO_CATALOG_MANIFEST }, |
222 { file::mojom::kServiceName, IDR_MOJO_FILE_MANIFEST } | 243 { file::mojom::kServiceName, IDR_MOJO_FILE_MANIFEST } |
223 }; | 244 }; |
224 | 245 |
225 for (size_t i = 0; i < arraysize(kManifests); ++i) { | 246 for (size_t i = 0; i < arraysize(kManifests); ++i) { |
226 std::string contents = GetContentClient()->GetDataResource( | 247 manifest_provider->AddServiceManifest(kManifests[i].name, |
227 kManifests[i].resource_id, | 248 kManifests[i].resource_id); |
228 ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); | 249 } |
229 base::debug::Alias(&i); | 250 for (const auto& manifest : |
230 CHECK(!contents.empty()); | 251 GetContentClient()->browser()->GetExtraServiceManifests()) { |
231 | 252 manifest_provider->AddServiceManifest(std::move(manifest.name), |
232 std::unique_ptr<base::Value> manifest_value = | 253 manifest.resource_id); |
233 base::JSONReader::Read(contents); | |
234 base::debug::Alias(&contents); | |
235 CHECK(manifest_value); | |
236 | |
237 std::unique_ptr<base::Value> overlay_value = | |
238 GetContentClient()->browser()->GetServiceManifestOverlay( | |
239 kManifests[i].name); | |
240 if (overlay_value) { | |
241 base::DictionaryValue* manifest_dictionary = nullptr; | |
242 CHECK(manifest_value->GetAsDictionary(&manifest_dictionary)); | |
243 base::DictionaryValue* overlay_dictionary = nullptr; | |
244 CHECK(overlay_value->GetAsDictionary(&overlay_dictionary)); | |
245 MergeDictionary(manifest_dictionary, overlay_dictionary); | |
246 } | |
247 | |
248 manifest_provider->AddManifestValue(kManifests[i].name, | |
249 std::move(manifest_value)); | |
250 } | 254 } |
251 in_process_context_ = new InProcessServiceManagerContext; | 255 in_process_context_ = new InProcessServiceManagerContext; |
252 request = in_process_context_->Start(std::move(manifest_provider)); | 256 request = in_process_context_->Start(std::move(manifest_provider)); |
253 } | 257 } |
254 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | 258 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( |
255 std::move(request), | 259 std::move(request), |
256 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 260 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
257 | 261 |
258 ContentBrowserClient::StaticServiceMap services; | 262 ContentBrowserClient::StaticServiceMap services; |
259 GetContentClient()->browser()->RegisterInProcessServices(&services); | 263 GetContentClient()->browser()->RegisterInProcessServices(&services); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 base::Bind(&DestroyConnectorOnIOThread)); | 315 base::Bind(&DestroyConnectorOnIOThread)); |
312 } | 316 } |
313 | 317 |
314 // static | 318 // static |
315 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 319 service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
317 return g_io_thread_connector.Get().get(); | 321 return g_io_thread_connector.Get().get(); |
318 } | 322 } |
319 | 323 |
320 } // namespace content | 324 } // namespace content |
OLD | NEW |