Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: content/child/indexed_db/indexed_db_key_builders.cc

Issue 2537953003: WebString: makes string16 conversions explicit (part 1: blink, content) (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/child/indexed_db/indexed_db_key_builders.h" 5 #include "content/child/indexed_db/indexed_db_key_builders.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "third_party/WebKit/public/platform/StringVectorCopier.h"
14 #include "third_party/WebKit/public/platform/WebVector.h" 15 #include "third_party/WebKit/public/platform/WebVector.h"
15 16
16 using blink::WebIDBKey; 17 using blink::WebIDBKey;
17 using blink::WebIDBKeyRange; 18 using blink::WebIDBKeyRange;
18 using blink::WebIDBKeyTypeArray; 19 using blink::WebIDBKeyTypeArray;
19 using blink::WebIDBKeyTypeBinary; 20 using blink::WebIDBKeyTypeBinary;
20 using blink::WebIDBKeyTypeDate; 21 using blink::WebIDBKeyTypeDate;
21 using blink::WebIDBKeyTypeInvalid; 22 using blink::WebIDBKeyTypeInvalid;
22 using blink::WebIDBKeyTypeMin; 23 using blink::WebIDBKeyTypeMin;
23 using blink::WebIDBKeyTypeNull; 24 using blink::WebIDBKeyTypeNull;
24 using blink::WebIDBKeyTypeNumber; 25 using blink::WebIDBKeyTypeNumber;
25 using blink::WebIDBKeyTypeString; 26 using blink::WebIDBKeyTypeString;
26 using blink::WebVector; 27 using blink::WebVector;
27 using blink::WebString; 28 using blink::WebString;
28 29
29 static content::IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) { 30 static content::IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) {
30 content::IndexedDBKey::KeyArray result; 31 content::IndexedDBKey::KeyArray result;
31 if (other.keyType() == WebIDBKeyTypeArray) { 32 if (other.keyType() == WebIDBKeyTypeArray) {
32 const WebVector<WebIDBKey>& array = other.array(); 33 const WebVector<WebIDBKey>& array = other.array();
33 for (size_t i = 0; i < array.size(); ++i) 34 for (size_t i = 0; i < array.size(); ++i)
34 result.push_back(content::IndexedDBKeyBuilder::Build(array[i])); 35 result.push_back(content::IndexedDBKeyBuilder::Build(array[i]));
35 } 36 }
36 return result; 37 return result;
37 } 38 }
38 39
39 static std::vector<base::string16> CopyArray( 40 static std::vector<base::string16> CopyArray(
40 const WebVector<WebString>& array) { 41 const WebVector<WebString>& array) {
41 std::vector<base::string16> copy(array.size()); 42 std::vector<base::string16> copy(array.size());
42 for (size_t i = 0; i < array.size(); ++i) 43 for (size_t i = 0; i < array.size(); ++i)
43 copy[i] = array[i]; 44 copy[i] = array[i].utf16();
44 return copy; 45 return copy;
45 } 46 }
46 47
47
48 namespace content { 48 namespace content {
49 49
50 IndexedDBKey IndexedDBKeyBuilder::Build(const blink::WebIDBKey& key) { 50 IndexedDBKey IndexedDBKeyBuilder::Build(const blink::WebIDBKey& key) {
51 switch (key.keyType()) { 51 switch (key.keyType()) {
52 case WebIDBKeyTypeArray: 52 case WebIDBKeyTypeArray:
53 return IndexedDBKey(CopyKeyArray(key)); 53 return IndexedDBKey(CopyKeyArray(key));
54 case WebIDBKeyTypeBinary: 54 case WebIDBKeyTypeBinary:
55 return IndexedDBKey( 55 return IndexedDBKey(
56 std::string(key.binary().data(), key.binary().size())); 56 std::string(key.binary().data(), key.binary().size()));
57 case WebIDBKeyTypeString: 57 case WebIDBKeyTypeString:
58 return IndexedDBKey(key.string()); 58 return IndexedDBKey(key.string().utf16());
59 case WebIDBKeyTypeDate: 59 case WebIDBKeyTypeDate:
60 return IndexedDBKey(key.date(), WebIDBKeyTypeDate); 60 return IndexedDBKey(key.date(), WebIDBKeyTypeDate);
61 case WebIDBKeyTypeNumber: 61 case WebIDBKeyTypeNumber:
62 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber); 62 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber);
63 case WebIDBKeyTypeNull: 63 case WebIDBKeyTypeNull:
64 case WebIDBKeyTypeInvalid: 64 case WebIDBKeyTypeInvalid:
65 return IndexedDBKey(key.keyType()); 65 return IndexedDBKey(key.keyType());
66 case WebIDBKeyTypeMin: 66 case WebIDBKeyTypeMin:
67 default: 67 default:
68 NOTREACHED(); 68 NOTREACHED();
69 return IndexedDBKey(); 69 return IndexedDBKey();
70 } 70 }
71 } 71 }
72 72
73 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { 73 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) {
74 switch (key.type()) { 74 switch (key.type()) {
75 case WebIDBKeyTypeArray: { 75 case WebIDBKeyTypeArray: {
76 const IndexedDBKey::KeyArray& array = key.array(); 76 const IndexedDBKey::KeyArray& array = key.array();
77 blink::WebVector<WebIDBKey> web_array(array.size()); 77 blink::WebVector<WebIDBKey> web_array(array.size());
78 for (size_t i = 0; i < array.size(); ++i) { 78 for (size_t i = 0; i < array.size(); ++i) {
79 web_array[i] = Build(array[i]); 79 web_array[i] = Build(array[i]);
80 } 80 }
81 return WebIDBKey::createArray(web_array); 81 return WebIDBKey::createArray(web_array);
82 } 82 }
83 case WebIDBKeyTypeBinary: 83 case WebIDBKeyTypeBinary:
84 return WebIDBKey::createBinary(key.binary()); 84 return WebIDBKey::createBinary(key.binary());
85 case WebIDBKeyTypeString: 85 case WebIDBKeyTypeString:
86 return WebIDBKey::createString(key.string()); 86 return WebIDBKey::createString(WebString::fromUTF16(key.string()));
87 case WebIDBKeyTypeDate: 87 case WebIDBKeyTypeDate:
88 return WebIDBKey::createDate(key.date()); 88 return WebIDBKey::createDate(key.date());
89 case WebIDBKeyTypeNumber: 89 case WebIDBKeyTypeNumber:
90 return WebIDBKey::createNumber(key.number()); 90 return WebIDBKey::createNumber(key.number());
91 case WebIDBKeyTypeInvalid: 91 case WebIDBKeyTypeInvalid:
92 return WebIDBKey::createInvalid(); 92 return WebIDBKey::createInvalid();
93 case WebIDBKeyTypeNull: 93 case WebIDBKeyTypeNull:
94 return WebIDBKey::createNull(); 94 return WebIDBKey::createNull();
95 case WebIDBKeyTypeMin: 95 case WebIDBKeyTypeMin:
96 default: 96 default:
(...skipping 15 matching lines...) Expand all
112 const IndexedDBKeyRange& key_range) { 112 const IndexedDBKeyRange& key_range) {
113 return WebIDBKeyRange(WebIDBKeyBuilder::Build(key_range.lower()), 113 return WebIDBKeyRange(WebIDBKeyBuilder::Build(key_range.lower()),
114 WebIDBKeyBuilder::Build(key_range.upper()), 114 WebIDBKeyBuilder::Build(key_range.upper()),
115 key_range.lower_open(), key_range.upper_open()); 115 key_range.lower_open(), key_range.upper_open());
116 } 116 }
117 117
118 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build( 118 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build(
119 const blink::WebIDBKeyPath& key_path) { 119 const blink::WebIDBKeyPath& key_path) {
120 switch (key_path.keyPathType()) { 120 switch (key_path.keyPathType()) {
121 case blink::WebIDBKeyPathTypeString: 121 case blink::WebIDBKeyPathTypeString:
122 return IndexedDBKeyPath(key_path.string()); 122 return IndexedDBKeyPath(key_path.string().utf16());
123 case blink::WebIDBKeyPathTypeArray: 123 case blink::WebIDBKeyPathTypeArray:
124 return IndexedDBKeyPath(CopyArray(key_path.array())); 124 return IndexedDBKeyPath(CopyArray(key_path.array()));
125 case blink::WebIDBKeyPathTypeNull: 125 case blink::WebIDBKeyPathTypeNull:
126 return IndexedDBKeyPath(); 126 return IndexedDBKeyPath();
127 default: 127 default:
128 NOTREACHED(); 128 NOTREACHED();
129 return IndexedDBKeyPath(); 129 return IndexedDBKeyPath();
130 } 130 }
131 } 131 }
132 132
133 blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build( 133 blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build(
134 const IndexedDBKeyPath& key_path) { 134 const IndexedDBKeyPath& key_path) {
135 switch (key_path.type()) { 135 switch (key_path.type()) {
136 case blink::WebIDBKeyPathTypeString: 136 case blink::WebIDBKeyPathTypeString:
137 return blink::WebIDBKeyPath::create(WebString(key_path.string())); 137 return blink::WebIDBKeyPath::create(
138 WebString::fromUTF16(key_path.string()));
138 case blink::WebIDBKeyPathTypeArray: 139 case blink::WebIDBKeyPathTypeArray:
139 return blink::WebIDBKeyPath::create(CopyArray(key_path.array())); 140 return blink::WebIDBKeyPath::create(
141 blink::CopyStringVectorFromUTF16(key_path.array()));
140 case blink::WebIDBKeyPathTypeNull: 142 case blink::WebIDBKeyPathTypeNull:
141 return blink::WebIDBKeyPath::createNull(); 143 return blink::WebIDBKeyPath::createNull();
142 default: 144 default:
143 NOTREACHED(); 145 NOTREACHED();
144 return blink::WebIDBKeyPath::createNull(); 146 return blink::WebIDBKeyPath::createNull();
145 } 147 }
146 } 148 }
147 149
148 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_database_callbacks_impl.cc ('k') | content/child/indexed_db/webidbdatabase_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698