summaryrefslogtreecommitdiffstats
path: root/base/guid_posix.cc
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 14:22:07 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 14:22:07 +0000
commit7e49ad360632304e1890082e1605b2239956afdb (patch)
tree1e3451b1a1af73cc5996c218a2888e35f1337709 /base/guid_posix.cc
parentfacd6e7bd32c811fa8be9a065505f465396cd92e (diff)
downloadchromium_src-7e49ad360632304e1890082e1605b2239956afdb.zip
chromium_src-7e49ad360632304e1890082e1605b2239956afdb.tar.gz
chromium_src-7e49ad360632304e1890082e1605b2239956afdb.tar.bz2
Move guid generation from chrome/common/ to base/.
It will be needed in webkit/dom_storage/. BUG=NONE TEST=Existing tests. Review URL: https://chromiumcodereview.appspot.com/10540003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/guid_posix.cc')
-rw-r--r--base/guid_posix.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/base/guid_posix.cc b/base/guid_posix.cc
new file mode 100644
index 0000000..89811d0
--- /dev/null
+++ b/base/guid_posix.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/guid.h"
+
+#include "base/rand_util.h"
+#include "base/stringprintf.h"
+
+namespace base {
+
+std::string GenerateGUID() {
+ uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() };
+ return RandomDataToGUIDString(sixteen_bytes);
+}
+
+// TODO(cmasone): Once we're comfortable this works, migrate Windows code to
+// use this as well.
+std::string RandomDataToGUIDString(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);
+}
+
+} // namespace guid