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

Side by Side Diff: content/browser/indexed_db/indexed_db_data_format_version.h

Issue 2773823002: Use a two-part data format version in IndexedDB metadata. (Closed)
Patch Set: rename blink constants Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_
7
8 #include <cstdint>
9 #include <limits>
10
11 #include "base/logging.h"
12 #include "content/common/content_export.h"
13
14 namespace content {
15
16 // Contains version data for the wire format used for encoding IndexedDB values.
17 // A version tuple (a, b) is at least as new as (a', b')
18 // iff a >= a' and b >= b'.
19 class IndexedDBDataFormatVersion {
20 public:
21 constexpr IndexedDBDataFormatVersion() {}
22 constexpr IndexedDBDataFormatVersion(uint32_t v8_version,
23 uint32_t blink_version)
24 : v8_version_(v8_version), blink_version_(blink_version) {}
25
26 static IndexedDBDataFormatVersion GetCurrent() { return current_; }
27 static IndexedDBDataFormatVersion& GetMutableCurrentForTesting() {
28 return current_;
29 }
30
31 uint32_t v8_version() const { return v8_version_; }
32 uint32_t blink_version() const { return blink_version_; }
33
34 bool operator==(const IndexedDBDataFormatVersion& other) const {
35 return v8_version_ == other.v8_version_ &&
36 blink_version_ == other.blink_version_;
37 }
38 bool operator!=(const IndexedDBDataFormatVersion& other) const {
39 return !operator==(other);
40 }
41
42 bool IsAtLeast(const IndexedDBDataFormatVersion& other) const {
43 return v8_version_ >= other.v8_version_ &&
44 blink_version_ >= other.blink_version_;
45 }
46
47 // Encodes and decodes the tuple from an int64_t.
48 // This scheme is chosen so that earlier versions (before we reported both the
49 // Blink and V8 versions) decode properly, with a V8 version of 0.
50 int64_t Encode() const {
51 // Since negative values are considered invalid, this scheme will only work
52 // as long as the v8 version would not overflow int32_t. We check both
53 // components, to be consistent.
54 DCHECK_GE(static_cast<int32_t>(v8_version_), 0);
55 DCHECK_GE(static_cast<int32_t>(blink_version_), 0);
56 return (static_cast<int64_t>(v8_version_) << 32) | blink_version_;
57 }
58 static IndexedDBDataFormatVersion Decode(int64_t encoded) {
59 DCHECK_GE(encoded, 0);
60 return IndexedDBDataFormatVersion(encoded >> 32, encoded);
61 }
62
63 private:
64 uint32_t v8_version_ = 0;
65 uint32_t blink_version_ = 0;
66
67 CONTENT_EXPORT static IndexedDBDataFormatVersion current_;
68 };
69
70 } // namespace content
71
72 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.cc ('k') | content/browser/indexed_db/indexed_db_data_format_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698