OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/chrome/browser/signin/signin_util.h" | 5 #include "ios/chrome/browser/signin/signin_util.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "google_apis/gaia/gaia_auth_util.h" | 8 #include "google_apis/gaia/gaia_auth_util.h" |
9 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 9 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
10 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 10 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
11 #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h" | 11 #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h" |
12 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
13 NSArray* GetScopeArray(const std::set<std::string>& scopes) { | 17 NSArray* GetScopeArray(const std::set<std::string>& scopes) { |
14 NSMutableArray* scopes_array = [[[NSMutableArray alloc] init] autorelease]; | 18 NSMutableArray* scopes_array = [[NSMutableArray alloc] init]; |
15 for (const auto& scope : scopes) { | 19 for (const auto& scope : scopes) { |
16 [scopes_array addObject:base::SysUTF8ToNSString(scope)]; | 20 [scopes_array addObject:base::SysUTF8ToNSString(scope)]; |
17 } | 21 } |
18 return scopes_array; | 22 return scopes_array; |
19 } | 23 } |
20 | 24 |
21 std::string GetCanonicalizedEmailForIdentity(ChromeIdentity* identity) { | 25 std::string GetCanonicalizedEmailForIdentity(ChromeIdentity* identity) { |
22 NSString* nsEmail = [identity userEmail]; | 26 NSString* nsEmail = [identity userEmail]; |
23 if (!nsEmail) | 27 if (!nsEmail) |
24 return std::string(); | 28 return std::string(); |
25 std::string email = base::SysNSStringToUTF8(nsEmail); | 29 std::string email = base::SysNSStringToUTF8(nsEmail); |
26 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)); | 30 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)); |
27 } | 31 } |
28 | 32 |
29 bool ShouldHandleSigninError(NSError* error) { | 33 bool ShouldHandleSigninError(NSError* error) { |
30 ios::SigninErrorProvider* provider = | 34 ios::SigninErrorProvider* provider = |
31 ios::GetChromeBrowserProvider()->GetSigninErrorProvider(); | 35 ios::GetChromeBrowserProvider()->GetSigninErrorProvider(); |
32 return ![provider->GetSigninErrorDomain() isEqualToString:error.domain] || | 36 return ![provider->GetSigninErrorDomain() isEqualToString:error.domain] || |
33 (error.code != provider->GetCode(ios::SigninError::CANCELED) && | 37 (error.code != provider->GetCode(ios::SigninError::CANCELED) && |
34 error.code != | 38 error.code != |
35 provider->GetCode(ios::SigninError::HANDLED_INTERNALLY)); | 39 provider->GetCode(ios::SigninError::HANDLED_INTERNALLY)); |
36 } | 40 } |
OLD | NEW |