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

Unified Diff: content/common/indexed_db/indexed_db_key.cc

Issue 15564008: Migrate the IndexedDB backend from Blink to Chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Accessor naming, use LevelDBSlice ctor explicitly Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/common/indexed_db/indexed_db_key.cc
diff --git a/content/common/indexed_db/indexed_db_key.cc b/content/common/indexed_db/indexed_db_key.cc
index 76306fd834cd47df5028c3cfc13a27ef5057f3f1..4319fb3a492bcabca0f97b5382477a1ce26d5bc5 100644
--- a/content/common/indexed_db/indexed_db_key.cc
+++ b/content/common/indexed_db/indexed_db_key.cc
@@ -60,7 +60,7 @@ static IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) {
}
return result;
}
-} // namespace
+} // namespace
IndexedDBKey::IndexedDBKey()
: type_(WebIDBKey::NullType),
@@ -104,6 +104,8 @@ IndexedDBKey::IndexedDBKey(const string16& key)
IndexedDBKey::~IndexedDBKey() {}
int IndexedDBKey::Compare(const IndexedDBKey& other) const {
+ DCHECK(IsValid());
+ DCHECK(other.IsValid());
if (type_ != other.type_)
return type_ > other.type_ ? -1 : 1;
@@ -121,12 +123,12 @@ int IndexedDBKey::Compare(const IndexedDBKey& other) const {
case WebIDBKey::StringType:
return -other.string_.compare(string_);
case WebIDBKey::DateType:
+ return (date_ < other.date_) ? -1 : (date_ > other.date_) ? 1 : 0;
case WebIDBKey::NumberType:
return (number_ < other.number_) ? -1 : (number_ > other.number_) ? 1 : 0;
case WebIDBKey::InvalidType:
case WebIDBKey::NullType:
- default:
- // This is a placeholder for WebKit::WebIDBKey::MinType
+ case WebIDBKey::MinType:
NOTREACHED();
return 0;
}
@@ -140,6 +142,20 @@ bool IndexedDBKey::IsEqual(const IndexedDBKey& other) const {
return !Compare(other);
}
+bool IndexedDBKey::IsValid() const {
+ if (type_ == WebIDBKey::InvalidType || type_ == WebIDBKey::NullType)
+ return false;
+
+ if (type_ == WebIDBKey::ArrayType) {
+ for (size_t i = 0; i < array_.size(); i++) {
+ if (!array_[i].IsValid())
+ return false;
+ }
+ }
+
+ return true;
+}
+
IndexedDBKey::operator WebIDBKey() const {
switch (type_) {
case WebIDBKey::ArrayType:
@@ -154,8 +170,7 @@ IndexedDBKey::operator WebIDBKey() const {
return WebIDBKey::createInvalid();
case WebIDBKey::NullType:
return WebIDBKey::createNull();
- default:
- // This is a placeholder for WebKit::WebIDBKey::MinType
+ case WebIDBKey::MinType:
NOTREACHED();
return WebIDBKey::createInvalid();
}

Powered by Google App Engine
This is Rietveld 408576698