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

Side by Side Diff: base/rand_util_win.cc

Issue 3800003: Moving GUID generation from base to chrome/browser/guid* (Closed)
Patch Set: Additional comment. 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 unified diff | Download patch
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/guid.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/rand_util.h" 5 #include "base/rand_util.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <objbase.h>
10 #include <windows.h>
11
12 #include "base/basictypes.h" 9 #include "base/basictypes.h"
13 #include "base/logging.h" 10 #include "base/logging.h"
14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h"
16 11
17 namespace { 12 namespace {
18 13
19 uint32 RandUint32() { 14 uint32 RandUint32() {
20 uint32 number; 15 uint32 number;
21 CHECK_EQ(rand_s(&number), 0); 16 CHECK_EQ(rand_s(&number), 0);
22 return number; 17 return number;
23 } 18 }
24 19
25 } // namespace 20 } // namespace
26 21
27 namespace base { 22 namespace base {
28 23
29 uint64 RandUint64() { 24 uint64 RandUint64() {
30 uint32 first_half = RandUint32(); 25 uint32 first_half = RandUint32();
31 uint32 second_half = RandUint32(); 26 uint32 second_half = RandUint32();
32 return (static_cast<uint64>(first_half) << 32) + second_half; 27 return (static_cast<uint64>(first_half) << 32) + second_half;
33 } 28 }
34 29
35 std::string GenerateGUID() {
36 const int kGUIDSize = 39;
37
38 GUID guid;
39 HRESULT guid_result = CoCreateGuid(&guid);
40 DCHECK(SUCCEEDED(guid_result));
41
42 std::wstring guid_string;
43 int result = StringFromGUID2(guid,
44 WriteInto(&guid_string, kGUIDSize), kGUIDSize);
45 DCHECK(result == kGUIDSize);
46
47 return WideToUTF8(guid_string.substr(1, guid_string.length() - 2));
48 }
49
50 } // namespace base 30 } // namespace base
OLDNEW
« no previous file with comments | « base/rand_util_unittest.cc ('k') | chrome/browser/guid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698