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 /chrome/browser/metrics | |
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 'chrome/browser/metrics')
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 41 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.h | 6 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service_unittest.cc | 22 |
3 files changed, 7 insertions, 62 deletions
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index b6d4c3f..e4c9a12 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -158,15 +158,11 @@ #include "chrome/browser/metrics/metrics_service.h" -#if defined(OS_WIN) -#include <windows.h> -#include <objbase.h> -#endif - #include "base/base64.h" #include "base/command_line.h" #include "base/histogram.h" #include "base/md5.h" +#include "base/rand_util.h" #include "base/string_number_conversions.h" #include "base/thread.h" #include "base/utf_string_conversions.h" @@ -192,10 +188,6 @@ #include "webkit/glue/plugins/webplugininfo.h" #include "libxml/xmlwriter.h" -#if !defined(OS_WIN) -#include "base/rand_util.h" -#endif - // TODO(port): port browser_distribution.h. #if !defined(OS_POSIX) #include "chrome/installer/util/browser_distribution.h" @@ -816,38 +808,9 @@ void MetricsService::OnInitTaskComplete( } std::string MetricsService::GenerateClientID() { -#if defined(OS_WIN) - 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)); -#else - uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() }; - return RandomBytesToGUIDString(sixteen_bytes); -#endif + return base::GenerateGUID(); } -#if defined(OS_POSIX) -// TODO(cmasone): Once we're comfortable this works, migrate Windows code to -// use this as well. -std::string MetricsService::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); -} -#endif - //------------------------------------------------------------------------------ // State save methods diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index 650935a..f1cfbb2 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -192,12 +192,6 @@ class MetricsService : public NotificationObserver, // Generates a new client ID to use to identify self to metrics server. static std::string GenerateClientID(); -#if defined(OS_POSIX) - // Generates a new client ID to use to identify self to metrics server, - // given 128 bits of randomness. - static std::string RandomBytesToGUIDString(const uint64 bytes[2]); -#endif - // Schedule the next save of LocalState information. This is called // automatically by the task that performs each save to schedule the next one. void ScheduleNextStateSave(); diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc index a5ec080..9e7b463 100644 --- a/chrome/browser/metrics/metrics_service_unittest.cc +++ b/chrome/browser/metrics/metrics_service_unittest.cc @@ -13,18 +13,12 @@ #include "testing/gtest/include/gtest/gtest.h" -#if defined(OS_POSIX) && defined(LINUX2) -TEST(MetricsServiceTest, ClientIdGeneratesAllZeroes) { - uint64 bytes[] = { 0, 0 }; - std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); - EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); -} -TEST(MetricsServiceTest, ClientIdGeneratesCorrectly) { - uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; - std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); - EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); -} +class MetricsServiceTest : public ::testing::Test { +}; + +static const size_t kMaxLocalListSize = 3; +// Ensure the ClientId is formatted as expected. TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { std::string clientid = MetricsService::GenerateClientID(); EXPECT_EQ(36U, clientid.length()); @@ -38,12 +32,6 @@ TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { } } } -#endif - -class MetricsServiceTest : public ::testing::Test { -}; - -static const size_t kMaxLocalListSize = 3; // Store and retrieve empty list. TEST(MetricsServiceTest, EmptyLogList) { |