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

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

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Require explicit wrapping when discarding map keys. Created 4 years, 2 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_
6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_
7
8 #include "content/common/indexed_db/indexed_db.mojom.h"
9 #include "content/common/indexed_db/indexed_db_metadata.h"
10
11 namespace mojo {
12
13 template <>
14 struct StructTraits<indexed_db::mojom::IndexMetadataDataView,
15 content::IndexedDBIndexMetadata> {
16 static int64_t id(const content::IndexedDBIndexMetadata& metadata) {
17 return metadata.id;
dcheng 2016/10/17 05:33:44 Does it make sense to DCHECK(metadata.id >= 0) her
Reilly Grant (use Gerrit) 2016/10/19 00:36:51 These are dictionary keys. I don't know if negativ
dcheng 2016/10/19 03:55:29 Ah, I saw kInvalidIndex = -1 in IndexedDBIndexMeta
18 }
19 static base::string16 name(const content::IndexedDBIndexMetadata& metadata) {
20 return metadata.name;
21 }
22 static const content::IndexedDBKeyPath& key_path(
23 const content::IndexedDBIndexMetadata& metadata) {
24 return metadata.key_path;
25 }
26 static bool unique(const content::IndexedDBIndexMetadata& metadata) {
27 return metadata.unique;
28 }
29 static bool multi_entry(const content::IndexedDBIndexMetadata& metadata) {
30 return metadata.multi_entry;
31 }
32 static bool Read(indexed_db::mojom::IndexMetadataDataView data,
33 content::IndexedDBIndexMetadata* out) {
dcheng 2016/10/17 05:33:44 Nit: please out-of-line non-trivial methods.
Reilly Grant (use Gerrit) 2016/10/19 00:36:51 Done.
34 out->id = data.id();
35 if (!data.ReadName(&out->name))
36 return false;
37 if (!data.ReadKeyPath(&out->key_path))
38 return false;
39 out->unique = data.unique();
40 out->multi_entry = data.multi_entry();
41 return true;
42 }
43 };
44
45 template <>
46 struct StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView,
47 content::IndexedDBObjectStoreMetadata> {
48 static int64_t id(const content::IndexedDBObjectStoreMetadata& metadata) {
49 return metadata.id;
50 }
51 static base::string16 name(
52 const content::IndexedDBObjectStoreMetadata& metadata) {
53 return metadata.name;
54 }
55 static const content::IndexedDBKeyPath& key_path(
56 const content::IndexedDBObjectStoreMetadata& metadata) {
57 return metadata.key_path;
58 }
59 static bool auto_increment(
60 const content::IndexedDBObjectStoreMetadata& metadata) {
61 return metadata.auto_increment;
62 }
63 static int64_t max_index_id(
64 const content::IndexedDBObjectStoreMetadata& metadata) {
65 return metadata.max_index_id;
66 }
67 static MapValuesArrayView<int64_t, content::IndexedDBIndexMetadata> indexes(
68 const content::IndexedDBObjectStoreMetadata& metadata) {
69 return MapValuesToArray(metadata.indexes);
70 }
71 static bool Read(indexed_db::mojom::ObjectStoreMetadataDataView data,
72 content::IndexedDBObjectStoreMetadata* out) {
73 out->id = data.id();
74 if (!data.ReadName(&out->name))
75 return false;
76 if (!data.ReadKeyPath(&out->key_path))
77 return false;
78 out->auto_increment = data.auto_increment();
79 out->max_index_id = data.max_index_id();
80 ArrayDataView<indexed_db::mojom::IndexMetadataDataView> indexes;
81 data.GetIndexesDataView(&indexes);
82 for (size_t i = 0; i < indexes.size(); ++i) {
83 indexed_db::mojom::IndexMetadataDataView index;
84 indexes.GetDataView(i, &index);
dcheng 2016/10/17 05:33:44 Should this check that 0 <= index.id() < indexes.s
Reilly Grant (use Gerrit) 2016/10/19 00:36:51 |indexes| is a map so index.id() is allowed to hav
dcheng 2016/10/19 03:55:29 I agree the current code is fine (for some reason,
85 if (!StructTraits<
86 indexed_db::mojom::IndexMetadataDataView,
87 content::IndexedDBIndexMetadata>::Read(index,
88 &out->indexes[index.id()]))
89 return false;
90 }
91 return true;
92 }
93 };
94
95 template <>
96 struct StructTraits<indexed_db::mojom::DatabaseMetadataDataView,
97 content::IndexedDBDatabaseMetadata> {
98 static int64_t id(const content::IndexedDBDatabaseMetadata& metadata) {
99 return metadata.id;
100 }
101 static base::string16 name(
102 const content::IndexedDBDatabaseMetadata& metadata) {
103 return metadata.name;
104 }
105 static int64_t version(const content::IndexedDBDatabaseMetadata& metadata) {
106 return metadata.version;
107 }
108 static int64_t max_object_store_id(
109 const content::IndexedDBDatabaseMetadata& metadata) {
110 return metadata.max_object_store_id;
111 }
112 static MapValuesArrayView<int64_t, content::IndexedDBObjectStoreMetadata>
113 object_stores(const content::IndexedDBDatabaseMetadata& metadata) {
114 return MapValuesToArray(metadata.object_stores);
115 }
116 static bool Read(indexed_db::mojom::DatabaseMetadataDataView data,
117 content::IndexedDBDatabaseMetadata* out) {
118 out->id = data.id();
119 if (!data.ReadName(&out->name))
120 return false;
121 out->version = data.version();
122 out->max_object_store_id = data.max_object_store_id();
123 ArrayDataView<indexed_db::mojom::ObjectStoreMetadataDataView> object_stores;
124 data.GetObjectStoresDataView(&object_stores);
125 for (size_t i = 0; i < object_stores.size(); ++i) {
126 indexed_db::mojom::ObjectStoreMetadataDataView object_store;
127 object_stores.GetDataView(i, &object_store);
128 if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView,
129 content::IndexedDBObjectStoreMetadata>::
130 Read(object_store, &out->object_stores[object_store.id()]))
131 return false;
132 }
133 return true;
134 }
135 };
136
137 } // namespace mojo
138
139 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698