summaryrefslogtreecommitdiffstats
path: root/base/rand_util_win.cc
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-13 23:49:25 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-13 23:49:25 +0000
commitf2c859a17e291cd481f89b55b79ac5450a81fcd0 (patch)
treefe38ce3e7712809d56967dc00316d85077ccc496 /base/rand_util_win.cc
parentc010c40a4aca2cb281c2e7a3c75cec24d2558661 (diff)
downloadchromium_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_win.cc')
-rw-r--r--base/rand_util_win.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
index ec0411e..5437177 100644
--- a/base/rand_util_win.cc
+++ b/base/rand_util_win.cc
@@ -6,8 +6,13 @@
#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 {
@@ -27,4 +32,19 @@ 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