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/mojo/mojo_shell_context.h" | 5 #include "content/browser/mojo/mojo_shell_context.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_reader.h" | |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "content/browser/gpu/gpu_process_host.h" | 17 #include "content/browser/gpu/gpu_process_host.h" |
17 #include "content/common/mojo/constants.h" | 18 #include "content/common/mojo/constants.h" |
18 #include "content/common/mojo/mojo_shell_connection_impl.h" | 19 #include "content/common/mojo/mojo_shell_connection_impl.h" |
19 #include "content/grit/content_resources.h" | 20 #include "content/grit/content_resources.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 shell::mojom::ServiceFactoryPtr service_factory; | 95 shell::mojom::ServiceFactoryPtr service_factory; |
95 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
96 BrowserThread::IO, FROM_HERE, | 97 BrowserThread::IO, FROM_HERE, |
97 base::Bind(&RequestGpuServiceFactory, | 98 base::Bind(&RequestGpuServiceFactory, |
98 base::Passed(GetProxy(&service_factory)))); | 99 base::Passed(GetProxy(&service_factory)))); |
99 service_factory->CreateService(std::move(request), service_name); | 100 service_factory->CreateService(std::move(request), service_name); |
100 } | 101 } |
101 | 102 |
102 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS | 103 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
103 | 104 |
105 void MergeDictionary(base::DictionaryValue* target, | |
Tom Sepez
2016/09/12 16:53:16
Nit: Maybe this should be a base::DictionaryValue
Tom Sepez
2016/09/12 16:54:27
Can we write a unit test for this? Might be easie
| |
106 const base::DictionaryValue* source) { | |
107 for (base::DictionaryValue::Iterator it(*source); !it.IsAtEnd(); | |
108 it.Advance()) { | |
109 const base::Value* merge_value = &it.value(); | |
110 // Check whether we have to merge dictionaries. | |
111 if (merge_value->IsType(base::Value::TYPE_DICTIONARY)) { | |
112 base::DictionaryValue* sub_dict; | |
113 if (target->GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) { | |
114 MergeDictionary( | |
115 sub_dict, | |
116 static_cast<const base::DictionaryValue*>(merge_value)); | |
117 continue; | |
118 } | |
119 } | |
120 if (merge_value->IsType(base::Value::TYPE_LIST)) { | |
121 const base::ListValue* merge_list = nullptr; | |
122 if (merge_value->GetAsList(&merge_list)) { | |
123 base::ListValue* target_list = nullptr; | |
124 DCHECK(target->GetListWithoutPathExpansion(it.key(), &target_list)); | |
125 for (size_t k = 0; k < target_list->GetSize(); ++k) { | |
126 std::string value; | |
127 DCHECK(target_list->GetString(k, &value)); | |
128 } | |
129 for (size_t i = 0; i < merge_list->GetSize(); ++i) { | |
130 std::string value; | |
131 DCHECK(merge_list->GetString(i, &value)); | |
132 target_list->AppendString(value); | |
133 } | |
134 } | |
135 } else { | |
136 // All other cases: Make a copy and hook it up. | |
137 target->SetWithoutPathExpansion(it.key(), merge_value->DeepCopy()); | |
138 } | |
139 } | |
140 } | |
141 | |
104 // A ManifestProvider which resolves application names to builtin manifest | 142 // A ManifestProvider which resolves application names to builtin manifest |
105 // resources for the catalog service to consume. | 143 // resources for the catalog service to consume. |
106 class BuiltinManifestProvider : public catalog::ManifestProvider { | 144 class BuiltinManifestProvider : public catalog::ManifestProvider { |
107 public: | 145 public: |
108 BuiltinManifestProvider() {} | 146 BuiltinManifestProvider() {} |
109 ~BuiltinManifestProvider() override {} | 147 ~BuiltinManifestProvider() override {} |
110 | 148 |
111 void AddManifests(std::unique_ptr< | 149 void AddManifests(std::unique_ptr< |
112 ContentBrowserClient::MojoApplicationManifestMap> manifests) { | 150 ContentBrowserClient::MojoApplicationManifestMap> manifests) { |
113 DCHECK(!manifests_); | 151 DCHECK(!manifests_); |
114 manifests_ = std::move(manifests); | 152 manifests_ = std::move(manifests); |
115 } | 153 } |
116 | 154 |
117 void AddManifestResource(const std::string& name, int resource_id) { | 155 void AddManifestResource(const std::string& name, int resource_id) { |
118 std::string contents = GetContentClient()->GetDataResource( | 156 std::string contents = GetContentClient()->GetDataResource( |
119 resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); | 157 resource_id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); |
120 DCHECK(!contents.empty()); | 158 DCHECK(!contents.empty()); |
121 | 159 |
122 DCHECK(manifests_); | 160 DCHECK(manifests_); |
123 auto result = manifests_->insert(std::make_pair(name, contents)); | 161 auto result = manifests_->insert(std::make_pair(name, contents)); |
124 DCHECK(result.second) << "Duplicate manifest entry: " << name; | 162 DCHECK(result.second) << "Duplicate manifest entry: " << name; |
125 } | 163 } |
126 | 164 |
127 private: | 165 private: |
128 // catalog::ManifestProvider: | 166 // catalog::ManifestProvider: |
129 bool GetApplicationManifest(const base::StringPiece& name, | 167 std::unique_ptr<base::Value> GetManifest(const std::string& name) override { |
130 std::string* manifest_contents) override { | 168 auto manifest_it = manifests_->find(name); |
131 auto manifest_it = manifests_->find(name.as_string()); | 169 std::unique_ptr<base::Value> manifest_root; |
132 if (manifest_it != manifests_->end()) { | 170 if (manifest_it != manifests_->end()) |
133 *manifest_contents = manifest_it->second; | 171 manifest_root = base::JSONReader::Read(manifest_it->second); |
134 DCHECK(!manifest_contents->empty()); | 172 |
135 return true; | 173 base::DictionaryValue* manifest_dictionary = nullptr; |
174 if (manifest_root && !manifest_root->GetAsDictionary(&manifest_dictionary)) | |
175 return nullptr; | |
176 | |
177 std::unique_ptr<base::Value> overlay_root = | |
178 GetContentClient()->browser()->GetServiceManifestOverlay(name); | |
179 if (overlay_root) { | |
180 if (!manifest_root) { | |
181 manifest_root = std::move(overlay_root); | |
182 } else { | |
183 base::DictionaryValue* overlay_dictionary = nullptr; | |
184 if (overlay_root->GetAsDictionary(&overlay_dictionary)) | |
185 MergeDictionary(manifest_dictionary, overlay_dictionary); | |
186 } | |
136 } | 187 } |
137 return false; | 188 return manifest_root; |
138 } | 189 } |
139 | 190 |
140 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; | 191 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; |
141 | 192 |
142 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); | 193 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); |
143 }; | 194 }; |
144 | 195 |
145 } // namespace | 196 } // namespace |
146 | 197 |
147 // State which lives on the IO thread and drives the ServiceManager. | 198 // State which lives on the IO thread and drives the ServiceManager. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 in_process_context_->ShutDown(); | 347 in_process_context_->ShutDown(); |
297 } | 348 } |
298 | 349 |
299 // static | 350 // static |
300 shell::Connector* MojoShellContext::GetConnectorForIOThread() { | 351 shell::Connector* MojoShellContext::GetConnectorForIOThread() { |
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
302 return g_io_thread_connector.Get().get(); | 353 return g_io_thread_connector.Get().get(); |
303 } | 354 } |
304 | 355 |
305 } // namespace content | 356 } // namespace content |
OLD | NEW |