summaryrefslogtreecommitdiffstats
path: root/content/common
diff options
context:
space:
mode:
authoralecflett@chromium.org <alecflett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-20 05:41:12 +0000
committeralecflett@chromium.org <alecflett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-20 05:41:12 +0000
commitb18649f477cf8dc675deaa8bd6d298b5633aaaea (patch)
treec1a1b9c46ea3f71ad88516dee1a5b596b0e34060 /content/common
parenta1c2c1dfa905380cfdbd338cc5735ff090181b26 (diff)
downloadchromium_src-b18649f477cf8dc675deaa8bd6d298b5633aaaea.zip
chromium_src-b18649f477cf8dc675deaa8bd6d298b5633aaaea.tar.gz
chromium_src-b18649f477cf8dc675deaa8bd6d298b5633aaaea.tar.bz2
Remove Set* methods from IndexedDBKey
This makes lifetime management of these objects much easier since they must be explicitly constructed. This is in preparation for migration of a bunch of code from Blink. BUG=234278 Review URL: https://chromiumcodereview.appspot.com/15198006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201033 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r--content/common/indexed_db/indexed_db_dispatcher_unittest.cc26
-rw-r--r--content/common/indexed_db/indexed_db_key.cc146
-rw-r--r--content/common/indexed_db/indexed_db_key.h30
-rw-r--r--content/common/indexed_db/indexed_db_key_range.cc54
-rw-r--r--content/common/indexed_db/indexed_db_key_range.h8
-rw-r--r--content/common/indexed_db/indexed_db_param_traits.cc78
-rw-r--r--content/common/indexed_db/proxy_webidbcursor_impl_unittest.cc52
7 files changed, 236 insertions, 158 deletions
diff --git a/content/common/indexed_db/indexed_db_dispatcher_unittest.cc b/content/common/indexed_db/indexed_db_dispatcher_unittest.cc
index f9be36d..37864ce 100644
--- a/content/common/indexed_db/indexed_db_dispatcher_unittest.cc
+++ b/content/common/indexed_db/indexed_db_dispatcher_unittest.cc
@@ -22,9 +22,7 @@ namespace {
class MockCallbacks : public WebIDBCallbacks {
public:
- MockCallbacks()
- : error_seen_(false) {
- }
+ MockCallbacks() : error_seen_(false) {}
virtual void onError(const WebIDBDatabaseError&) OVERRIDE {
error_seen_ = true;
@@ -47,18 +45,16 @@ TEST(IndexedDBDispatcherTest, ValueSizeTest) {
MockCallbacks callbacks;
IndexedDBDispatcher dispatcher;
- IndexedDBKey key;
- key.SetNumber(0);
- dispatcher.RequestIDBDatabasePut(
- ipc_dummy_id,
- transaction_id,
- object_store_id,
- value,
- key,
- WebIDBDatabase::AddOrUpdate,
- &callbacks,
- WebVector<long long>(),
- WebVector<WebVector<WebIDBKey> >());
+ IndexedDBKey key(0, WebIDBKey::NumberType);
+ dispatcher.RequestIDBDatabasePut(ipc_dummy_id,
+ transaction_id,
+ object_store_id,
+ value,
+ key,
+ WebIDBDatabase::AddOrUpdate,
+ &callbacks,
+ WebVector<long long>(),
+ WebVector<WebVector<WebIDBKey> >());
EXPECT_TRUE(callbacks.error_seen());
}
diff --git a/content/common/indexed_db/indexed_db_key.cc b/content/common/indexed_db/indexed_db_key.cc
index 994dc4b..de43f5a 100644
--- a/content/common/indexed_db/indexed_db_key.cc
+++ b/content/common/indexed_db/indexed_db_key.cc
@@ -13,60 +13,132 @@ namespace content {
using WebKit::WebIDBKey;
using WebKit::WebVector;
-IndexedDBKey::IndexedDBKey()
- : type_(WebIDBKey::NullType),
- date_(0),
- number_(0) {
-}
+namespace {
+size_t CalculateKeySize(const WebIDBKey& key);
-IndexedDBKey::IndexedDBKey(const WebIDBKey& key) {
- Set(key);
+template <typename T> static size_t CalculateSize(const T& keys) {
+ size_t size(0);
+ for (size_t i = 0; i < keys.size(); ++i) {
+ size += CalculateKeySize(keys[i]);
+ }
+ return size;
}
-IndexedDBKey::~IndexedDBKey() {
+size_t CalculateKeySize(const WebIDBKey& key) {
+ switch (key.type()) {
+ case WebIDBKey::ArrayType:
+ return CalculateSize(key.array());
+
+ case WebIDBKey::StringType:
+ return key.string().length() * sizeof(string16::value_type);
+
+ case WebIDBKey::DateType:
+ case WebIDBKey::NumberType:
+ return sizeof(double);
+ default:
+ return 0;
+ }
+ NOTREACHED();
+ return 0;
}
-void IndexedDBKey::SetInvalid() {
- type_ = WebIDBKey::InvalidType;
+template <typename T>
+static IndexedDBKey::KeyArray
+CopyKeyArray(const T& array) {
+ IndexedDBKey::KeyArray result;
+ result.reserve(array.size());
+ for (size_t i = 0; i < array.size(); ++i) {
+ result.push_back(IndexedDBKey(array[i]));
+ }
+ return result;
}
-void IndexedDBKey::SetNull() {
- type_ = WebIDBKey::NullType;
+static IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) {
+ IndexedDBKey::KeyArray result;
+ if (other.type() == WebIDBKey::ArrayType) {
+ result = CopyKeyArray(other.array());
+ }
+ return result;
}
+} // namespace
+
+IndexedDBKey::IndexedDBKey()
+ : type_(WebIDBKey::NullType),
+ date_(0),
+ number_(0),
+ size_estimate_(kOverheadSize) {}
-void IndexedDBKey::SetArray(const std::vector<IndexedDBKey>& array) {
- type_ = WebIDBKey::ArrayType;
- array_ = array;
+IndexedDBKey::IndexedDBKey(WebIDBKey::Type type)
+ : type_(type), date_(0), number_(0), size_estimate_(kOverheadSize) {
+ DCHECK(type == WebIDBKey::NullType || type == WebIDBKey::InvalidType);
}
-void IndexedDBKey::SetString(const string16& string) {
- type_ = WebIDBKey::StringType;
- string_ = string;
+IndexedDBKey::IndexedDBKey(double number, WebIDBKey::Type type)
+ : type_(type),
+ date_(number),
+ number_(number),
+ size_estimate_(kOverheadSize + sizeof(double)) {
+ DCHECK(type == WebIDBKey::NumberType || type == WebIDBKey::DateType);
}
-void IndexedDBKey::SetDate(double date) {
- type_ = WebIDBKey::DateType;
- date_ = date;
+IndexedDBKey::IndexedDBKey(const KeyArray& keys)
+ : type_(WebIDBKey::ArrayType),
+ array_(CopyKeyArray(keys)),
+ date_(0),
+ number_(0),
+ size_estimate_(kOverheadSize + CalculateSize(keys)) {}
+
+IndexedDBKey::IndexedDBKey(const WebIDBKey& key)
+ : type_(key.type()),
+ array_(CopyKeyArray(key)),
+ string_(key.type() == WebIDBKey::StringType
+ ? static_cast<string16>(key.string())
+ : string16()),
+ date_(key.type() == WebIDBKey::DateType ? key.date() : 0),
+ number_(key.type() == WebIDBKey::NumberType ? key.number() : 0),
+ size_estimate_(kOverheadSize + CalculateKeySize(key)) {}
+
+IndexedDBKey::IndexedDBKey(const string16& key)
+ : type_(WebIDBKey::StringType), string_(key) {}
+
+IndexedDBKey::~IndexedDBKey() {}
+
+int IndexedDBKey::Compare(const IndexedDBKey& other) const {
+ if (type_ != other.type_)
+ return type_ > other.type_ ? -1 : 1;
+
+ switch (type_) {
+ case WebIDBKey::ArrayType:
+ for (size_t i = 0; i < array_.size() && i < other.array_.size(); ++i) {
+ if (int result = array_[i].Compare(other.array_[i]))
+ return result;
+ }
+ if (array_.size() < other.array_.size())
+ return -1;
+ if (array_.size() > other.array_.size())
+ return 1;
+ return 0;
+ case WebIDBKey::StringType:
+ return -other.string_.compare(string_);
+ case WebIDBKey::DateType:
+ case WebIDBKey::NumberType:
+ return (number_ < other.number_) ? -1 : (number_ > other.number_) ? 1 : 0;
+ case WebIDBKey::InvalidType:
+ case WebIDBKey::NullType:
+ NOTREACHED();
+ return 0;
+ }
+
+ NOTREACHED();
+ return 0;
}
-void IndexedDBKey::SetNumber(double number) {
- type_ = WebIDBKey::NumberType;
- number_ = number;
+bool IndexedDBKey::IsLessThan(const IndexedDBKey& other) const {
+ return Compare(other) < 0;
}
-void IndexedDBKey::Set(const WebIDBKey& key) {
- type_ = key.type();
- array_.clear();
- if (key.type() == WebIDBKey::ArrayType) {
- WebVector<WebIDBKey> array = key.array();
- for (size_t i = 0; i < array.size(); ++i) {
- array_.push_back(IndexedDBKey(array[i]));
- }
- }
- string_ = key.type() == WebIDBKey::StringType ?
- static_cast<string16>(key.string()) : string16();
- number_ = key.type() == WebIDBKey::NumberType ? key.number() : 0;
- date_ = key.type() == WebIDBKey::DateType ? key.date() : 0;
+bool IndexedDBKey::IsEqual(const IndexedDBKey& other) const {
+ return !Compare(other);
}
IndexedDBKey::operator WebIDBKey() const {
diff --git a/content/common/indexed_db/indexed_db_key.h b/content/common/indexed_db/indexed_db_key.h
index 4a546f4..77f6f3c 100644
--- a/content/common/indexed_db/indexed_db_key.h
+++ b/content/common/indexed_db/indexed_db_key.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/scoped_vector.h"
#include "base/string16.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebIDBKey.h"
@@ -16,17 +17,22 @@ namespace content {
class CONTENT_EXPORT IndexedDBKey {
public:
- IndexedDBKey(); // Defaults to WebKit::WebIDBKey::InvalidType.
+ typedef std::vector<IndexedDBKey> KeyArray;
+
+ IndexedDBKey(); // Defaults to WebKit::WebIDBKey::InvalidType.
+ IndexedDBKey(WebKit::WebIDBKey::Type); // must be Null or Invalid
+ explicit IndexedDBKey(const KeyArray& array);
+ explicit IndexedDBKey(const string16& str);
+ IndexedDBKey(double number,
+ WebKit::WebIDBKey::Type type); // must be date or number
explicit IndexedDBKey(const WebKit::WebIDBKey& key);
~IndexedDBKey();
- void SetNull();
- void SetInvalid();
- void SetArray(const std::vector<IndexedDBKey>& array);
- void SetString(const string16& string);
- void SetDate(double date);
- void SetNumber(double number);
- void Set(const WebKit::WebIDBKey& key);
+ bool IsValid() const;
+
+ int Compare(const IndexedDBKey& other) const;
+ bool IsLessThan(const IndexedDBKey& other) const;
+ bool IsEqual(const IndexedDBKey& other) const;
WebKit::WebIDBKey::Type type() const { return type_; }
const std::vector<IndexedDBKey>& array() const { return array_; }
@@ -35,6 +41,7 @@ class CONTENT_EXPORT IndexedDBKey {
double number() const { return number_; }
operator WebKit::WebIDBKey() const;
+ size_t size_estimate() const { return size_estimate_; }
private:
WebKit::WebIDBKey::Type type_;
@@ -42,6 +49,13 @@ class CONTENT_EXPORT IndexedDBKey {
string16 string_;
double date_;
double number_;
+
+ size_t size_estimate_;
+
+ // Very rough estimate of minimum key size overhead.
+ enum {
+ kOverheadSize = 16
+ };
};
} // namespace content
diff --git a/content/common/indexed_db/indexed_db_key_range.cc b/content/common/indexed_db/indexed_db_key_range.cc
index 1449734..28a80d9 100644
--- a/content/common/indexed_db/indexed_db_key_range.cc
+++ b/content/common/indexed_db/indexed_db_key_range.cc
@@ -12,30 +12,36 @@ using WebKit::WebIDBKeyRange;
using WebKit::WebIDBKey;
IndexedDBKeyRange::IndexedDBKeyRange()
- : lower_open_(false),
- upper_open_(false) {
- lower_.SetNull();
- upper_.SetNull();
-}
-
-IndexedDBKeyRange::IndexedDBKeyRange(const WebIDBKeyRange& key_range) {
- lower_.Set(key_range.lower());
- upper_.Set(key_range.upper());
- lower_open_ = key_range.lowerOpen();
- upper_open_ = key_range.upperOpen();
-}
-
-IndexedDBKeyRange::~IndexedDBKeyRange() {
-}
-
-
-void IndexedDBKeyRange::Set(const IndexedDBKey& lower,
- const IndexedDBKey& upper,
- bool lower_open, bool upper_open) {
- lower_.Set(lower);
- upper_.Set(upper);
- lower_open_ = lower_open;
- upper_open_ = upper_open;
+ : lower_(WebIDBKey::NullType),
+ upper_(WebIDBKey::NullType),
+ lower_open_(false),
+ upper_open_(false) {}
+
+IndexedDBKeyRange::IndexedDBKeyRange(const WebIDBKeyRange& key_range)
+ : lower_(key_range.lower()),
+ upper_(key_range.upper()),
+ lower_open_(key_range.lowerOpen()),
+ upper_open_(key_range.upperOpen()) {}
+
+IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower,
+ const IndexedDBKey& upper,
+ bool lower_open,
+ bool upper_open)
+ : lower_(lower),
+ upper_(upper),
+ lower_open_(lower_open),
+ upper_open_(upper_open) {}
+
+IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& key)
+ : lower_(key), upper_(key), lower_open_(false), upper_open_(false) {}
+
+IndexedDBKeyRange::~IndexedDBKeyRange() {}
+
+bool IndexedDBKeyRange::IsOnlyKey() const {
+ if (lower_open_ || upper_open_)
+ return false;
+
+ return lower_.IsEqual(upper_);
}
IndexedDBKeyRange::operator WebIDBKeyRange() const {
diff --git a/content/common/indexed_db/indexed_db_key_range.h b/content/common/indexed_db/indexed_db_key_range.h
index 9cc9043..9f8684a 100644
--- a/content/common/indexed_db/indexed_db_key_range.h
+++ b/content/common/indexed_db/indexed_db_key_range.h
@@ -16,6 +16,11 @@ class CONTENT_EXPORT IndexedDBKeyRange {
public:
IndexedDBKeyRange();
explicit IndexedDBKeyRange(const WebKit::WebIDBKeyRange& key_range);
+ explicit IndexedDBKeyRange(const IndexedDBKey& onlyKey);
+ IndexedDBKeyRange(const IndexedDBKey& lower,
+ const IndexedDBKey& upper,
+ bool lower_open,
+ bool upper_open);
~IndexedDBKeyRange();
const IndexedDBKey& lower() const { return lower_; }
@@ -23,8 +28,7 @@ class CONTENT_EXPORT IndexedDBKeyRange {
bool lowerOpen() const { return lower_open_; }
bool upperOpen() const { return upper_open_; }
- void Set(const IndexedDBKey& lower, const IndexedDBKey& upper,
- bool lower_open, bool upper_open);
+ bool IsOnlyKey() const;
operator WebKit::WebIDBKeyRange() const;
diff --git a/content/common/indexed_db/indexed_db_param_traits.cc b/content/common/indexed_db/indexed_db_param_traits.cc
index 0d0e4b8..fd6421f 100644
--- a/content/common/indexed_db/indexed_db_param_traits.cc
+++ b/content/common/indexed_db/indexed_db_param_traits.cc
@@ -13,26 +13,28 @@ using content::IndexedDBKey;
using content::IndexedDBKeyPath;
using content::IndexedDBKeyRange;
+using WebKit::WebIDBKey;
+using WebKit::WebIDBKeyPath;
+
namespace IPC {
-void ParamTraits<IndexedDBKey>::Write(Message* m,
- const param_type& p) {
+void ParamTraits<IndexedDBKey>::Write(Message* m, const param_type& p) {
WriteParam(m, int(p.type()));
switch (p.type()) {
- case WebKit::WebIDBKey::ArrayType:
+ case WebIDBKey::ArrayType:
WriteParam(m, p.array());
return;
- case WebKit::WebIDBKey::StringType:
+ case WebIDBKey::StringType:
WriteParam(m, p.string());
return;
- case WebKit::WebIDBKey::DateType:
+ case WebIDBKey::DateType:
WriteParam(m, p.date());
return;
- case WebKit::WebIDBKey::NumberType:
+ case WebIDBKey::NumberType:
WriteParam(m, p.number());
return;
- case WebKit::WebIDBKey::InvalidType:
- case WebKit::WebIDBKey::NullType:
+ case WebIDBKey::InvalidType:
+ case WebIDBKey::NullType:
return;
default:
// This is a placeholder for WebKit::WebIDBKey::MinType
@@ -47,49 +49,41 @@ bool ParamTraits<IndexedDBKey>::Read(const Message* m,
int type;
if (!ReadParam(m, iter, &type))
return false;
+ WebIDBKey::Type web_type = static_cast<WebIDBKey::Type>(type);
- switch (type) {
- case WebKit::WebIDBKey::ArrayType: {
+ switch (web_type) {
+ case WebIDBKey::ArrayType: {
std::vector<IndexedDBKey> array;
if (!ReadParam(m, iter, &array))
return false;
- r->SetArray(array);
+ *r = IndexedDBKey(array);
return true;
}
- case WebKit::WebIDBKey::StringType: {
+ case WebIDBKey::StringType: {
string16 string;
if (!ReadParam(m, iter, &string))
return false;
- r->SetString(string);
+ *r = IndexedDBKey(string);
return true;
}
- case WebKit::WebIDBKey::DateType: {
- double date;
- if (!ReadParam(m, iter, &date))
- return false;
- r->SetDate(date);
- return true;
- }
- case WebKit::WebIDBKey::NumberType: {
+ case WebIDBKey::DateType:
+ case WebIDBKey::NumberType: {
double number;
if (!ReadParam(m, iter, &number))
return false;
- r->SetNumber(number);
+ *r = IndexedDBKey(number, web_type);
return true;
}
- case WebKit::WebIDBKey::InvalidType:
- r->SetInvalid();
- return true;
- case WebKit::WebIDBKey::NullType:
- r->SetNull();
+ case WebIDBKey::InvalidType:
+ case WebIDBKey::NullType:
+ *r = IndexedDBKey(web_type);
return true;
}
NOTREACHED();
return false;
}
-void ParamTraits<IndexedDBKey>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) {
l->append("<IndexedDBKey>(");
LogParam(int(p.type()), l);
l->append(", ");
@@ -110,17 +104,16 @@ void ParamTraits<IndexedDBKey>::Log(const param_type& p,
l->append(")");
}
-void ParamTraits<IndexedDBKeyPath>::Write(Message* m,
- const param_type& p) {
+void ParamTraits<IndexedDBKeyPath>::Write(Message* m, const param_type& p) {
WriteParam(m, int(p.type()));
switch (p.type()) {
- case WebKit::WebIDBKeyPath::ArrayType:
+ case WebIDBKeyPath::ArrayType:
WriteParam(m, p.array());
return;
- case WebKit::WebIDBKeyPath::StringType:
+ case WebIDBKeyPath::StringType:
WriteParam(m, p.string());
return;
- case WebKit::WebIDBKeyPath::NullType:
+ case WebIDBKeyPath::NullType:
return;
}
NOTREACHED();
@@ -134,21 +127,21 @@ bool ParamTraits<IndexedDBKeyPath>::Read(const Message* m,
return false;
switch (type) {
- case WebKit::WebIDBKeyPath::ArrayType: {
+ case WebIDBKeyPath::ArrayType: {
std::vector<string16> array;
if (!ReadParam(m, iter, &array))
return false;
r->SetArray(array);
return true;
}
- case WebKit::WebIDBKeyPath::StringType: {
+ case WebIDBKeyPath::StringType: {
string16 string;
if (!ReadParam(m, iter, &string))
return false;
r->SetString(string);
return true;
}
- case WebKit::WebIDBKeyPath::NullType:
+ case WebIDBKeyPath::NullType:
r->SetNull();
return true;
}
@@ -156,8 +149,7 @@ bool ParamTraits<IndexedDBKeyPath>::Read(const Message* m,
return false;
}
-void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p, std::string* l) {
l->append("<IndexedDBKeyPath>(");
LogParam(int(p.type()), l);
l->append(", ");
@@ -174,8 +166,7 @@ void ParamTraits<IndexedDBKeyPath>::Log(const param_type& p,
l->append("])");
}
-void ParamTraits<IndexedDBKeyRange>::Write(Message* m,
- const param_type& p) {
+void ParamTraits<IndexedDBKeyRange>::Write(Message* m, const param_type& p) {
WriteParam(m, p.lower());
WriteParam(m, p.upper());
WriteParam(m, p.lowerOpen());
@@ -201,12 +192,11 @@ bool ParamTraits<IndexedDBKeyRange>::Read(const Message* m,
if (!ReadParam(m, iter, &upper_open))
return false;
- r->Set(lower, upper, lower_open, upper_open);
+ *r = IndexedDBKeyRange(lower, upper, lower_open, upper_open);
return true;
}
-void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<IndexedDBKeyRange>::Log(const param_type& p, std::string* l) {
l->append("<IndexedDBKeyRange>(lower=");
LogParam(p.lower(), l);
l->append(", upper=");
diff --git a/content/common/indexed_db/proxy_webidbcursor_impl_unittest.cc b/content/common/indexed_db/proxy_webidbcursor_impl_unittest.cc
index ffbd02c..fdb02e1 100644
--- a/content/common/indexed_db/proxy_webidbcursor_impl_unittest.cc
+++ b/content/common/indexed_db/proxy_webidbcursor_impl_unittest.cc
@@ -24,25 +24,22 @@ namespace {
class MockDispatcher : public IndexedDBDispatcher {
public:
MockDispatcher()
- : prefetch_calls_(0)
- , last_prefetch_count_(0)
- , continue_calls_(0)
- , destroyed_cursor_id_(0) {
- }
-
- virtual void RequestIDBCursorPrefetch(
- int n,
- WebIDBCallbacks* callbacks,
- int32 ipc_cursor_id) OVERRIDE {
+ : prefetch_calls_(0),
+ last_prefetch_count_(0),
+ continue_calls_(0),
+ destroyed_cursor_id_(0) {}
+
+ virtual void RequestIDBCursorPrefetch(int n,
+ WebIDBCallbacks* callbacks,
+ int32 ipc_cursor_id) OVERRIDE {
++prefetch_calls_;
last_prefetch_count_ = n;
callbacks_.reset(callbacks);
}
- virtual void RequestIDBCursorContinue(
- const IndexedDBKey&,
- WebIDBCallbacks* callbacks,
- int32 ipc_cursor_id) OVERRIDE {
+ virtual void RequestIDBCursorContinue(const IndexedDBKey&,
+ WebIDBCallbacks* callbacks,
+ int32 ipc_cursor_id) OVERRIDE {
++continue_calls_;
callbacks_.reset(callbacks);
}
@@ -66,15 +63,14 @@ class MockDispatcher : public IndexedDBDispatcher {
class MockContinueCallbacks : public WebIDBCallbacks {
public:
- MockContinueCallbacks(IndexedDBKey* key = 0)
- : key_(key) {
- }
+ MockContinueCallbacks(IndexedDBKey* key = 0) : key_(key) {}
virtual void onSuccess(const WebIDBKey& key,
const WebIDBKey& primaryKey,
const WebData& value) {
+
if (key_)
- key_->Set(key);
+ *key_ = IndexedDBKey(key);
}
private:
@@ -99,8 +95,8 @@ TEST(RendererWebIDBCursorImplTest, PrefetchTest) {
for (int i = 0; i < RendererWebIDBCursorImpl::kPrefetchContinueThreshold;
++i) {
cursor.continueFunction(null_key, new MockContinueCallbacks());
- EXPECT_EQ(dispatcher.continue_calls(), ++continue_calls);
- EXPECT_EQ(dispatcher.prefetch_calls(), 0);
+ EXPECT_EQ(++continue_calls, dispatcher.continue_calls());
+ EXPECT_EQ(0, dispatcher.prefetch_calls());
}
// Do enough repetitions to verify that the count grows each time,
@@ -114,8 +110,8 @@ TEST(RendererWebIDBCursorImplTest, PrefetchTest) {
// Initiate the prefetch
cursor.continueFunction(null_key, new MockContinueCallbacks());
- EXPECT_EQ(dispatcher.continue_calls(), continue_calls);
- EXPECT_EQ(dispatcher.prefetch_calls(), repetitions + 1);
+ EXPECT_EQ(continue_calls, dispatcher.continue_calls());
+ EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls());
// Verify that the requested count has increased since last time.
int prefetch_count = dispatcher.last_prefetch_count();
@@ -123,11 +119,11 @@ TEST(RendererWebIDBCursorImplTest, PrefetchTest) {
last_prefetch_count = prefetch_count;
// Fill the prefetch cache as requested.
- std::vector<IndexedDBKey> keys(prefetch_count);
+ std::vector<IndexedDBKey> keys;
std::vector<IndexedDBKey> primary_keys(prefetch_count);
std::vector<WebData> values(prefetch_count);
for (int i = 0; i < prefetch_count; ++i) {
- keys[i].SetNumber(expected_key + i);
+ keys.push_back(IndexedDBKey(expected_key + i, WebIDBKey::NumberType));
}
cursor.SetPrefetchData(keys, primary_keys, values);
@@ -139,11 +135,11 @@ TEST(RendererWebIDBCursorImplTest, PrefetchTest) {
for (int i = 0; i < prefetch_count; ++i) {
IndexedDBKey key;
cursor.continueFunction(null_key, new MockContinueCallbacks(&key));
- EXPECT_EQ(dispatcher.continue_calls(), continue_calls);
- EXPECT_EQ(dispatcher.prefetch_calls(), repetitions + 1);
+ EXPECT_EQ(continue_calls, dispatcher.continue_calls());
+ EXPECT_EQ(repetitions + 1, dispatcher.prefetch_calls());
- EXPECT_EQ(key.type(), WebIDBKey::NumberType);
- EXPECT_EQ(key.number(), expected_key++);
+ EXPECT_EQ(WebIDBKey::NumberType, key.type());
+ EXPECT_EQ(expected_key++, key.number());
}
}
}