summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 20:34:59 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 20:34:59 +0000
commit3469e7e544aeea3a5cee8aee9a8891a29c61a17d (patch)
tree4d9d1056f06f90f724ba702e94aa2b4d47da7fa6 /base
parent94e9666e60bf1d5e3559bfe216845a2cb054b204 (diff)
downloadchromium_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 'base')
-rw-r--r--base/rand_util.h5
-rw-r--r--base/rand_util_posix.cc17
-rw-r--r--base/rand_util_unittest.cc47
-rw-r--r--base/rand_util_win.cc20
4 files changed, 0 insertions, 89 deletions
diff --git a/base/rand_util.h b/base/rand_util.h
index d298134..699fc7f 100644
--- a/base/rand_util.h
+++ b/base/rand_util.h
@@ -6,8 +6,6 @@
#define BASE_RAND_UTIL_H_
#pragma once
-#include <string>
-
#include "base/basictypes.h"
namespace base {
@@ -28,9 +26,6 @@ uint64 RandGenerator(uint64 max);
// Returns a random double in range [0, 1). Thread-safe.
double RandDouble();
-// Generate a 128-bit random GUID of the form: "%08X-%04X-%04X-%04X-%012llX".
-std::string GenerateGUID();
-
} // namespace base
#endif // BASE_RAND_UTIL_H_
diff --git a/base/rand_util_posix.cc b/base/rand_util_posix.cc
index 6a0a203..43dfd1e 100644
--- a/base/rand_util_posix.cc
+++ b/base/rand_util_posix.cc
@@ -12,7 +12,6 @@
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/stringprintf.h"
namespace {
@@ -55,22 +54,6 @@ 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) {
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index 112099f..cbc338a 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -35,50 +35,3 @@ TEST(RandUtilTest, RandGeneratorForRandomShuffle) {
EXPECT_LE(std::numeric_limits<ptrdiff_t>::max(),
std::numeric_limits<int64>::max());
}
-
-#if defined(OS_POSIX)
-// For unit testing purposes only. Do not use outside of tests.
-namespace base {
-extern std::string RandomBytesToGUIDString(const uint64 bytes[2]);
-} // base
-
-TEST(RandUtilTest, GUIDGeneratesAllZeroes) {
- uint64 bytes[] = { 0, 0 };
- std::string clientid = base::RandomBytesToGUIDString(bytes);
- EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
-}
-
-TEST(RandUtilTest, GUIDGeneratesCorrectly) {
- uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
- std::string clientid = base::RandomBytesToGUIDString(bytes);
- EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
-}
-#endif
-
-TEST(RandUtilTest, GUIDCorrectlyFormatted) {
- const int kIterations = 10;
- for (int it = 0; it < kIterations; ++it) {
- std::string guid = base::GenerateGUID();
- EXPECT_EQ(36U, guid.length());
- std::string hexchars = "0123456789ABCDEF";
- for (uint32 i = 0; i < guid.length(); ++i) {
- char current = guid.at(i);
- if (i == 8 || i == 13 || i == 18 || i == 23) {
- EXPECT_EQ('-', current);
- } else {
- EXPECT_TRUE(std::string::npos != hexchars.find(current));
- }
- }
- }
-}
-
-TEST(RandUtilTest, GUIDBasicUniqueness) {
- const int kIterations = 10;
- for (int it = 0; it < kIterations; ++it) {
- std::string guid1 = base::GenerateGUID();
- std::string guid2 = base::GenerateGUID();
- EXPECT_EQ(36U, guid1.length());
- EXPECT_EQ(36U, guid2.length());
- EXPECT_NE(guid1, guid2);
- }
-}
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
index 5437177..ec0411e 100644
--- a/base/rand_util_win.cc
+++ b/base/rand_util_win.cc
@@ -6,13 +6,8 @@
#include <stdlib.h>
-#include <objbase.h>
-#include <windows.h>
-
#include "base/basictypes.h"
#include "base/logging.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
namespace {
@@ -32,19 +27,4 @@ uint64 RandUint64() {
return (static_cast<uint64>(first_half) << 32) + second_half;
}
-std::string GenerateGUID() {
- const int kGUIDSize = 39;
-
- GUID guid;
- HRESULT guid_result = CoCreateGuid(&guid);
- DCHECK(SUCCEEDED(guid_result));
-
- std::wstring guid_string;
- int result = StringFromGUID2(guid,
- WriteInto(&guid_string, kGUIDSize), kGUIDSize);
- DCHECK(result == kGUIDSize);
-
- return WideToUTF8(guid_string.substr(1, guid_string.length() - 2));
-}
-
} // namespace base