OLD | NEW |
---|---|
(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_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_ | |
6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_ | |
7 | |
8 #include <cstdint> | |
9 #include <limits> | |
10 | |
11 #include "base/logging.h" | |
12 | |
13 namespace content { | |
14 | |
15 // Contains version data for the wire format used for encoding IndexedDB values. | |
16 // A version tuple (a, b) is at least as new as (a', b') | |
17 // iff a >= a' and b >= b'. | |
18 class IndexedDBDataFormatVersion { | |
19 public: | |
20 IndexedDBDataFormatVersion() {} | |
21 IndexedDBDataFormatVersion(uint32_t v8_version, uint32_t blink_version) | |
22 : v8_version_(v8_version), blink_version_(blink_version) {} | |
23 | |
24 uint32_t v8_version() const { return v8_version_; } | |
25 uint32_t blink_version() const { return blink_version_; } | |
26 | |
27 bool operator==(const IndexedDBDataFormatVersion& other) const { | |
28 return v8_version_ == other.v8_version_ && | |
29 blink_version_ == other.blink_version_; | |
30 } | |
31 bool operator!=(const IndexedDBDataFormatVersion& other) const { | |
32 return !operator==(other); | |
33 } | |
34 | |
35 bool IsAtLeast(const IndexedDBDataFormatVersion& other) const { | |
36 return v8_version_ >= other.v8_version_ && | |
37 blink_version_ >= other.blink_version_; | |
38 } | |
39 | |
40 // 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.
| |
41 // Since negative values are considered invalid, this scheme will only work | |
42 // 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.
| |
43 int64_t Encode() const { | |
44 DCHECK_GE(static_cast<int32_t>(v8_version_), 0); | |
45 DCHECK_GE(static_cast<int32_t>(blink_version_), 0); | |
46 return (static_cast<int64_t>(v8_version_) << 32) | blink_version_; | |
47 } | |
48 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.
| |
49 return IndexedDBDataFormatVersion(encoded >> 32, encoded); | |
50 } | |
51 | |
52 private: | |
53 uint32_t v8_version_ = 0; | |
54 uint32_t blink_version_ = 0; | |
55 }; | |
56 | |
57 } // namespace content | |
58 | |
59 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_ | |
OLD | NEW |