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

Unified Diff: base/ios/device_util.mm

Issue 11576008: Fixing identifier for device returning a 0 identifierForVendor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/ios/device_util_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/ios/device_util.mm
diff --git a/base/ios/device_util.mm b/base/ios/device_util.mm
index e6801abe8466f1bef86aa71241dc80cd2c94a86f..b538ea858a5558987e268e2e7aed78ecaee805a0 100644
--- a/base/ios/device_util.mm
+++ b/base/ios/device_util.mm
@@ -24,9 +24,33 @@
namespace {
// Client ID key in the user preferences.
-NSString* const kClientIdPreferenceKey = @"ChromiumClientID";
+NSString* const kLegacyClientIdPreferenceKey = @"ChromiumClientID";
+NSString* const kClientIdPreferenceKey = @"ChromeClientID";
// Default salt for device ids.
const char kDefaultSalt[] = "Salt";
+// Zero UUID returned on buggy iOS devices.
+NSString* const kZeroUUID = @"00000000-0000-0000-0000-000000000000";
+
+NSString* GenerateClientId() {
+ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
+
+ // Try to migrate from legacy client id.
+ NSString* client_id = [defaults stringForKey:kLegacyClientIdPreferenceKey];
+
+ // Some iOS6 devices return a buggy identifierForVendor:
+ // http://openradar.appspot.com/12377282. If this is the case, revert to
+ // generating a new one.
+ if (!client_id || [client_id isEqualToString:kZeroUUID]) {
+ if (base::ios::IsRunningOnIOS6OrLater()) {
+ client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
+ if ([client_id isEqualToString:kZeroUUID])
+ client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId());
+ } else {
+ client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId());
+ }
+ }
+ return client_id;
+}
} // namespace
@@ -104,10 +128,7 @@ std::string GetDeviceIdentifier(const char* salt) {
NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
if (!client_id) {
- if (base::ios::IsRunningOnIOS6OrLater())
- client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
- else
- client_id = base::SysUTF8ToNSString(GetRandomId());
+ client_id = GenerateClientId();
[defaults setObject:client_id forKey:kClientIdPreferenceKey];
[defaults synchronize];
}
« no previous file with comments | « no previous file | base/ios/device_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698