diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 20:34:59 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 20:34:59 +0000 |
commit | 3469e7e544aeea3a5cee8aee9a8891a29c61a17d (patch) | |
tree | 4d9d1056f06f90f724ba702e94aa2b4d47da7fa6 /chrome/browser/guid_posix.cc | |
parent | 94e9666e60bf1d5e3559bfe216845a2cb054b204 (diff) | |
download | chromium_src-3469e7e544aeea3a5cee8aee9a8891a29c61a17d.zip chromium_src-3469e7e544aeea3a5cee8aee9a8891a29c61a17d.tar.gz chromium_src-3469e7e544aeea3a5cee8aee9a8891a29c61a17d.tar.bz2 |
Moving GUID generation from base to chrome/browser/guid*
Moves GUID generation into chrome/browser/guid*. GUID generation is used only within chrome/browser. So am moving it there.
BUG=58813
TEST=GUIDTest.GUIDGeneratesAllZeroes, GUIDTest.GUIDGeneratesCorrectly, GUIDTest.GUIDCorrectlyFormatted, MetricsServiceTest.ClientIdCorrectlyFormatted
Review URL: http://codereview.chromium.org/3800003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62639 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/guid_posix.cc')
-rw-r--r-- | chrome/browser/guid_posix.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/chrome/browser/guid_posix.cc b/chrome/browser/guid_posix.cc new file mode 100644 index 0000000..48d7198 --- /dev/null +++ b/chrome/browser/guid_posix.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/guid.h" + +#include "base/rand_util.h" +#include "base/stringprintf.h" + +namespace guid { + +std::string GenerateGUID() { + uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() }; + return RandomDataToGUIDString(sixteen_bytes); +} + +// TODO(cmasone): Once we're comfortable this works, migrate Windows code to +// use this as well. +std::string RandomDataToGUIDString(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); +} + +} // namespace guid |