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

Unified Diff: content/common/indexed_db/indexed_db_data_format_version.h

Issue 2773823002: Use a two-part data format version in IndexedDB metadata. (Closed)
Patch Set: partially revert test change Created 3 years, 9 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_data_format_version.h
diff --git a/content/common/indexed_db/indexed_db_data_format_version.h b/content/common/indexed_db/indexed_db_data_format_version.h
new file mode 100644
index 0000000000000000000000000000000000000000..4663537f9e3c741587187799634a26baa82dd535
--- /dev/null
+++ b/content/common/indexed_db/indexed_db_data_format_version.h
@@ -0,0 +1,59 @@
+// Copyright 2017 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_DATA_FORMAT_VERSION_H_
+#define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_
+
+#include <cstdint>
+#include <limits>
+
+#include "base/logging.h"
+
+namespace content {
+
+// Contains version data for the wire format used for encoding IndexedDB values.
+// A version tuple (a, b) is at least as new as (a', b')
+// iff a >= a' and b >= b'.
+class IndexedDBDataFormatVersion {
+ public:
+ IndexedDBDataFormatVersion() {}
+ IndexedDBDataFormatVersion(uint32_t v8_version, uint32_t blink_version)
+ : v8_version_(v8_version), blink_version_(blink_version) {}
+
+ uint32_t v8_version() const { return v8_version_; }
+ uint32_t blink_version() const { return blink_version_; }
+
+ bool operator==(const IndexedDBDataFormatVersion& other) const {
+ return v8_version_ == other.v8_version_ &&
+ blink_version_ == other.blink_version_;
+ }
+ bool operator!=(const IndexedDBDataFormatVersion& other) const {
+ return !operator==(other);
+ }
+
+ bool IsAtLeast(const IndexedDBDataFormatVersion& other) const {
+ return v8_version_ >= other.v8_version_ &&
+ blink_version_ >= other.blink_version_;
+ }
+
+ // Encodes and decodes the tuple from an int64_t.
jsbell 2017/04/03 18:08:26 Can you update content/browser/indexed_db/leveldb_
jbroman 2017/04/04 18:50:38 Done.
+ // Since negative values are considered invalid, this scheme will only work
+ // the v8 version would overflow int32_t. We check both, to be consistent.
jsbell 2017/04/03 18:08:26 Also note that the encoding scheme is chosen such
jbroman 2017/04/04 18:50:38 Done.
+ int64_t Encode() const {
+ DCHECK_GE(static_cast<int32_t>(v8_version_), 0);
+ DCHECK_GE(static_cast<int32_t>(blink_version_), 0);
+ return (static_cast<int64_t>(v8_version_) << 32) | blink_version_;
+ }
+ static IndexedDBDataFormatVersion Decode(int64_t encoded) {
jsbell 2017/04/03 18:08:26 DCHECK_GE(encoded, 0) ?
jbroman 2017/04/04 18:50:38 Done.
+ return IndexedDBDataFormatVersion(encoded >> 32, encoded);
+ }
+
+ private:
+ uint32_t v8_version_ = 0;
+ uint32_t blink_version_ = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_

Powered by Google App Engine
This is Rietveld 408576698