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

Side by Side Diff: cc/surfaces/local_frame_id.h

Issue 2379653006: Replaced cc::SurfaceId::nonce_ with base::UnguessableToken (Closed)
Patch Set: Changed comments in surface_id.h to reflect the change Created 4 years, 2 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_SURFACES_LOCAL_FRAME_ID_H_ 5 #ifndef CC_SURFACES_LOCAL_FRAME_ID_H_
6 #define CC_SURFACES_LOCAL_FRAME_ID_H_ 6 #define CC_SURFACES_LOCAL_FRAME_ID_H_
7 7
8 #include <inttypes.h> 8 #include <inttypes.h>
9 #include <tuple> 9 #include <tuple>
10 10
11 #include "base/hash.h" 11 #include "base/hash.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/unguessable_token.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 class LocalFrameId { 17 class LocalFrameId {
17 public: 18 public:
18 constexpr LocalFrameId() : local_id_(0), nonce_(0) {} 19 constexpr LocalFrameId() : local_id_(0) {}
19 20
20 constexpr LocalFrameId(const LocalFrameId& other) 21 constexpr LocalFrameId(const LocalFrameId& other)
21 : local_id_(other.local_id_), nonce_(other.nonce_) {} 22 : local_id_(other.local_id_), nonce_(other.nonce_) {}
22 23
23 constexpr LocalFrameId(uint32_t local_id, uint64_t nonce) 24 constexpr LocalFrameId(uint32_t local_id, const base::UnguessableToken& nonce)
24 : local_id_(local_id), nonce_(nonce) {} 25 : local_id_(local_id), nonce_(nonce) {}
25 26
26 constexpr bool is_null() const { return local_id_ == 0 && nonce_ == 0; } 27 constexpr bool is_null() const { return local_id_ == 0 && nonce_.is_empty(); }
27 28
28 constexpr uint32_t local_id() const { return local_id_; } 29 constexpr uint32_t local_id() const { return local_id_; }
29 30
30 constexpr uint64_t nonce() const { return nonce_; } 31 constexpr const base::UnguessableToken& nonce() const { return nonce_; }
31 32
32 bool operator==(const LocalFrameId& other) const { 33 bool operator==(const LocalFrameId& other) const {
33 return local_id_ == other.local_id_ && nonce_ == other.nonce_; 34 return local_id_ == other.local_id_ && nonce_ == other.nonce_;
34 } 35 }
35 36
36 bool operator!=(const LocalFrameId& other) const { return !(*this == other); } 37 bool operator!=(const LocalFrameId& other) const { return !(*this == other); }
37 38
38 bool operator<(const LocalFrameId& other) const { 39 bool operator<(const LocalFrameId& other) const {
39 return std::tie(local_id_, nonce_) < 40 return std::tie(local_id_, nonce_) <
40 std::tie(other.local_id_, other.nonce_); 41 std::tie(other.local_id_, other.nonce_);
41 } 42 }
42 43
43 size_t hash() const { return base::HashInts(local_id_, nonce_); } 44 size_t hash() const {
45 return base::HashInts(local_id_, base::UnguessableTokenHash()(nonce_));
46 }
44 47
45 std::string ToString() const { 48 std::string ToString() const {
46 return base::StringPrintf("LocalFrameId(%d, %" PRIu64 ")", local_id_, 49 return base::StringPrintf("LocalFrameId(%d, %s" PRIu64 ")", local_id_,
47 nonce_); 50 nonce_.ToString().c_str());
48 } 51 }
49 52
50 private: 53 private:
51 uint32_t local_id_; 54 uint32_t local_id_;
52 uint64_t nonce_; 55 base::UnguessableToken nonce_;
53 }; 56 };
54 57
55 struct LocalFrameIdHash { 58 struct LocalFrameIdHash {
56 size_t operator()(const LocalFrameId& key) const { return key.hash(); } 59 size_t operator()(const LocalFrameId& key) const { return key.hash(); }
57 }; 60 };
58 61
59 } // namespace cc 62 } // namespace cc
60 63
61 #endif // CC_SURFACES_LOCAL_FRAME_ID_H_ 64 #endif // CC_SURFACES_LOCAL_FRAME_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698