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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/indexed_db/indexed_db_struct_traits.cc
diff --git a/content/common/indexed_db/indexed_db_struct_traits.cc b/content/common/indexed_db/indexed_db_struct_traits.cc
index d304b0fca01ca16533b41aa0abd07d4a706dd222..6b3a675598d73e8738c45ed254c04fa27e868885 100644
--- a/content/common/indexed_db/indexed_db_struct_traits.cc
+++ b/content/common/indexed_db/indexed_db_struct_traits.cc
@@ -6,9 +6,164 @@
#include "content/common/indexed_db/indexed_db_struct_traits.h"
#include "mojo/common/common_custom_types_struct_traits.h"
+using content::IndexedDBKey;
+using content::IndexedDBKeyPath;
+using content::IndexedDBKeyRange;
+
namespace mojo {
// static
+indexed_db::mojom::KeyDataPtr
+StructTraits<indexed_db::mojom::KeyDataView, IndexedDBKey>::data(
+ const IndexedDBKey& key) {
+ auto data = indexed_db::mojom::KeyData::New();
+ switch (key.type()) {
+ case blink::WebIDBKeyTypeInvalid:
+ data->set_other(indexed_db::mojom::DatalessKeyType::Invalid);
+ return data;
+ case blink::WebIDBKeyTypeArray:
+ data->set_key_array(key.array());
+ return data;
+ case blink::WebIDBKeyTypeBinary:
+ data->set_binary(std::vector<uint8_t>(
+ key.binary().data(), key.binary().data() + key.binary().size()));
+ return data;
+ case blink::WebIDBKeyTypeString:
+ data->set_string(key.string());
+ return data;
+ case blink::WebIDBKeyTypeDate:
+ data->set_date(key.date());
+ return data;
+ case blink::WebIDBKeyTypeNumber:
+ data->set_number(key.number());
+ return data;
+ case blink::WebIDBKeyTypeNull:
+ data->set_other(indexed_db::mojom::DatalessKeyType::Null);
+ return data;
+ case blink::WebIDBKeyTypeMin:
+ break;
+ }
+ NOTREACHED();
+ return data;
+}
+
+// static
+bool StructTraits<indexed_db::mojom::KeyDataView, IndexedDBKey>::Read(
+ indexed_db::mojom::KeyDataView data,
+ IndexedDBKey* out) {
+ indexed_db::mojom::KeyDataDataView data_view;
+ data.GetDataDataView(&data_view);
+
+ switch (data_view.tag()) {
+ case indexed_db::mojom::KeyDataDataView::Tag::KEY_ARRAY: {
+ std::vector<IndexedDBKey> array;
+ if (!data_view.ReadKeyArray(&array))
+ return false;
+ *out = IndexedDBKey(array);
+ return true;
+ }
+ case indexed_db::mojom::KeyDataDataView::Tag::BINARY: {
+ std::vector<uint8_t> binary;
+ if (!data_view.ReadBinary(&binary))
+ return false;
+ *out = IndexedDBKey(
+ std::string(binary.data(), binary.data() + binary.size()));
+ return true;
+ }
+ case indexed_db::mojom::KeyDataDataView::Tag::STRING: {
+ base::string16 string;
+ if (!data_view.ReadString(&string))
+ return false;
+ *out = IndexedDBKey(string);
+ return true;
+ }
+ case indexed_db::mojom::KeyDataDataView::Tag::DATE:
+ *out = IndexedDBKey(data_view.date(), blink::WebIDBKeyTypeDate);
+ return true;
+ case indexed_db::mojom::KeyDataDataView::Tag::NUMBER:
+ *out = IndexedDBKey(data_view.number(), blink::WebIDBKeyTypeNumber);
+ return true;
+ case indexed_db::mojom::KeyDataDataView::Tag::OTHER:
+ switch (data_view.other()) {
+ case indexed_db::mojom::DatalessKeyType::Invalid:
+ *out = IndexedDBKey(blink::WebIDBKeyTypeInvalid);
+ return true;
+ case indexed_db::mojom::DatalessKeyType::Null:
+ *out = IndexedDBKey(blink::WebIDBKeyTypeNull);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// static
+indexed_db::mojom::KeyPathDataPtr
+StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::data(
+ const IndexedDBKeyPath& key_path) {
+ if (key_path.IsNull())
+ return nullptr;
+
+ auto data = indexed_db::mojom::KeyPathData::New();
+ switch (key_path.type()) {
+ case blink::WebIDBKeyPathTypeString:
+ data->set_string(key_path.string());
+ return data;
+ case blink::WebIDBKeyPathTypeArray:
+ data->set_string_array(key_path.array());
+ return data;
+ default:
+ NOTREACHED();
+ return data;
+ }
+}
+
+// static
+bool StructTraits<indexed_db::mojom::KeyPathDataView, IndexedDBKeyPath>::Read(
+ indexed_db::mojom::KeyPathDataView data,
+ IndexedDBKeyPath* out) {
+ indexed_db::mojom::KeyPathDataDataView data_view;
+ data.GetDataDataView(&data_view);
+
+ if (data_view.is_null()) {
+ *out = IndexedDBKeyPath();
+ return true;
+ }
+
+ switch (data_view.tag()) {
+ case indexed_db::mojom::KeyPathDataDataView::Tag::STRING: {
+ base::string16 string;
+ if (!data_view.ReadString(&string))
+ return false;
+ *out = IndexedDBKeyPath(string);
+ return true;
+ }
+ case indexed_db::mojom::KeyPathDataDataView::Tag::STRING_ARRAY: {
+ std::vector<base::string16> array;
+ if (!data_view.ReadStringArray(&array))
+ return false;
+ *out = IndexedDBKeyPath(array);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// static
+bool StructTraits<indexed_db::mojom::KeyRangeDataView, IndexedDBKeyRange>::Read(
+ indexed_db::mojom::KeyRangeDataView data,
+ IndexedDBKeyRange* out) {
+ IndexedDBKey lower;
+ IndexedDBKey upper;
+ if (!data.ReadLower(&lower) || !data.ReadUpper(&upper))
+ return false;
+
+ *out = IndexedDBKeyRange(lower, upper, data.lower_open(), data.upper_open());
+ return true;
+}
+
+// static
bool StructTraits<indexed_db::mojom::IndexKeysDataView,
content::IndexedDBIndexKeys>::
Read(indexed_db::mojom::IndexKeysDataView data,
« 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