OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/child/indexed_db/indexed_db_key_builders.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/platform/WebVector.h" |
| 9 |
| 10 using WebKit::WebIDBKey; |
| 11 using WebKit::WebIDBKeyRange; |
| 12 using WebKit::WebIDBKeyTypeArray; |
| 13 using WebKit::WebIDBKeyTypeDate; |
| 14 using WebKit::WebIDBKeyTypeInvalid; |
| 15 using WebKit::WebIDBKeyTypeMin; |
| 16 using WebKit::WebIDBKeyTypeNull; |
| 17 using WebKit::WebIDBKeyTypeNumber; |
| 18 using WebKit::WebIDBKeyTypeString; |
| 19 using WebKit::WebVector; |
| 20 using WebKit::WebString; |
| 21 |
| 22 static content::IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) { |
| 23 content::IndexedDBKey::KeyArray result; |
| 24 if (other.keyType() == WebIDBKeyTypeArray) { |
| 25 const WebVector<WebIDBKey>& array = other.array(); |
| 26 for (size_t i = 0; i < array.size(); ++i) |
| 27 result.push_back(content::IndexedDBKeyBuilder::Build(array[i])); |
| 28 } |
| 29 return result; |
| 30 } |
| 31 |
| 32 static std::vector<string16> CopyArray( |
| 33 const WebVector<WebString>& array) { |
| 34 std::vector<string16> copy(array.size()); |
| 35 for (size_t i = 0; i < array.size(); ++i) |
| 36 copy[i] = array[i]; |
| 37 return copy; |
| 38 } |
| 39 |
| 40 |
| 41 namespace content { |
| 42 |
| 43 IndexedDBKey IndexedDBKeyBuilder::Build(const WebKit::WebIDBKey& key) { |
| 44 switch (key.keyType()) { |
| 45 case WebIDBKeyTypeArray: |
| 46 return IndexedDBKey(CopyKeyArray(key)); |
| 47 case WebIDBKeyTypeString: |
| 48 return IndexedDBKey(key.string()); |
| 49 case WebIDBKeyTypeDate: |
| 50 return IndexedDBKey(key.date(), WebIDBKeyTypeDate); |
| 51 case WebIDBKeyTypeNumber: |
| 52 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber); |
| 53 case WebIDBKeyTypeNull: |
| 54 case WebIDBKeyTypeInvalid: |
| 55 return IndexedDBKey(key.keyType()); |
| 56 case WebIDBKeyTypeMin: |
| 57 NOTREACHED(); |
| 58 return IndexedDBKey(); |
| 59 } |
| 60 NOTREACHED(); |
| 61 return IndexedDBKey(); |
| 62 } |
| 63 |
| 64 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { |
| 65 switch (key.type()) { |
| 66 case WebIDBKeyTypeArray: { |
| 67 const IndexedDBKey::KeyArray& array = key.array(); |
| 68 WebKit::WebVector<WebIDBKey> web_array(array.size()); |
| 69 for (size_t i = 0; i < array.size(); ++i) { |
| 70 web_array[i] = Build(array[i]); |
| 71 } |
| 72 return WebIDBKey::createArray(web_array); |
| 73 } |
| 74 case WebIDBKeyTypeString: |
| 75 return WebIDBKey::createString(key.string()); |
| 76 case WebIDBKeyTypeDate: |
| 77 return WebIDBKey::createDate(key.date()); |
| 78 case WebIDBKeyTypeNumber: |
| 79 return WebIDBKey::createNumber(key.number()); |
| 80 case WebIDBKeyTypeInvalid: |
| 81 return WebIDBKey::createInvalid(); |
| 82 case WebIDBKeyTypeNull: |
| 83 return WebIDBKey::createNull(); |
| 84 case WebIDBKeyTypeMin: |
| 85 NOTREACHED(); |
| 86 return WebIDBKey::createInvalid(); |
| 87 } |
| 88 NOTREACHED(); |
| 89 return WebIDBKey::createInvalid(); |
| 90 } |
| 91 |
| 92 IndexedDBKeyRange IndexedDBKeyRangeBuilder::Build( |
| 93 const WebIDBKeyRange& key_range) { |
| 94 return IndexedDBKeyRange( |
| 95 IndexedDBKeyBuilder::Build(key_range.lower()), |
| 96 IndexedDBKeyBuilder::Build(key_range.upper()), |
| 97 key_range.lowerOpen(), |
| 98 key_range.upperOpen()); |
| 99 } |
| 100 |
| 101 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build( |
| 102 const WebKit::WebIDBKeyPath& key_path) { |
| 103 switch (key_path.keyPathType()) { |
| 104 case WebKit::WebIDBKeyPathTypeString: |
| 105 return IndexedDBKeyPath(key_path.string()); |
| 106 case WebKit::WebIDBKeyPathTypeArray: |
| 107 return IndexedDBKeyPath(CopyArray(key_path.array())); |
| 108 case WebKit::WebIDBKeyPathTypeNull: |
| 109 return IndexedDBKeyPath(); |
| 110 } |
| 111 NOTREACHED(); |
| 112 return IndexedDBKeyPath(); |
| 113 } |
| 114 |
| 115 WebKit::WebIDBKeyPath WebIDBKeyPathBuilder::Build( |
| 116 const IndexedDBKeyPath& key_path) { |
| 117 switch (key_path.type()) { |
| 118 case WebKit::WebIDBKeyPathTypeString: |
| 119 return WebKit::WebIDBKeyPath::create(WebString(key_path.string())); |
| 120 case WebKit::WebIDBKeyPathTypeArray: |
| 121 return WebKit::WebIDBKeyPath::create(CopyArray(key_path.array())); |
| 122 case WebKit::WebIDBKeyPathTypeNull: |
| 123 return WebKit::WebIDBKeyPath::createNull(); |
| 124 } |
| 125 NOTREACHED(); |
| 126 return WebKit::WebIDBKeyPath::createNull(); |
| 127 } |
| 128 |
| 129 } // namespace content |
OLD | NEW |