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

Side by Side Diff: ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm

Issue 2123273003: Introduce FakeChromeIdentity and FakeChromeIdentityService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/strings/sys_string_conversions.h"
10 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
11 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
12
13 namespace ios {
14
15 NSString* const kIdentityEmailFormat = @"%@@foo.com";
16 NSString* const kIdentityGaiaIDFormat = @"%@ID";
17
18 FakeChromeIdentityService::FakeChromeIdentityService()
19 : identities_([[NSMutableArray alloc] init]) {}
20
21 FakeChromeIdentityService::~FakeChromeIdentityService() {}
22
23 // static
24 FakeChromeIdentityService* FakeChromeIdentityService::GetInstance() {
25 return static_cast<ios::FakeChromeIdentityService*>(
26 ios::GetChromeBrowserProvider()->GetChromeIdentityService());
27 }
28
29 bool FakeChromeIdentityService::IsValidIdentity(
30 ChromeIdentity* identity) const {
31 return [identities_ indexOfObject:identity] != NSNotFound;
32 }
33
34 ChromeIdentity* FakeChromeIdentityService::GetIdentityWithEmail(
35 const std::string& email) const {
36 NSString* userEmail = base::SysUTF8ToNSString(email);
37 NSUInteger index =
38 [identities_ indexOfObjectPassingTest:^BOOL(ChromeIdentity* obj,
39 NSUInteger, BOOL* stop) {
40 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
41 }];
42 if (index == NSNotFound) {
43 return nil;
44 }
45 return [identities_ objectAtIndex:index];
46 }
47
48 ChromeIdentity* FakeChromeIdentityService::GetIdentityWithGaiaID(
49 const std::string& gaia_id) const {
50 NSString* gaiaID = base::SysUTF8ToNSString(gaia_id);
51 NSUInteger index =
52 [identities_ indexOfObjectPassingTest:^BOOL(ChromeIdentity* obj,
53 NSUInteger, BOOL* stop) {
54 return [[obj gaiaID] isEqualToString:gaiaID];
55 }];
56 if (index == NSNotFound) {
57 return nil;
58 }
59 return [identities_ objectAtIndex:index];
60 }
61
62 bool FakeChromeIdentityService::HasIdentities() const {
63 return [identities_ count] > 0;
64 }
65
66 NSArray* FakeChromeIdentityService::GetAllIdentities() const {
67 return identities_;
68 }
69
70 NSArray* FakeChromeIdentityService::GetAllIdentitiesSortedForDisplay() const {
71 return identities_;
72 }
73
74 void FakeChromeIdentityService::ForgetIdentity(
75 ChromeIdentity* identity,
76 ForgetIdentityCallback callback) {
77 [identities_ removeObject:identity];
78 FireIdentityListChanged();
79 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
80 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
81 callback(nil);
82 });
83 }
84 }
85
86 void FakeChromeIdentityService::AddIdentities(NSArray* identitiesNames) {
87 for (NSString* name in identitiesNames) {
88 NSString* email = [NSString stringWithFormat:kIdentityEmailFormat, name];
89 NSString* gaiaID = [NSString stringWithFormat:kIdentityGaiaIDFormat, name];
90 [identities_ addObject:[FakeChromeIdentity identityWithEmail:email
91 gaiaID:gaiaID
92 name:name]];
93 }
94 }
95
96 void FakeChromeIdentityService::AddIdentity(ChromeIdentity* identity) {
97 [identities_ addObject:identity];
98 FireIdentityListChanged();
99 }
100 }
sdefresne 2016/07/07 12:12:40 } // namespace ios and add a blank line before
bzanotti 2016/07/07 12:48:11 Done.
101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698