[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 5 | #ifndef BASE_GUID_H_ |
6 | #define BASE_GUID_H_ | ||||
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 7 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 10 | #include <string> |
11 | |||||
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 12 | #include "base/base_export.h" |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 13 | #include "build/build_config.h" |
14 | |||||
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 15 | namespace base { |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 16 | |
17 | // Generate a 128-bit random GUID of the form: "%08X-%04X-%04X-%04X-%012llX". | ||||
18 | // If GUID generation fails an empty string is returned. | ||||
sungmann.cho | 8b0ae1b | 2014-09-29 06:39:18 | [diff] [blame] | 19 | // The POSIX implementation uses pseudo random number generation to create |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 20 | // the GUID. The Windows implementation uses system services. |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 21 | BASE_EXPORT std::string GenerateGUID(); |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 22 | |
[email protected] | d3d728e9 | 2010-10-20 03:24:55 | [diff] [blame] | 23 | // Returns true if the input string conforms to the GUID format. |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 24 | BASE_EXPORT bool IsValidGUID(const std::string& guid); |
[email protected] | d3d728e9 | 2010-10-20 03:24:55 | [diff] [blame] | 25 | |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 26 | #if defined(OS_POSIX) |
27 | // For unit testing purposes only. Do not use outside of tests. | ||||
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 28 | BASE_EXPORT std::string RandomDataToGUIDString(const uint64_t bytes[2]); |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 29 | #endif |
30 | |||||
[email protected] | 4461e9ad | 2013-09-27 08:52:29 | [diff] [blame] | 31 | } // namespace base |
[email protected] | 3469e7e | 2010-10-14 20:34:59 | [diff] [blame] | 32 | |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 33 | #endif // BASE_GUID_H_ |