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

Side by Side Diff: base/ios/device_util.mm

Issue 11031066: Adding utility method to test the version of the OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile issue Created 8 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 | Annotate | Revision Log
OLDNEW
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 <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #import <UIKit/UIKit.h>
9 10
10 #include <ifaddrs.h> 11 #include <ifaddrs.h>
11 #include <net/if_dl.h> 12 #include <net/if_dl.h>
12 #include <string.h> 13 #include <string.h>
13 #include <sys/socket.h> 14 #include <sys/socket.h>
14 #include <sys/sysctl.h> 15 #include <sys/sysctl.h>
15 16
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
20 #include "base/sys_info.h"
19 #include "base/mac/scoped_cftyperef.h" 21 #include "base/mac/scoped_cftyperef.h"
20 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
21 #include "base/sys_string_conversions.h" 23 #include "base/sys_string_conversions.h"
22 24
23 namespace { 25 namespace {
24 26
25 // Client ID key in the user preferences. 27 // Client ID key in the user preferences.
26 NSString* const kClientIdPreferenceKey = @"ChromiumClientID"; 28 NSString* const kClientIdPreferenceKey = @"ChromiumClientID";
27 // Default salt for device ids. 29 // Default salt for device ids.
28 const char kDefaultSalt[] = "Salt"; 30 const char kDefaultSalt[] = "Salt";
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( 98 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
97 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); 99 CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
98 return base::SysCFStringRefToUTF8(uuid_string); 100 return base::SysCFStringRefToUTF8(uuid_string);
99 } 101 }
100 102
101 std::string GetDeviceIdentifier(const char* salt) { 103 std::string GetDeviceIdentifier(const char* salt) {
102 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 104 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
103 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey]; 105 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
104 106
105 if (!client_id) { 107 if (!client_id) {
106 client_id = base::SysUTF8ToNSString(GetRandomId()); 108 if (base::SysInfo::IsRunningOnIOS6OrLater())
109 client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
110 else
111 client_id = base::SysUTF8ToNSString(GetRandomId());
107 [defaults setObject:client_id forKey:kClientIdPreferenceKey]; 112 [defaults setObject:client_id forKey:kClientIdPreferenceKey];
108 [defaults synchronize]; 113 [defaults synchronize];
109 } 114 }
110 115
111 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id, 116 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id,
112 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding]; 117 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding];
113 118
114 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; 119 unsigned char hash[CC_SHA256_DIGEST_LENGTH];
115 CC_SHA256([hash_data bytes], [hash_data length], hash); 120 CC_SHA256([hash_data bytes], [hash_data length], hash);
116 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); 121 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash);
117 122
118 base::mac::ScopedCFTypeRef<CFUUIDRef> 123 base::mac::ScopedCFTypeRef<CFUUIDRef>
119 uuid_object(CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); 124 uuid_object(CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes));
120 base::mac::ScopedCFTypeRef<CFStringRef> device_id( 125 base::mac::ScopedCFTypeRef<CFStringRef> device_id(
121 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); 126 CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
122 return base::SysCFStringRefToUTF8(device_id); 127 return base::SysCFStringRefToUTF8(device_id);
123 } 128 }
124 129
125 } // namespace device_util 130 } // namespace device_util
126 } // namespace ios 131 } // namespace ios
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698