Index: content/common/indexed_db/indexed_db_struct_traits.h |
diff --git a/content/common/indexed_db/indexed_db_struct_traits.h b/content/common/indexed_db/indexed_db_struct_traits.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf8c74deaecf825b7c3fc40620a4e30ade00fa35 |
--- /dev/null |
+++ b/content/common/indexed_db/indexed_db_struct_traits.h |
@@ -0,0 +1,139 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_ |
+#define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_ |
+ |
+#include "content/common/indexed_db/indexed_db.mojom.h" |
+#include "content/common/indexed_db/indexed_db_metadata.h" |
+ |
+namespace mojo { |
+ |
+template <> |
+struct StructTraits<indexed_db::mojom::IndexMetadataDataView, |
+ content::IndexedDBIndexMetadata> { |
+ static int64_t id(const content::IndexedDBIndexMetadata& metadata) { |
+ 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
|
+ } |
+ static base::string16 name(const content::IndexedDBIndexMetadata& metadata) { |
+ return metadata.name; |
+ } |
+ static const content::IndexedDBKeyPath& key_path( |
+ const content::IndexedDBIndexMetadata& metadata) { |
+ return metadata.key_path; |
+ } |
+ static bool unique(const content::IndexedDBIndexMetadata& metadata) { |
+ return metadata.unique; |
+ } |
+ static bool multi_entry(const content::IndexedDBIndexMetadata& metadata) { |
+ return metadata.multi_entry; |
+ } |
+ static bool Read(indexed_db::mojom::IndexMetadataDataView data, |
+ 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.
|
+ out->id = data.id(); |
+ if (!data.ReadName(&out->name)) |
+ return false; |
+ if (!data.ReadKeyPath(&out->key_path)) |
+ return false; |
+ out->unique = data.unique(); |
+ out->multi_entry = data.multi_entry(); |
+ return true; |
+ } |
+}; |
+ |
+template <> |
+struct StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView, |
+ content::IndexedDBObjectStoreMetadata> { |
+ static int64_t id(const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return metadata.id; |
+ } |
+ static base::string16 name( |
+ const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return metadata.name; |
+ } |
+ static const content::IndexedDBKeyPath& key_path( |
+ const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return metadata.key_path; |
+ } |
+ static bool auto_increment( |
+ const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return metadata.auto_increment; |
+ } |
+ static int64_t max_index_id( |
+ const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return metadata.max_index_id; |
+ } |
+ static MapValuesArrayView<int64_t, content::IndexedDBIndexMetadata> indexes( |
+ const content::IndexedDBObjectStoreMetadata& metadata) { |
+ return MapValuesToArray(metadata.indexes); |
+ } |
+ static bool Read(indexed_db::mojom::ObjectStoreMetadataDataView data, |
+ content::IndexedDBObjectStoreMetadata* out) { |
+ out->id = data.id(); |
+ if (!data.ReadName(&out->name)) |
+ return false; |
+ if (!data.ReadKeyPath(&out->key_path)) |
+ return false; |
+ out->auto_increment = data.auto_increment(); |
+ out->max_index_id = data.max_index_id(); |
+ ArrayDataView<indexed_db::mojom::IndexMetadataDataView> indexes; |
+ data.GetIndexesDataView(&indexes); |
+ for (size_t i = 0; i < indexes.size(); ++i) { |
+ indexed_db::mojom::IndexMetadataDataView index; |
+ 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,
|
+ if (!StructTraits< |
+ indexed_db::mojom::IndexMetadataDataView, |
+ content::IndexedDBIndexMetadata>::Read(index, |
+ &out->indexes[index.id()])) |
+ return false; |
+ } |
+ return true; |
+ } |
+}; |
+ |
+template <> |
+struct StructTraits<indexed_db::mojom::DatabaseMetadataDataView, |
+ content::IndexedDBDatabaseMetadata> { |
+ static int64_t id(const content::IndexedDBDatabaseMetadata& metadata) { |
+ return metadata.id; |
+ } |
+ static base::string16 name( |
+ const content::IndexedDBDatabaseMetadata& metadata) { |
+ return metadata.name; |
+ } |
+ static int64_t version(const content::IndexedDBDatabaseMetadata& metadata) { |
+ return metadata.version; |
+ } |
+ static int64_t max_object_store_id( |
+ const content::IndexedDBDatabaseMetadata& metadata) { |
+ return metadata.max_object_store_id; |
+ } |
+ static MapValuesArrayView<int64_t, content::IndexedDBObjectStoreMetadata> |
+ object_stores(const content::IndexedDBDatabaseMetadata& metadata) { |
+ return MapValuesToArray(metadata.object_stores); |
+ } |
+ static bool Read(indexed_db::mojom::DatabaseMetadataDataView data, |
+ content::IndexedDBDatabaseMetadata* out) { |
+ out->id = data.id(); |
+ if (!data.ReadName(&out->name)) |
+ return false; |
+ out->version = data.version(); |
+ out->max_object_store_id = data.max_object_store_id(); |
+ ArrayDataView<indexed_db::mojom::ObjectStoreMetadataDataView> object_stores; |
+ data.GetObjectStoresDataView(&object_stores); |
+ for (size_t i = 0; i < object_stores.size(); ++i) { |
+ indexed_db::mojom::ObjectStoreMetadataDataView object_store; |
+ object_stores.GetDataView(i, &object_store); |
+ if (!StructTraits<indexed_db::mojom::ObjectStoreMetadataDataView, |
+ content::IndexedDBObjectStoreMetadata>:: |
+ Read(object_store, &out->object_stores[object_store.id()])) |
+ return false; |
+ } |
+ return true; |
+ } |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_STRUCT_TRAITS_H_ |