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

Side by Side 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 unified diff | 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 »
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
9 #include "base/basictypes.h" 12 #include "base/basictypes.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h"
11 16
12 namespace { 17 namespace {
13 18
14 uint32 RandUint32() { 19 uint32 RandUint32() {
15 uint32 number; 20 uint32 number;
16 CHECK_EQ(rand_s(&number), 0); 21 CHECK_EQ(rand_s(&number), 0);
17 return number; 22 return number;
18 } 23 }
19 24
20 } // namespace 25 } // namespace
21 26
22 namespace base { 27 namespace base {
23 28
24 uint64 RandUint64() { 29 uint64 RandUint64() {
25 uint32 first_half = RandUint32(); 30 uint32 first_half = RandUint32();
26 uint32 second_half = RandUint32(); 31 uint32 second_half = RandUint32();
27 return (static_cast<uint64>(first_half) << 32) + second_half; 32 return (static_cast<uint64>(first_half) << 32) + second_half;
28 } 33 }
29 34
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
30 } // namespace base 50 } // namespace base
OLDNEW
« 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