Chromium Code Reviews| 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. | |
| 41 // Since negative values are considered invalid, this scheme will only work | |
|
dcheng
2017/04/04 19:59:21
Nit: I think there's a missing word or two here.
| |
| 42 // the v8 version would overflow int32_t. We check both, to be consistent. | |
| 43 // | |
| 44 // This scheme is chosen so that earlier versions (before we reported both the | |
| 45 // Blink and V8 versions) decode properly, with a V8 version of 0. | |
| 46 int64_t Encode() const { | |
| 47 DCHECK_GE(static_cast<int32_t>(v8_version_), 0); | |
| 48 DCHECK_GE(static_cast<int32_t>(blink_version_), 0); | |
| 49 return (static_cast<int64_t>(v8_version_) << 32) | blink_version_; | |
| 50 } | |
| 51 static IndexedDBDataFormatVersion Decode(int64_t encoded) { | |
| 52 DCHECK_GE(encoded, 0); | |
| 53 return IndexedDBDataFormatVersion(encoded >> 32, encoded); | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 uint32_t v8_version_ = 0; | |
| 58 uint32_t blink_version_ = 0; | |
| 59 }; | |
| 60 | |
| 61 } // namespace content | |
| 62 | |
| 63 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DATA_FORMAT_VERSION_H_ | |
| OLD | NEW |