OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ios/device_util.h" | 5 #include "base/ios/device_util.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include <ifaddrs.h> | 10 #include <ifaddrs.h> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 break; | 113 break; |
114 } | 114 } |
115 } | 115 } |
116 freeifaddrs(addresses); | 116 freeifaddrs(addresses); |
117 } | 117 } |
118 return mac_string; | 118 return mac_string; |
119 } | 119 } |
120 | 120 |
121 std::string GetRandomId() { | 121 std::string GetRandomId() { |
122 base::mac::ScopedCFTypeRef<CFUUIDRef> | 122 base::ScopedCFTypeRef<CFUUIDRef> uuid_object( |
123 uuid_object(CFUUIDCreate(kCFAllocatorDefault)); | 123 CFUUIDCreate(kCFAllocatorDefault)); |
124 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( | 124 base::ScopedCFTypeRef<CFStringRef> uuid_string( |
125 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); | 125 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); |
126 return base::SysCFStringRefToUTF8(uuid_string); | 126 return base::SysCFStringRefToUTF8(uuid_string); |
127 } | 127 } |
128 | 128 |
129 std::string GetDeviceIdentifier(const char* salt) { | 129 std::string GetDeviceIdentifier(const char* salt) { |
130 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 130 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
131 | 131 |
132 NSString* last_seen_hardware = | 132 NSString* last_seen_hardware = |
133 [defaults stringForKey:kHardwareTypePreferenceKey]; | 133 [defaults stringForKey:kHardwareTypePreferenceKey]; |
134 NSString* current_hardware = base::SysUTF8ToNSString(GetPlatform()); | 134 NSString* current_hardware = base::SysUTF8ToNSString(GetPlatform()); |
(...skipping 12 matching lines...) Expand all Loading... |
147 [defaults synchronize]; | 147 [defaults synchronize]; |
148 } | 148 } |
149 | 149 |
150 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id, | 150 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id, |
151 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding]; | 151 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding]; |
152 | 152 |
153 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; | 153 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; |
154 CC_SHA256([hash_data bytes], [hash_data length], hash); | 154 CC_SHA256([hash_data bytes], [hash_data length], hash); |
155 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); | 155 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); |
156 | 156 |
157 base::mac::ScopedCFTypeRef<CFUUIDRef> | 157 base::ScopedCFTypeRef<CFUUIDRef> uuid_object( |
158 uuid_object(CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); | 158 CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); |
159 base::mac::ScopedCFTypeRef<CFStringRef> device_id( | 159 base::ScopedCFTypeRef<CFStringRef> device_id( |
160 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); | 160 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); |
161 return base::SysCFStringRefToUTF8(device_id); | 161 return base::SysCFStringRefToUTF8(device_id); |
162 } | 162 } |
163 | 163 |
164 } // namespace device_util | 164 } // namespace device_util |
165 } // namespace ios | 165 } // namespace ios |
OLD | NEW |