From e40aab96ddec63ff5d3b02ebda75941fb8982576 Mon Sep 17 00:00:00 2001 From: "jsbell@chromium.org" Date: Wed, 9 Nov 2011 17:48:38 +0000 Subject: IndexedDB: IPC support for compound (array) keys WebKit side is: https://bugs.webkit.org/show_bug.cgi?id=62284 BUG=92038 Review URL: http://codereview.chromium.org/8417055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109266 0039d316-1c4b-4281-b951-d872f2087c98 --- .../in_process_webkit/indexed_db_browsertest.cc | 4 ++ content/common/indexed_db_key.cc | 15 ++++- content/common/indexed_db_key.h | 5 ++ content/common/indexed_db_param_traits.cc | 78 ++++++++++++++++------ 4 files changed, 80 insertions(+), 22 deletions(-) (limited to 'content') diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc index d7e3433..4a30039 100644 --- a/content/browser/in_process_webkit/indexed_db_browsertest.cc +++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc @@ -83,6 +83,10 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionGetTest) { SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("transaction_get_test.html")))); } +IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, KeyTypesTest) { + SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("key_types_test.html")))); +} + // Flaky: http://crbug.com/70773 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DISABLED_ObjectStoreTest) { SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("object_store_test.html")))); diff --git a/content/common/indexed_db_key.cc b/content/common/indexed_db_key.cc index 6a97d08..44cb81a 100644 --- a/content/common/indexed_db_key.cc +++ b/content/common/indexed_db_key.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" using WebKit::WebIDBKey; @@ -26,6 +27,11 @@ void IndexedDBKey::SetInvalid() { type_ = WebIDBKey::InvalidType; } +void IndexedDBKey::SetArray(const std::vector& array) { + type_ = WebIDBKey::ArrayType; + array_ = array; +} + void IndexedDBKey::SetString(const string16& string) { type_ = WebIDBKey::StringType; string_ = string; @@ -43,6 +49,12 @@ void IndexedDBKey::SetNumber(double number) { void IndexedDBKey::Set(const WebIDBKey& key) { type_ = key.type(); + array_.clear(); + if (key.type() == WebIDBKey::ArrayType) { + for (size_t i = 0; i < key.array().size(); ++i) { + array_.push_back(IndexedDBKey(key.array()[i])); + } + } string_ = key.type() == WebIDBKey::StringType ? static_cast(key.string()) : string16(); number_ = key.type() == WebIDBKey::NumberType ? key.number() : 0; @@ -51,6 +63,8 @@ void IndexedDBKey::Set(const WebIDBKey& key) { IndexedDBKey::operator WebIDBKey() const { switch (type_) { + case WebIDBKey::ArrayType: + return WebIDBKey::createArray(array_); case WebIDBKey::StringType: return WebIDBKey::createString(string_); case WebIDBKey::DateType: @@ -58,7 +72,6 @@ IndexedDBKey::operator WebIDBKey() const { case WebIDBKey::NumberType: return WebIDBKey::createNumber(number_); case WebIDBKey::InvalidType: - default: // TODO(jsbell): Remove after WebIDBKey::ArrayType added. return WebIDBKey::createInvalid(); } NOTREACHED(); diff --git a/content/common/indexed_db_key.h b/content/common/indexed_db_key.h index 808aaa8..93daf7c 100644 --- a/content/common/indexed_db_key.h +++ b/content/common/indexed_db_key.h @@ -6,6 +6,8 @@ #define CONTENT_COMMON_INDEXED_DB_KEY_H_ #pragma once +#include + #include "base/basictypes.h" #include "base/string16.h" #include "content/common/content_export.h" @@ -18,12 +20,14 @@ class CONTENT_EXPORT IndexedDBKey { ~IndexedDBKey(); void SetInvalid(); + void SetArray(const std::vector& array); void SetString(const string16& string); void SetDate(double date); void SetNumber(double number); void Set(const WebKit::WebIDBKey& key); WebKit::WebIDBKey::Type type() const { return type_; } + const std::vector& array() const { return array_; } const string16& string() const { return string_; } double date() const { return date_; } double number() const { return number_; } @@ -32,6 +36,7 @@ class CONTENT_EXPORT IndexedDBKey { private: WebKit::WebIDBKey::Type type_; + std::vector array_; string16 string_; double date_; double number_; diff --git a/content/common/indexed_db_param_traits.cc b/content/common/indexed_db_param_traits.cc index 7aa7ec9..5c3eb95 100644 --- a/content/common/indexed_db_param_traits.cc +++ b/content/common/indexed_db_param_traits.cc @@ -48,39 +48,66 @@ void ParamTraits::Log(const param_type& p, void ParamTraits::Write(Message* m, const param_type& p) { WriteParam(m, int(p.type())); - // TODO(jorlow): Technically, we only need to pack the type being used. - WriteParam(m, p.string()); - WriteParam(m, p.date()); - WriteParam(m, p.number()); + switch (p.type()) { + case WebKit::WebIDBKey::ArrayType: + WriteParam(m, p.array()); + return; + case WebKit::WebIDBKey::StringType: + WriteParam(m, p.string()); + return; + case WebKit::WebIDBKey::DateType: + WriteParam(m, p.date()); + return; + case WebKit::WebIDBKey::NumberType: + WriteParam(m, p.number()); + return; + case WebKit::WebIDBKey::InvalidType: + return; + } + NOTREACHED(); } bool ParamTraits::Read(const Message* m, void** iter, param_type* r) { int type; - string16 string; - double date; - double number; - bool ok = - ReadParam(m, iter, &type) && - ReadParam(m, iter, &string) && - ReadParam(m, iter, &date) && - ReadParam(m, iter, &number); - - if (!ok) + if (!ReadParam(m, iter, &type)) return false; + switch (type) { + case WebKit::WebIDBKey::ArrayType: + { + std::vector array; + if (!ReadParam(m, iter, &array)) + return false; + r->SetArray(array); + return true; + } case WebKit::WebIDBKey::StringType: - r->SetString(string); - return true; + { + string16 string; + if (!ReadParam(m, iter, &string)) + return false; + r->SetString(string); + return true; + } case WebKit::WebIDBKey::DateType: - r->SetDate(date); - return true; + { + double date; + if (!ReadParam(m, iter, &date)) + return false; + r->SetDate(date); + return true; + } case WebKit::WebIDBKey::NumberType: - r->SetNumber(number); - return true; + { + double number; + if (!ReadParam(m, iter, &number)) + return false; + r->SetNumber(number); + return true; + } case WebKit::WebIDBKey::InvalidType: - default: // TODO(jsbell): Remove after WebIDBKey::ArrayType added. r->SetInvalid(); return true; } @@ -92,6 +119,15 @@ void ParamTraits::Log(const param_type& p, std::string* l) { l->append("("); LogParam(int(p.type()), l); l->append(", "); + l->append("["); + std::vector::const_iterator it = p.array().begin(); + while (it != p.array().end()) { + Log(*it, l); + ++it; + if (it != p.array().end()) + l->append(", "); + } + l->append("], "); LogParam(p.string(), l); l->append(", "); LogParam(p.date(), l); -- cgit v1.1