Chromium Code Reviews| Index: cc/surfaces/surface_id.h |
| diff --git a/cc/surfaces/surface_id.h b/cc/surfaces/surface_id.h |
| index 48a434affe1309ba155534537d63b381d938bff8..0420aa0dbcfe4b9136b1dcb4fae7919d964b3a27 100644 |
| --- a/cc/surfaces/surface_id.h |
| +++ b/cc/surfaces/surface_id.h |
| @@ -13,12 +13,13 @@ |
| #include "base/format_macros.h" |
| #include "base/hash.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/unguessable_token.h" |
| namespace cc { |
| class SurfaceId { |
| public: |
| - SurfaceId() : client_id_(0), local_id_(0), nonce_(0) {} |
| + SurfaceId() : client_id_(0), local_id_(0), nonce_() {} |
|
Fady Samuel
2016/09/30 20:30:41
no need for calling the default constructor for no
Alex Z.
2016/10/05 18:10:45
Done.
|
| SurfaceId(const SurfaceId& other) |
| : client_id_(other.client_id_), |
| @@ -32,26 +33,36 @@ class SurfaceId { |
| // compositor client that uniquely identifies a surface. |
| // A |nonce| is a cryptographically secure random int that makes a SurfaceId |
| // unguessable by other clients. |
| - SurfaceId(uint32_t client_id, uint32_t local_id, uint64_t nonce) |
| + SurfaceId(uint32_t client_id, |
| + uint32_t local_id, |
| + const base::UnguessableToken& nonce) |
| : client_id_(client_id), local_id_(local_id), nonce_(nonce) {} |
| + SurfaceId(uint32_t client_id, uint32_t local_id) |
| + : client_id_(client_id), local_id_(local_id) { |
| + nonce_ = base::UnguessableToken::Create(); |
|
danakj
2016/09/30 20:45:12
do this as a constructor initializer
Alex Z.
2016/10/05 18:10:45
Done.
|
| + } |
| + |
| bool is_null() const { |
| - return client_id_ == 0 && nonce_ == 0 && local_id_ == 0; |
| + return client_id_ == 0 && nonce_ == base::UnguessableToken() && |
|
Fady Samuel
2016/09/30 20:30:41
nonce_.is_empty()
Alex Z.
2016/10/05 18:10:45
Done.
|
| + local_id_ == 0; |
| } |
| size_t hash() const { |
| size_t interim = base::HashInts(client_id_, local_id_); |
| - return base::HashInts(static_cast<uint64_t>(interim), nonce_); |
| + return base::HashInts(static_cast<uint64_t>(interim), |
|
danakj
2016/09/30 20:45:12
drop the static cast
Alex Z.
2016/10/05 18:10:45
Done.
|
| + base::UnguessableTokenHash()(nonce_)); |
| } |
| uint32_t client_id() const { return client_id_; } |
| uint32_t local_id() const { return local_id_; } |
| - uint64_t nonce() const { return nonce_; } |
| + base::UnguessableToken nonce() const { return nonce_; } |
|
Fady Samuel
2016/09/30 20:30:41
const base::UnguessableToken&
Alex Z.
2016/10/05 18:10:45
Done.
|
| std::string ToString() const { |
| - return base::StringPrintf("%d:%d:%" PRIu64, client_id_, local_id_, nonce_); |
| + return base::StringPrintf("%d:%d" PRIu64, client_id_, local_id_) |
| + .append(nonce_.ToString()); |
|
danakj
2016/09/30 20:45:11
you need a space between fields tho. i'd rather yo
Alex Z.
2016/10/05 18:10:45
Done.
|
| } |
| bool operator==(const SurfaceId& other) const { |
| @@ -70,7 +81,7 @@ class SurfaceId { |
| // See SurfaceIdAllocator::GenerateId. |
| uint32_t client_id_; |
| uint32_t local_id_; |
| - uint64_t nonce_; |
| + base::UnguessableToken nonce_; |
| }; |
| struct SurfaceIdHash { |