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

Side by Side Diff: content/common/indexed_db/indexed_db_struct_traits.cc

Issue 2509913002: Implement StructTraits for remaining IndexedDB IPC types. (Closed)
Patch Set: Created 4 years, 1 month 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 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 #include "content/common/indexed_db/indexed_db_param_traits.h" 5 #include "content/common/indexed_db/indexed_db_param_traits.h"
6 #include "content/common/indexed_db/indexed_db_struct_traits.h" 6 #include "content/common/indexed_db/indexed_db_struct_traits.h"
7 #include "mojo/common/common_custom_types_struct_traits.h" 7 #include "mojo/common/common_custom_types_struct_traits.h"
8 8
9 using content::IndexedDBKey;
10 using content::IndexedDBKeyPath;
11 using content::IndexedDBKeyRange;
12
9 namespace mojo { 13 namespace mojo {
10 14
11 // static 15 // static
16 indexed_db::mojom::KeyDataPtr
17 StructTraits<indexed_db::mojom::KeyDataView, IndexedDBKey>::data(
18 const IndexedDBKey& key) {
19 auto data = indexed_db::mojom::KeyData::New();
20 switch (key.type()) {
21 case blink::WebIDBKeyTypeInvalid:
jsbell 2016/11/17 04:32:42 I'd love to figure out where Invalid may be coming
22 data->set_other(indexed_db::mojom::DatalessKeyType::Invalid);
23 return data;
24 case blink::WebIDBKeyTypeArray:
25 data->set_key_array(key.array());
26 return data;
27 case blink::WebIDBKeyTypeBinary:
28 data->set_binary(std::vector<uint8_t>(
29 key.binary().data(), key.binary().data() + key.binary().size()));
30 return data;
31 case blink::WebIDBKeyTypeString:
32 data->set_string(key.string());
33 return data;
34 case blink::WebIDBKeyTypeDate:
35 data->set_date(key.date());
36 return data;
37 case blink::WebIDBKeyTypeNumber:
38 data->set_number(key.number());
39 return data;
40 case blink::WebIDBKeyTypeNull:
41 data->set_other(indexed_db::mojom::DatalessKeyType::Null);
42 return data;
43 case blink::WebIDBKeyTypeMin:
44 NOTREACHED();
45 return data;
46 }
47 }
48
49 // static
50 bool StructTraits<indexed_db::mojom::KeyDataView, IndexedDBKey>::Read(
51 indexed_db::mojom::KeyDataView data,
52 IndexedDBKey* out) {
53 indexed_db::mojom::KeyDataDataView data_view;
54 data.GetDataDataView(&data_view);
55
56 switch (data_view.tag()) {
57 case indexed_db::mojom::KeyDataDataView::Tag::KEY_ARRAY: {
58 std::vector<IndexedDBKey> array;
59 if (!data_view.ReadKeyArray(&array))
60 return false;
61 *out = IndexedDBKey(array);
62 return true;
63 }
64 case indexed_db::mojom::KeyDataDataView::Tag::BINARY: {
65 std::vector<uint8_t> binary;
66 if (!data_view.ReadBinary(&binary))
67 return false;
68 *out = IndexedDBKey(
69 std::string(binary.data(), binary.data() + binary.size()));
70 return true;
71 }
72 case indexed_db::mojom::KeyDataDataView::Tag::STRING: {
73 base::string16 string;
74 if (!data_view.ReadString(&string))
75 return false;
76 *out = IndexedDBKey(string);
77 return true;
78 }
79 case indexed_db::mojom::KeyDataDataView::Tag::DATE:
80 *out = IndexedDBKey(data_view.date(), blink::WebIDBKeyTypeDate);
81 return true;
82 case indexed_db::mojom::KeyDataDataView::Tag::NUMBER:
83 *out = IndexedDBKey(data_view.number(), blink::WebIDBKeyTypeNumber);
84 return true;
85 case indexed_db::mojom::KeyDataDataView::Tag::OTHER:
86 switch (data_view.other()) {
87 case indexed_db::mojom::DatalessKeyType::Invalid:
88 *out = IndexedDBKey(blink::WebIDBKeyTypeInvalid);
89 return true;
90 case indexed_db::mojom::DatalessKeyType::Null:
91 *out = IndexedDBKey(blink::WebIDBKeyTypeNull);
92 return true;
93 }
94 }
95
96 return false;
97 }
98
99 // static
100 indexed_db::mojom::KeyPathDataPtr
101 StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::data(
102 const IndexedDBKeyPath& key_path) {
103 if (key_path.IsNull())
104 return nullptr;
105
106 auto data = indexed_db::mojom::KeyPathData::New();
107 switch (key_path.type()) {
108 case blink::WebIDBKeyPathTypeString:
109 data->set_string(key_path.string());
110 return data;
111 case blink::WebIDBKeyPathTypeArray:
112 data->set_string_array(key_path.array());
113 return data;
114 default:
115 NOTREACHED();
116 return data;
117 }
118 }
119
120 // static
121 bool StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::Read(
122 indexed_db::mojom::KeyPathDataView data,
123 IndexedDBKeyPath* out) {
124 indexed_db::mojom::KeyPathDataDataView data_view;
125 data.GetDataDataView(&data_view);
126
127 if (data_view.is_null()) {
128 *out = IndexedDBKeyPath();
129 return true;
130 }
131
132 switch (data_view.tag()) {
133 case indexed_db::mojom::KeyPathDataDataView::Tag::STRING: {
134 base::string16 string;
135 if (!data_view.ReadString(&string))
136 return false;
137 *out = IndexedDBKeyPath(string);
138 return true;
139 }
140 case indexed_db::mojom::KeyPathDataDataView::Tag::STRING_ARRAY: {
141 std::vector<base::string16> array;
142 if (!data_view.ReadStringArray(&array))
143 return false;
144 *out = IndexedDBKeyPath(array);
145 return true;
146 }
147 }
148
149 return false;
150 }
151
152 // static
153 bool StructTraits<indexed_db::mojom::KeyRangeDataView, IndexedDBKeyRange>::Read(
154 indexed_db::mojom::KeyRangeDataView data,
155 IndexedDBKeyRange* out) {
156 IndexedDBKey lower;
157 IndexedDBKey upper;
158 if (!data.ReadLower(&lower) || !data.ReadUpper(&upper))
159 return false;
160
161 *out = IndexedDBKeyRange(lower, upper, data.lower_open(), data.upper_open());
162 return true;
163 }
164
165 // static
12 bool StructTraits<indexed_db::mojom::IndexKeysDataView, 166 bool StructTraits<indexed_db::mojom::IndexKeysDataView,
13 content::IndexedDBIndexKeys>:: 167 content::IndexedDBIndexKeys>::
14 Read(indexed_db::mojom::IndexKeysDataView data, 168 Read(indexed_db::mojom::IndexKeysDataView data,
15 content::IndexedDBIndexKeys* out) { 169 content::IndexedDBIndexKeys* out) {
16 out->first = data.index_id(); 170 out->first = data.index_id();
17 return data.ReadIndexKeys(&out->second); 171 return data.ReadIndexKeys(&out->second);
18 } 172 }
19 173
20 // static 174 // static
21 bool StructTraits<indexed_db::mojom::IndexMetadataDataView, 175 bool StructTraits<indexed_db::mojom::IndexMetadataDataView,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 DCHECK(!base::ContainsKey(out->object_stores, object_store.id())); 231 DCHECK(!base::ContainsKey(out->object_stores, object_store.id()));
78 if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView, 232 if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView,
79 content::IndexedDBObjectStoreMetadata>:: 233 content::IndexedDBObjectStoreMetadata>::
80 Read(object_store, &out->object_stores[object_store.id()])) 234 Read(object_store, &out->object_stores[object_store.id()]))
81 return false; 235 return false;
82 } 236 }
83 return true; 237 return true;
84 } 238 }
85 239
86 } // namespace mojo 240 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698