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
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/signin/signin_util.h"
7 #include "base/strings/sys_string_conversions.h"
8 #include "google_apis/gaia/gaia_auth_util.h"
9 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
10 #include "ios/public/provider/chrome/browser/signin/signin_error_provider.h"
12 NSArray* GetScopeArray(const std::set<std::string>& scopes) {
13 NSMutableArray* scopes_array = [[[NSMutableArray alloc] init] autorelease];
14 for (const auto& scope : scopes) {
15 [scopes_array addObject:base::SysUTF8ToNSString(scope)];
20 std::string GetCanonicalizedEmailForIdentity(ChromeIdentity* identity) {
21 NSString* nsEmail = [identity userEmail];
24 std::string email = base::SysNSStringToUTF8(nsEmail);
25 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email));
28 bool ShouldHandleSigninError(NSError* error) {
29 ios::SigninErrorProvider* provider = ios::GetSigninErrorProvider();
30 return ![provider->GetSigninErrorDomain() isEqualToString:error.domain] ||
31 (error.code != provider->GetCode(ios::SigninError::CANCELED) &&
33 provider->GetCode(ios::SigninError::HANDLED_INTERNALLY));