Chromium Code Reviews| Index: ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm |
| diff --git a/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm b/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba3eaf303a006264601c800e8b9a1f810f4fb915 |
| --- /dev/null |
| +++ b/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h" |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| +#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| + |
| +namespace ios { |
| + |
| +NSString* const kIdentityEmailFormat = @"%@@foo.com"; |
| +NSString* const kIdentityGaiaIDFormat = @"%@ID"; |
| + |
| +FakeChromeIdentityService::FakeChromeIdentityService() |
| + : identities_([[NSMutableArray alloc] init]) {} |
| + |
| +FakeChromeIdentityService::~FakeChromeIdentityService() {} |
| + |
| +// static |
| +FakeChromeIdentityService* FakeChromeIdentityService::GetInstance() { |
| + return static_cast<ios::FakeChromeIdentityService*>( |
| + ios::GetChromeBrowserProvider()->GetChromeIdentityService()); |
| +} |
| + |
| +bool FakeChromeIdentityService::IsValidIdentity( |
| + ChromeIdentity* identity) const { |
| + return [identities_ indexOfObject:identity] != NSNotFound; |
| +} |
| + |
| +ChromeIdentity* FakeChromeIdentityService::GetIdentityWithEmail( |
| + const std::string& email) const { |
| + NSString* userEmail = base::SysUTF8ToNSString(email); |
| + NSUInteger index = |
| + [identities_ indexOfObjectPassingTest:^BOOL(ChromeIdentity* obj, |
| + NSUInteger, BOOL* stop) { |
| + return [[obj userEmail] isEqualToString:userEmail]; |
|
msarda
2016/07/07 11:58:06
In general, emails need to be sanitized and canoni
bzanotti
2016/07/07 12:48:11
Good point, but this was causing some dependencies
|
| + }]; |
| + if (index == NSNotFound) { |
| + return nil; |
| + } |
| + return [identities_ objectAtIndex:index]; |
| +} |
| + |
| +ChromeIdentity* FakeChromeIdentityService::GetIdentityWithGaiaID( |
| + const std::string& gaia_id) const { |
| + NSString* gaiaID = base::SysUTF8ToNSString(gaia_id); |
| + NSUInteger index = |
| + [identities_ indexOfObjectPassingTest:^BOOL(ChromeIdentity* obj, |
| + NSUInteger, BOOL* stop) { |
| + return [[obj gaiaID] isEqualToString:gaiaID]; |
| + }]; |
| + if (index == NSNotFound) { |
| + return nil; |
| + } |
| + return [identities_ objectAtIndex:index]; |
| +} |
| + |
| +bool FakeChromeIdentityService::HasIdentities() const { |
| + return [identities_ count] > 0; |
| +} |
| + |
| +NSArray* FakeChromeIdentityService::GetAllIdentities() const { |
| + return identities_; |
| +} |
| + |
| +NSArray* FakeChromeIdentityService::GetAllIdentitiesSortedForDisplay() const { |
| + return identities_; |
| +} |
| + |
| +void FakeChromeIdentityService::ForgetIdentity( |
| + ChromeIdentity* identity, |
| + ForgetIdentityCallback callback) { |
| + [identities_ removeObject:identity]; |
| + FireIdentityListChanged(); |
| + if (callback) { |
|
msarda
2016/07/07 11:58:06
I think we should use the Chromium style of postin
bzanotti
2016/07/07 12:48:11
The RunLoop already support the iOS dispatch mecha
|
| + dispatch_async(dispatch_get_main_queue(), ^{ |
|
msarda
2016/07/07 11:58:06
Why do we dispatch here. Wouldn't it be easier to
sdefresne
2016/07/07 12:12:40
+1, please add a comment explaining why if it cann
bzanotti
2016/07/07 12:48:11
Added a comment here. Basically, ForgetIdentity is
|
| + callback(nil); |
| + }); |
| + } |
| +} |
| + |
| +void FakeChromeIdentityService::AddIdentities(NSArray* identitiesNames) { |
| + for (NSString* name in identitiesNames) { |
| + NSString* email = [NSString stringWithFormat:kIdentityEmailFormat, name]; |
| + NSString* gaiaID = [NSString stringWithFormat:kIdentityGaiaIDFormat, name]; |
| + [identities_ addObject:[FakeChromeIdentity identityWithEmail:email |
| + gaiaID:gaiaID |
| + name:name]]; |
| + } |
| +} |
| + |
| +void FakeChromeIdentityService::AddIdentity(ChromeIdentity* identity) { |
| + [identities_ addObject:identity]; |
| + FireIdentityListChanged(); |
| +} |
| +} |
|
sdefresne
2016/07/07 12:12:40
} // namespace ios
and add a blank line before
bzanotti
2016/07/07 12:48:11
Done.
|
| + |