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

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: Fix compile error on GCC. 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
« no previous file with comments | « content/common/indexed_db/indexed_db_struct_traits.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
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 break;
45 }
46 NOTREACHED();
47 return data;
48 }
49
50 // static
51 bool StructTraits<indexed_db::mojom::KeyDataView, IndexedDBKey>::Read(
52 indexed_db::mojom::KeyDataView data,
53 IndexedDBKey* out) {
54 indexed_db::mojom::KeyDataDataView data_view;
55 data.GetDataDataView(&data_view);
56
57 switch (data_view.tag()) {
58 case indexed_db::mojom::KeyDataDataView::Tag::KEY_ARRAY: {
59 std::vector<IndexedDBKey> array;
60 if (!data_view.ReadKeyArray(&array))
61 return false;
62 *out = IndexedDBKey(array);
63 return true;
64 }
65 case indexed_db::mojom::KeyDataDataView::Tag::BINARY: {
66 std::vector<uint8_t> binary;
67 if (!data_view.ReadBinary(&binary))
68 return false;
69 *out = IndexedDBKey(
70 std::string(binary.data(), binary.data() + binary.size()));
71 return true;
72 }
73 case indexed_db::mojom::KeyDataDataView::Tag::STRING: {
74 base::string16 string;
75 if (!data_view.ReadString(&string))
76 return false;
77 *out = IndexedDBKey(string);
78 return true;
79 }
80 case indexed_db::mojom::KeyDataDataView::Tag::DATE:
81 *out = IndexedDBKey(data_view.date(), blink::WebIDBKeyTypeDate);
82 return true;
83 case indexed_db::mojom::KeyDataDataView::Tag::NUMBER:
84 *out = IndexedDBKey(data_view.number(), blink::WebIDBKeyTypeNumber);
85 return true;
86 case indexed_db::mojom::KeyDataDataView::Tag::OTHER:
87 switch (data_view.other()) {
88 case indexed_db::mojom::DatalessKeyType::Invalid:
89 *out = IndexedDBKey(blink::WebIDBKeyTypeInvalid);
90 return true;
91 case indexed_db::mojom::DatalessKeyType::Null:
92 *out = IndexedDBKey(blink::WebIDBKeyTypeNull);
93 return true;
94 }
95 }
96
97 return false;
98 }
99
100 // static
101 indexed_db::mojom::KeyPathDataPtr
102 StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::data(
103 const IndexedDBKeyPath& key_path) {
104 if (key_path.IsNull())
105 return nullptr;
106
107 auto data = indexed_db::mojom::KeyPathData::New();
108 switch (key_path.type()) {
109 case blink::WebIDBKeyPathTypeString:
110 data->set_string(key_path.string());
111 return data;
112 case blink::WebIDBKeyPathTypeArray:
113 data->set_string_array(key_path.array());
114 return data;
115 default:
116 NOTREACHED();
117 return data;
118 }
119 }
120
121 // static
122 bool StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::Read(
123 indexed_db::mojom::KeyPathDataView data,
124 IndexedDBKeyPath* out) {
125 indexed_db::mojom::KeyPathDataDataView data_view;
126 data.GetDataDataView(&data_view);
127
128 if (data_view.is_null()) {
129 *out = IndexedDBKeyPath();
130 return true;
131 }
132
133 switch (data_view.tag()) {
134 case indexed_db::mojom::KeyPathDataDataView::Tag::STRING: {
135 base::string16 string;
136 if (!data_view.ReadString(&string))
137 return false;
138 *out = IndexedDBKeyPath(string);
139 return true;
140 }
141 case indexed_db::mojom::KeyPathDataDataView::Tag::STRING_ARRAY: {
142 std::vector<base::string16> array;
143 if (!data_view.ReadStringArray(&array))
144 return false;
145 *out = IndexedDBKeyPath(array);
146 return true;
147 }
148 }
149
150 return false;
151 }
152
153 // static
154 bool StructTraits<indexed_db::mojom::KeyRangeDataView, IndexedDBKeyRange>::Read(
155 indexed_db::mojom::KeyRangeDataView data,
156 IndexedDBKeyRange* out) {
157 IndexedDBKey lower;
158 IndexedDBKey upper;
159 if (!data.ReadLower(&lower) || !data.ReadUpper(&upper))
160 return false;
161
162 *out = IndexedDBKeyRange(lower, upper, data.lower_open(), data.upper_open());
163 return true;
164 }
165
166 // static
12 bool StructTraits<indexed_db::mojom::IndexKeysDataView, 167 bool StructTraits<indexed_db::mojom::IndexKeysDataView,
13 content::IndexedDBIndexKeys>:: 168 content::IndexedDBIndexKeys>::
14 Read(indexed_db::mojom::IndexKeysDataView data, 169 Read(indexed_db::mojom::IndexKeysDataView data,
15 content::IndexedDBIndexKeys* out) { 170 content::IndexedDBIndexKeys* out) {
16 out->first = data.index_id(); 171 out->first = data.index_id();
17 return data.ReadIndexKeys(&out->second); 172 return data.ReadIndexKeys(&out->second);
18 } 173 }
19 174
20 // static 175 // static
21 bool StructTraits<indexed_db::mojom::IndexMetadataDataView, 176 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())); 232 DCHECK(!base::ContainsKey(out->object_stores, object_store.id()));
78 if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView, 233 if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView,
79 content::IndexedDBObjectStoreMetadata>:: 234 content::IndexedDBObjectStoreMetadata>::
80 Read(object_store, &out->object_stores[object_store.id()])) 235 Read(object_store, &out->object_stores[object_store.id()]))
81 return false; 236 return false;
82 } 237 }
83 return true; 238 return true;
84 } 239 }
85 240
86 } // namespace mojo 241 } // namespace mojo
OLDNEW
« no previous file with comments | « content/common/indexed_db/indexed_db_struct_traits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698