OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "content/browser/mojo/merge_dictionary.h" |
| 6 |
| 7 namespace content { |
| 8 |
| 9 void MergeDictionary(base::DictionaryValue* target, |
| 10 const base::DictionaryValue* source) { |
| 11 for (base::DictionaryValue::Iterator it(*source); !it.IsAtEnd(); |
| 12 it.Advance()) { |
| 13 const base::Value* merge_value = &it.value(); |
| 14 // Check whether we have to merge dictionaries. |
| 15 if (merge_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 16 base::DictionaryValue* sub_dict; |
| 17 if (target->GetDictionaryWithoutPathExpansion(it.key(), &sub_dict)) { |
| 18 MergeDictionary( |
| 19 sub_dict, |
| 20 static_cast<const base::DictionaryValue*>(merge_value)); |
| 21 continue; |
| 22 } |
| 23 } |
| 24 if (merge_value->IsType(base::Value::TYPE_LIST)) { |
| 25 const base::ListValue* merge_list = nullptr; |
| 26 if (merge_value->GetAsList(&merge_list)) { |
| 27 base::ListValue* target_list = nullptr; |
| 28 if (target->GetListWithoutPathExpansion(it.key(), &target_list)) { |
| 29 for (size_t i = 0; i < merge_list->GetSize(); ++i) { |
| 30 const base::Value* element = nullptr; |
| 31 CHECK(merge_list->Get(i, &element)); |
| 32 target_list->Append(element->CreateDeepCopy()); |
| 33 } |
| 34 continue; |
| 35 } |
| 36 } |
| 37 } |
| 38 // All other cases: Make a copy and hook it up. |
| 39 target->SetWithoutPathExpansion(it.key(), merge_value->DeepCopy()); |
| 40 } |
| 41 } |
| 42 |
| 43 } // namespace content |
OLD | NEW |