diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 23:49:25 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 23:49:25 +0000 |
commit | f2c859a17e291cd481f89b55b79ac5450a81fcd0 (patch) | |
tree | fe38ce3e7712809d56967dc00316d85077ccc496 /base/rand_util_posix.cc | |
parent | c010c40a4aca2cb281c2e7a3c75cec24d2558661 (diff) | |
download | chromium_src-f2c859a17e291cd481f89b55b79ac5450a81fcd0.zip chromium_src-f2c859a17e291cd481f89b55b79ac5450a81fcd0.tar.gz chromium_src-f2c859a17e291cd481f89b55b79ac5450a81fcd0.tar.bz2 |
Factoring GUID generation from metrics to base
Factors GUID generation into base/rand_util. The Autofill feature is in need of this utility so am factoring GUID generation out of metrics and moving to the commons.
BUG=58813
TEST=RandUtilTest.GUIDGeneratesAllZeroes, RandUtilTest.GUIDGeneratesCorrectly, RandUtilTest.GUIDCorrectlyFormatted, MetricsServiceTest.ClientIdCorrectlyFormatted
Review URL: http://codereview.chromium.org/3800001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/rand_util_posix.cc')
-rw-r--r-- | base/rand_util_posix.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/base/rand_util_posix.cc b/base/rand_util_posix.cc index 43dfd1e..6a0a203 100644 --- a/base/rand_util_posix.cc +++ b/base/rand_util_posix.cc @@ -12,6 +12,7 @@ #include "base/file_util.h" #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/stringprintf.h" namespace { @@ -54,6 +55,22 @@ uint64 RandUint64() { return number; } +// TODO(cmasone): Once we're comfortable this works, migrate Windows code to +// use this as well. +std::string RandomBytesToGUIDString(const uint64 bytes[2]) { + return StringPrintf("%08X-%04X-%04X-%04X-%012llX", + static_cast<unsigned int>(bytes[0] >> 32), + static_cast<unsigned int>((bytes[0] >> 16) & 0x0000ffff), + static_cast<unsigned int>(bytes[0] & 0x0000ffff), + static_cast<unsigned int>(bytes[1] >> 48), + bytes[1] & 0x0000ffffffffffffULL); +} + +std::string GenerateGUID() { + uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() }; + return RandomBytesToGUIDString(sixteen_bytes); +} + } // namespace base int GetUrandomFD(void) { |