Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2588)

Unified Diff: base/rand_util_win.cc

Issue 3800001: Factoring GUID generation from metrics to base (Closed)
Patch Set: Adding unit tests. Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/metrics/metrics_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util_win.cc
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
index ec0411efd3add4ba6be9d1ab57c53deb9c32cadf..5437177135ff9ba7376817ad21b421f2c30b38fe 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
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/metrics/metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698