Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "mojo/public/cpp/bindings/map_traits.h" | 9 #include "mojo/public/cpp/bindings/map_traits.h" |
| 10 #include "third_party/WebKit/Source/wtf/HashMap.h" | 10 #include "third_party/WebKit/Source/wtf/HashMap.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 static void AdvanceIterator(ConstIterator& iterator) { ++iterator; } | 40 static void AdvanceIterator(ConstIterator& iterator) { ++iterator; } |
| 41 static void AdvanceIterator(Iterator& iterator) { ++iterator; } | 41 static void AdvanceIterator(Iterator& iterator) { ++iterator; } |
| 42 | 42 |
| 43 static const K& GetKey(Iterator& iterator) { return iterator->key; } | 43 static const K& GetKey(Iterator& iterator) { return iterator->key; } |
| 44 static const K& GetKey(ConstIterator& iterator) { return iterator->key; } | 44 static const K& GetKey(ConstIterator& iterator) { return iterator->key; } |
| 45 | 45 |
| 46 static V& GetValue(Iterator& iterator) { return iterator->value; } | 46 static V& GetValue(Iterator& iterator) { return iterator->value; } |
| 47 static const V& GetValue(ConstIterator& iterator) { return iterator->value; } | 47 static const V& GetValue(ConstIterator& iterator) { return iterator->value; } |
| 48 | 48 |
| 49 static bool Insert(WTF::HashMap<K, V>& input, const K& key, V&& value) { | 49 template <typename IK, typename IV> |
| 50 static bool Insert(WTF::HashMap<K, V>& input, IK&& key, IV&& value) { | |
| 50 if (!WTF::HashMap<K, V>::isValidKey(key)) { | 51 if (!WTF::HashMap<K, V>::isValidKey(key)) { |
| 51 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key; | 52 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key; |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 input.add(key, std::forward<V>(value)); | 55 input.add(std::forward<IK>(key), std::forward<IV>(value)); |
| 55 return true; | 56 return true; |
| 56 } | 57 } |
| 57 static bool Insert(WTF::HashMap<K, V>& input, const K& key, const V& value) { | 58 static bool Insert(WTF::HashMap<K, V>& input, const K& key, const V& value) { |
|
yzshen1
2016/09/20 23:44:40
Do we still need this method?
tibell
2016/09/21 07:10:53
Done.
| |
| 58 if (!WTF::HashMap<K, V>::isValidKey(key)) { | 59 if (!WTF::HashMap<K, V>::isValidKey(key)) { |
| 59 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key; | 60 LOG(ERROR) << "The key value is disallowed by WTF::HashMap: " << key; |
| 60 return false; | 61 return false; |
| 61 } | 62 } |
| 62 input.add(key, value); | 63 input.add(key, value); |
| 63 return true; | 64 return true; |
| 64 } | 65 } |
| 65 | 66 |
| 66 static void SetToEmpty(WTF::HashMap<K, V>* output) { output->clear(); } | 67 static void SetToEmpty(WTF::HashMap<K, V>* output) { output->clear(); } |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 } // namespace mojo | 70 } // namespace mojo |
| 70 | 71 |
| 71 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ | 72 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_WTF_HASH_MAP_H_ |
| OLD | NEW |