| Index: services/resource_coordinator/public/cpp/coordination_unit_id.cc
|
| diff --git a/services/resource_coordinator/public/cpp/coordination_unit_id.cc b/services/resource_coordinator/public/cpp/coordination_unit_id.cc
|
| index ed92241435916e788856675a623f576e3eb4aa2a..ea9cd5a56f5dc90f5b2186637484343b9d232301 100644
|
| --- a/services/resource_coordinator/public/cpp/coordination_unit_id.cc
|
| +++ b/services/resource_coordinator/public/cpp/coordination_unit_id.cc
|
| @@ -4,32 +4,38 @@
|
|
|
| #include "services/resource_coordinator/public/cpp/coordination_unit_id.h"
|
|
|
| -#include "base/logging.h"
|
| #include "base/numerics/safe_conversions.h"
|
| +#include "base/unguessable_token.h"
|
| #include "third_party/smhasher/src/MurmurHash2.h"
|
|
|
| namespace resource_coordinator {
|
|
|
| +namespace {
|
| +
|
| // The seed to use when taking the murmur2 hash of the id.
|
| const uint64_t kMurmur2HashSeed = 0;
|
|
|
| +uint64_t CreateMurmurHash64A(const std::string& id) {
|
| + DCHECK(base::IsValueInRangeForNumericType<int>(id.size()));
|
| +
|
| + return MurmurHash64A(&id.front(), static_cast<int>(id.size()),
|
| + kMurmur2HashSeed);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| CoordinationUnitID::CoordinationUnitID()
|
| : id(0), type(CoordinationUnitType::kInvalidType) {}
|
|
|
| CoordinationUnitID::CoordinationUnitID(const CoordinationUnitType& type,
|
| const std::string& new_id)
|
| : type(type) {
|
| - DCHECK(base::IsValueInRangeForNumericType<int>(new_id.size()));
|
| - if (!new_id.empty()) {
|
| - id = MurmurHash64A(&new_id.front(), static_cast<int>(new_id.size()),
|
| - kMurmur2HashSeed);
|
| - } else {
|
| - id = 0;
|
| - }
|
| + id = CreateMurmurHash64A(
|
| + !new_id.empty() ? new_id : base::UnguessableToken().Create().ToString());
|
| }
|
|
|
| CoordinationUnitID::CoordinationUnitID(const CoordinationUnitType& type,
|
| uint64_t new_id)
|
| : id(new_id), type(type) {}
|
|
|
| -} // resource_coordinator
|
| +} // namespace resource_coordinator
|
|
|