Index: util/misc/uuid.cc |
diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc |
index 904efcd339838d7b8a9d0e2f456ccfc49d5ffe6e..ca7b22b1fffed0494e2a1efca1ff50f4e91627c5 100644 |
--- a/util/misc/uuid.cc |
+++ b/util/misc/uuid.cc |
@@ -23,11 +23,16 @@ |
#include <string.h> |
#include "base/basictypes.h" |
+#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/sys_byteorder.h" |
#include "util/stdlib/cxx.h" |
+#if defined(OS_MACOSX) |
+#include <uuid/uuid.h> |
+#endif // OS_MACOSX |
+ |
#if CXX_LIBRARY_VERSION >= 2011 |
#include <type_traits> |
#endif |
@@ -44,6 +49,10 @@ static_assert(std::is_standard_layout<UUID>::value, |
UUID::UUID() : data_1(0), data_2(0), data_3(0), data_4(), data_5() { |
} |
+UUID::UUID(InitializeWithNewTag) { |
+ CHECK(InitializeWithNew()); |
+} |
+ |
UUID::UUID(const uint8_t* bytes) { |
InitializeFromBytes(bytes); |
} |
@@ -88,6 +97,25 @@ bool UUID::InitializeFromString(const base::StringPiece& string) { |
return true; |
} |
+bool UUID::InitializeWithNew() { |
+#if defined(OS_MACOSX) |
+ uuid_t uuid; |
+ uuid_generate(uuid); |
+ InitializeFromBytes(uuid); |
+ return true; |
+#elif defined(OS_WIN) |
+ ::UUID system_uuid; |
+ if (UuidCreate(&system_uuid) != RPC_S_OK) { |
+ LOG(ERROR) << "UuidCreate"; |
+ return false; |
+ } |
+ InitializeFromSystemUUID(&system_uuid); |
+ return true; |
+#else |
+#error Port. |
+#endif // OS_MACOSX |
+} |
+ |
#if defined(OS_WIN) |
void UUID::InitializeFromSystemUUID(const ::UUID* system_uuid) { |
static_assert(sizeof(::UUID) == sizeof(UUID), |