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

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: Follow review. 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
« no previous file with comments | « base/ios/OWNERS ('k') | base/ios/device_util_unittest.mm » ('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) 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 <UIKit/UIKit.h>
9 9
10 #include <ifaddrs.h> 10 #include <ifaddrs.h>
11 #include <net/if_dl.h> 11 #include <net/if_dl.h>
12 #include <string.h> 12 #include <string.h>
13 #include <sys/socket.h> 13 #include <sys/socket.h>
14 #include <sys/sysctl.h> 14 #include <sys/sysctl.h>
15 15
16 #include "base/ios/ios_util.h"
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"
19 #include "base/mac/scoped_cftyperef.h" 20 #include "base/mac/scoped_cftyperef.h"
20 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
21 #include "base/sys_string_conversions.h" 22 #include "base/sys_string_conversions.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Client ID key in the user preferences. 26 // Client ID key in the user preferences.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( 97 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
97 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); 98 CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
98 return base::SysCFStringRefToUTF8(uuid_string); 99 return base::SysCFStringRefToUTF8(uuid_string);
99 } 100 }
100 101
101 std::string GetDeviceIdentifier(const char* salt) { 102 std::string GetDeviceIdentifier(const char* salt) {
102 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 103 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
103 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey]; 104 NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
104 105
105 if (!client_id) { 106 if (!client_id) {
106 client_id = base::SysUTF8ToNSString(GetRandomId()); 107 if (base::ios::IsRunningOnIOS6OrLater())
108 client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
109 else
110 client_id = base::SysUTF8ToNSString(GetRandomId());
107 [defaults setObject:client_id forKey:kClientIdPreferenceKey]; 111 [defaults setObject:client_id forKey:kClientIdPreferenceKey];
108 [defaults synchronize]; 112 [defaults synchronize];
109 } 113 }
110 114
111 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id, 115 NSData* hash_data = [[NSString stringWithFormat:@"%@%s", client_id,
112 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding]; 116 salt ? salt : kDefaultSalt] dataUsingEncoding:NSUTF8StringEncoding];
113 117
114 unsigned char hash[CC_SHA256_DIGEST_LENGTH]; 118 unsigned char hash[CC_SHA256_DIGEST_LENGTH];
115 CC_SHA256([hash_data bytes], [hash_data length], hash); 119 CC_SHA256([hash_data bytes], [hash_data length], hash);
116 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); 120 CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash);
117 121
118 base::mac::ScopedCFTypeRef<CFUUIDRef> 122 base::mac::ScopedCFTypeRef<CFUUIDRef>
119 uuid_object(CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); 123 uuid_object(CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes));
120 base::mac::ScopedCFTypeRef<CFStringRef> device_id( 124 base::mac::ScopedCFTypeRef<CFStringRef> device_id(
121 CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); 125 CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
122 return base::SysCFStringRefToUTF8(device_id); 126 return base::SysCFStringRefToUTF8(device_id);
123 } 127 }
124 128
125 } // namespace device_util 129 } // namespace device_util
126 } // namespace ios 130 } // namespace ios
OLDNEW
« no previous file with comments | « base/ios/OWNERS ('k') | base/ios/device_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698