Chromium Code Reviews| Index: content/browser/mojo/mojo_shell_context.cc |
| diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc |
| index 95f6ac6b7387649ffb331b67d0d9bda904edb547..f6757d37ee207a6bd4aad9311d78efc00c5737a5 100644 |
| --- a/content/browser/mojo/mojo_shell_context.cc |
| +++ b/content/browser/mojo/mojo_shell_context.cc |
| @@ -9,6 +9,7 @@ |
| #include <utility> |
| #include "base/bind.h" |
| +#include "base/json/json_reader.h" |
| #include "base/lazy_instance.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| @@ -101,6 +102,43 @@ void StartServiceInGpuProcess(const std::string& service_name, |
| #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
| +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
|
| + const base::DictionaryValue* source) { |
| + for (base::DictionaryValue::Iterator it(*source); !it.IsAtEnd(); |
| + it.Advance()) { |
| + const base::Value* merge_value = &it.value(); |
| + // Check whether we have to merge dictionaries. |
| + if (merge_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| + base::DictionaryValue* sub_dict; |
| + if (target->GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) { |
| + MergeDictionary( |
| + sub_dict, |
| + static_cast<const base::DictionaryValue*>(merge_value)); |
| + continue; |
| + } |
| + } |
| + if (merge_value->IsType(base::Value::TYPE_LIST)) { |
| + const base::ListValue* merge_list = nullptr; |
| + if (merge_value->GetAsList(&merge_list)) { |
| + base::ListValue* target_list = nullptr; |
| + DCHECK(target->GetListWithoutPathExpansion(it.key(), &target_list)); |
| + for (size_t k = 0; k < target_list->GetSize(); ++k) { |
| + std::string value; |
| + DCHECK(target_list->GetString(k, &value)); |
| + } |
| + for (size_t i = 0; i < merge_list->GetSize(); ++i) { |
| + std::string value; |
| + DCHECK(merge_list->GetString(i, &value)); |
| + target_list->AppendString(value); |
| + } |
| + } |
| + } else { |
| + // All other cases: Make a copy and hook it up. |
| + target->SetWithoutPathExpansion(it.key(), merge_value->DeepCopy()); |
| + } |
| + } |
| +} |
| + |
| // A ManifestProvider which resolves application names to builtin manifest |
| // resources for the catalog service to consume. |
| class BuiltinManifestProvider : public catalog::ManifestProvider { |
| @@ -126,15 +164,28 @@ class BuiltinManifestProvider : public catalog::ManifestProvider { |
| private: |
| // catalog::ManifestProvider: |
| - bool GetApplicationManifest(const base::StringPiece& name, |
| - std::string* manifest_contents) override { |
| - auto manifest_it = manifests_->find(name.as_string()); |
| - if (manifest_it != manifests_->end()) { |
| - *manifest_contents = manifest_it->second; |
| - DCHECK(!manifest_contents->empty()); |
| - return true; |
| + std::unique_ptr<base::Value> GetManifest(const std::string& name) override { |
| + auto manifest_it = manifests_->find(name); |
| + std::unique_ptr<base::Value> manifest_root; |
| + if (manifest_it != manifests_->end()) |
| + manifest_root = base::JSONReader::Read(manifest_it->second); |
| + |
| + base::DictionaryValue* manifest_dictionary = nullptr; |
| + if (manifest_root && !manifest_root->GetAsDictionary(&manifest_dictionary)) |
| + return nullptr; |
| + |
| + std::unique_ptr<base::Value> overlay_root = |
| + GetContentClient()->browser()->GetServiceManifestOverlay(name); |
| + if (overlay_root) { |
| + if (!manifest_root) { |
| + manifest_root = std::move(overlay_root); |
| + } else { |
| + base::DictionaryValue* overlay_dictionary = nullptr; |
| + if (overlay_root->GetAsDictionary(&overlay_dictionary)) |
| + MergeDictionary(manifest_dictionary, overlay_dictionary); |
| + } |
| } |
| - return false; |
| + return manifest_root; |
| } |
| std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; |