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

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

Issue 2586483002: Use explicit WebString <-> string16 conversion methods in storage API files (Closed)
Patch Set: '' 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>
(...skipping 22 matching lines...) Expand all
33 for (size_t i = 0; i < array.size(); ++i) 33 for (size_t i = 0; i < array.size(); ++i)
34 result.push_back(content::IndexedDBKeyBuilder::Build(array[i])); 34 result.push_back(content::IndexedDBKeyBuilder::Build(array[i]));
35 } 35 }
36 return result; 36 return result;
37 } 37 }
38 38
39 static std::vector<base::string16> CopyArray( 39 static std::vector<base::string16> CopyArray(
40 const WebVector<WebString>& array) { 40 const WebVector<WebString>& array) {
41 std::vector<base::string16> copy(array.size()); 41 std::vector<base::string16> copy(array.size());
42 for (size_t i = 0; i < array.size(); ++i) 42 for (size_t i = 0; i < array.size(); ++i)
43 copy[i] = array[i]; 43 copy[i] = array[i].utf16();
44 return copy; 44 return copy;
45 } 45 }
46 46
47
48 namespace content { 47 namespace content {
49 48
50 IndexedDBKey IndexedDBKeyBuilder::Build(const blink::WebIDBKey& key) { 49 IndexedDBKey IndexedDBKeyBuilder::Build(const blink::WebIDBKey& key) {
51 switch (key.keyType()) { 50 switch (key.keyType()) {
52 case WebIDBKeyTypeArray: 51 case WebIDBKeyTypeArray:
53 return IndexedDBKey(CopyKeyArray(key)); 52 return IndexedDBKey(CopyKeyArray(key));
54 case WebIDBKeyTypeBinary: 53 case WebIDBKeyTypeBinary:
55 return IndexedDBKey( 54 return IndexedDBKey(
56 std::string(key.binary().data(), key.binary().size())); 55 std::string(key.binary().data(), key.binary().size()));
57 case WebIDBKeyTypeString: 56 case WebIDBKeyTypeString:
58 return IndexedDBKey(key.string()); 57 return IndexedDBKey(key.string().utf16());
59 case WebIDBKeyTypeDate: 58 case WebIDBKeyTypeDate:
60 return IndexedDBKey(key.date(), WebIDBKeyTypeDate); 59 return IndexedDBKey(key.date(), WebIDBKeyTypeDate);
61 case WebIDBKeyTypeNumber: 60 case WebIDBKeyTypeNumber:
62 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber); 61 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber);
63 case WebIDBKeyTypeNull: 62 case WebIDBKeyTypeNull:
64 case WebIDBKeyTypeInvalid: 63 case WebIDBKeyTypeInvalid:
65 return IndexedDBKey(key.keyType()); 64 return IndexedDBKey(key.keyType());
66 case WebIDBKeyTypeMin: 65 case WebIDBKeyTypeMin:
67 default: 66 default:
68 NOTREACHED(); 67 NOTREACHED();
69 return IndexedDBKey(); 68 return IndexedDBKey();
70 } 69 }
71 } 70 }
72 71
73 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { 72 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) {
74 switch (key.type()) { 73 switch (key.type()) {
75 case WebIDBKeyTypeArray: { 74 case WebIDBKeyTypeArray: {
76 const IndexedDBKey::KeyArray& array = key.array(); 75 const IndexedDBKey::KeyArray& array = key.array();
77 blink::WebVector<WebIDBKey> web_array(array.size()); 76 blink::WebVector<WebIDBKey> web_array(array.size());
78 for (size_t i = 0; i < array.size(); ++i) { 77 for (size_t i = 0; i < array.size(); ++i) {
79 web_array[i] = Build(array[i]); 78 web_array[i] = Build(array[i]);
80 } 79 }
81 return WebIDBKey::createArray(web_array); 80 return WebIDBKey::createArray(web_array);
82 } 81 }
83 case WebIDBKeyTypeBinary: 82 case WebIDBKeyTypeBinary:
84 return WebIDBKey::createBinary(key.binary()); 83 return WebIDBKey::createBinary(key.binary());
85 case WebIDBKeyTypeString: 84 case WebIDBKeyTypeString:
86 return WebIDBKey::createString(key.string()); 85 return WebIDBKey::createString(WebString::fromUTF16(key.string()));
87 case WebIDBKeyTypeDate: 86 case WebIDBKeyTypeDate:
88 return WebIDBKey::createDate(key.date()); 87 return WebIDBKey::createDate(key.date());
89 case WebIDBKeyTypeNumber: 88 case WebIDBKeyTypeNumber:
90 return WebIDBKey::createNumber(key.number()); 89 return WebIDBKey::createNumber(key.number());
91 case WebIDBKeyTypeInvalid: 90 case WebIDBKeyTypeInvalid:
92 return WebIDBKey::createInvalid(); 91 return WebIDBKey::createInvalid();
93 case WebIDBKeyTypeNull: 92 case WebIDBKeyTypeNull:
94 return WebIDBKey::createNull(); 93 return WebIDBKey::createNull();
95 case WebIDBKeyTypeMin: 94 case WebIDBKeyTypeMin:
96 default: 95 default:
(...skipping 15 matching lines...) Expand all
112 const IndexedDBKeyRange& key_range) { 111 const IndexedDBKeyRange& key_range) {
113 return WebIDBKeyRange(WebIDBKeyBuilder::Build(key_range.lower()), 112 return WebIDBKeyRange(WebIDBKeyBuilder::Build(key_range.lower()),
114 WebIDBKeyBuilder::Build(key_range.upper()), 113 WebIDBKeyBuilder::Build(key_range.upper()),
115 key_range.lower_open(), key_range.upper_open()); 114 key_range.lower_open(), key_range.upper_open());
116 } 115 }
117 116
118 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build( 117 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build(
119 const blink::WebIDBKeyPath& key_path) { 118 const blink::WebIDBKeyPath& key_path) {
120 switch (key_path.keyPathType()) { 119 switch (key_path.keyPathType()) {
121 case blink::WebIDBKeyPathTypeString: 120 case blink::WebIDBKeyPathTypeString:
122 return IndexedDBKeyPath(key_path.string()); 121 return IndexedDBKeyPath(key_path.string().utf16());
123 case blink::WebIDBKeyPathTypeArray: 122 case blink::WebIDBKeyPathTypeArray:
124 return IndexedDBKeyPath(CopyArray(key_path.array())); 123 return IndexedDBKeyPath(CopyArray(key_path.array()));
125 case blink::WebIDBKeyPathTypeNull: 124 case blink::WebIDBKeyPathTypeNull:
126 return IndexedDBKeyPath(); 125 return IndexedDBKeyPath();
127 default: 126 default:
128 NOTREACHED(); 127 NOTREACHED();
129 return IndexedDBKeyPath(); 128 return IndexedDBKeyPath();
130 } 129 }
131 } 130 }
132 131
133 blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build( 132 blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build(
134 const IndexedDBKeyPath& key_path) { 133 const IndexedDBKeyPath& key_path) {
135 switch (key_path.type()) { 134 switch (key_path.type()) {
136 case blink::WebIDBKeyPathTypeString: 135 case blink::WebIDBKeyPathTypeString:
137 return blink::WebIDBKeyPath::create(WebString(key_path.string())); 136 return blink::WebIDBKeyPath::create(
138 case blink::WebIDBKeyPathTypeArray: 137 WebString::fromUTF16(key_path.string()));
139 return blink::WebIDBKeyPath::create(CopyArray(key_path.array())); 138 case blink::WebIDBKeyPathTypeArray: {
139 WebVector<WebString> key_path_vector(key_path.array().size());
140 std::transform(key_path.array().begin(), key_path.array().end(),
141 key_path_vector.begin(),
142 [](const typename base::string16& s) {
143 return WebString::fromUTF16(s);
144 });
145 return blink::WebIDBKeyPath::create(key_path_vector);
146 }
140 case blink::WebIDBKeyPathTypeNull: 147 case blink::WebIDBKeyPathTypeNull:
141 return blink::WebIDBKeyPath::createNull(); 148 return blink::WebIDBKeyPath::createNull();
142 default: 149 default:
143 NOTREACHED(); 150 NOTREACHED();
144 return blink::WebIDBKeyPath::createNull(); 151 return blink::WebIDBKeyPath::createNull();
145 } 152 }
146 } 153 }
147 154
148 } // namespace content 155 } // 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