| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 CC_SURFACES_LOCAL_FRAME_ID_H_ | |
| 6 #define CC_SURFACES_LOCAL_FRAME_ID_H_ | |
| 7 | |
| 8 #include <inttypes.h> | |
| 9 | |
| 10 #include <iosfwd> | |
| 11 #include <string> | |
| 12 #include <tuple> | |
| 13 | |
| 14 #include "base/hash.h" | |
| 15 #include "base/unguessable_token.h" | |
| 16 #include "mojo/public/cpp/bindings/struct_traits.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 namespace mojom { | |
| 20 class LocalFrameIdDataView; | |
| 21 } | |
| 22 | |
| 23 class LocalFrameId { | |
| 24 public: | |
| 25 constexpr LocalFrameId() : local_id_(0) {} | |
| 26 | |
| 27 constexpr LocalFrameId(const LocalFrameId& other) | |
| 28 : local_id_(other.local_id_), nonce_(other.nonce_) {} | |
| 29 | |
| 30 constexpr LocalFrameId(uint32_t local_id, const base::UnguessableToken& nonce) | |
| 31 : local_id_(local_id), nonce_(nonce) {} | |
| 32 | |
| 33 constexpr bool is_valid() const { | |
| 34 return local_id_ != 0 && !nonce_.is_empty(); | |
| 35 } | |
| 36 | |
| 37 constexpr uint32_t local_id() const { return local_id_; } | |
| 38 | |
| 39 constexpr const base::UnguessableToken& nonce() const { return nonce_; } | |
| 40 | |
| 41 bool operator==(const LocalFrameId& other) const { | |
| 42 return local_id_ == other.local_id_ && nonce_ == other.nonce_; | |
| 43 } | |
| 44 | |
| 45 bool operator!=(const LocalFrameId& other) const { return !(*this == other); } | |
| 46 | |
| 47 bool operator<(const LocalFrameId& other) const { | |
| 48 return std::tie(local_id_, nonce_) < | |
| 49 std::tie(other.local_id_, other.nonce_); | |
| 50 } | |
| 51 | |
| 52 size_t hash() const { | |
| 53 return base::HashInts( | |
| 54 local_id_, static_cast<uint64_t>(base::UnguessableTokenHash()(nonce_))); | |
| 55 } | |
| 56 | |
| 57 std::string ToString() const; | |
| 58 | |
| 59 private: | |
| 60 friend struct mojo::StructTraits<mojom::LocalFrameIdDataView, LocalFrameId>; | |
| 61 | |
| 62 uint32_t local_id_; | |
| 63 base::UnguessableToken nonce_; | |
| 64 }; | |
| 65 | |
| 66 std::ostream& operator<<(std::ostream& out, const LocalFrameId& local_frame_id); | |
| 67 | |
| 68 struct LocalFrameIdHash { | |
| 69 size_t operator()(const LocalFrameId& key) const { return key.hash(); } | |
| 70 }; | |
| 71 | |
| 72 } // namespace cc | |
| 73 | |
| 74 #endif // CC_SURFACES_LOCAL_FRAME_ID_H_ | |
| OLD | NEW |