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 |