diff options
author | droger <droger@chromium.org> | 2015-08-04 01:42:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-04 08:45:34 +0000 |
commit | cf85e4a6f6595aeae8a7f0ef737df24cc9fe0073 (patch) | |
tree | e6670131aaff475cc123dbedbc73c26866f312df | |
parent | f96f9eca26285fd4ea9328a7e61e311dc34ab7d5 (diff) | |
download | chromium_src-cf85e4a6f6595aeae8a7f0ef737df24cc9fe0073.zip chromium_src-cf85e4a6f6595aeae8a7f0ef737df24cc9fe0073.tar.gz chromium_src-cf85e4a6f6595aeae8a7f0ef737df24cc9fe0073.tar.bz2 |
[iOS] Upstream ChromeIdentity and ChromeIdentityService
Review URL: https://codereview.chromium.org/1265153003
Cr-Commit-Position: refs/heads/master@{#341700}
14 files changed, 546 insertions, 2 deletions
diff --git a/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h new file mode 100644 index 0000000..20624cf --- /dev/null +++ b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h @@ -0,0 +1,45 @@ +// Copyright 2015 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. + +#ifndef IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_ +#define IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_ + +#include <Foundation/Foundation.h> + +#include "base/macros.h" +#include "base/scoped_observer.h" +#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" + +// Objective-C protocol mirroring ChromeIdentityService::Observer. +@protocol ChromeIdentityServiceObserver<NSObject> +@optional +- (void)onIdentityListChanged; +- (void)onAccessTokenRefreshFailed:(ChromeIdentity*)identity + error:(ios::AccessTokenErrorReason)error; +- (void)onProfileUpdate:(ChromeIdentity*)identity; +@end + +// Simple observer bridge that forwards all events to its delegate observer. +class ChromeIdentityServiceObserverBridge + : public ios::ChromeIdentityService::Observer { + public: + explicit ChromeIdentityServiceObserverBridge( + id<ChromeIdentityServiceObserver> observer); + ~ChromeIdentityServiceObserverBridge() override; + + private: + // ios::ChromeIdentityService::Observer implementation. + void OnIdentityListChanged() override; + void OnAccessTokenRefreshFailed(ChromeIdentity* identity, + ios::AccessTokenErrorReason error) override; + void OnProfileUpdate(ChromeIdentity* identity) override; + + id<ChromeIdentityServiceObserver> observer_; // Weak. |observer_| owns this. + ScopedObserver<ios::ChromeIdentityService, + ChromeIdentityServiceObserverBridge> scoped_observer_; + + DISALLOW_COPY_AND_ASSIGN(ChromeIdentityServiceObserverBridge); +}; + +#endif // IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_ diff --git a/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.mm b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.mm new file mode 100644 index 0000000..2962c8c --- /dev/null +++ b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge.mm @@ -0,0 +1,38 @@ +// Copyright 2015 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. + +#include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" + +#include "base/logging.h" +#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" + +ChromeIdentityServiceObserverBridge::ChromeIdentityServiceObserverBridge( + id<ChromeIdentityServiceObserver> observer) + : observer_(observer), scoped_observer_(this) { + DCHECK(observer_); + scoped_observer_.Add( + ios::GetChromeBrowserProvider()->GetChromeIdentityService()); +} + +ChromeIdentityServiceObserverBridge::~ChromeIdentityServiceObserverBridge() {} + +void ChromeIdentityServiceObserverBridge::OnIdentityListChanged() { + if ([observer_ respondsToSelector:@selector(onIdentityListChanged)]) + [observer_ onIdentityListChanged]; +} + +void ChromeIdentityServiceObserverBridge::OnAccessTokenRefreshFailed( + ChromeIdentity* identity, + ios::AccessTokenErrorReason error) { + if ([observer_ + respondsToSelector:@selector(onAccessTokenRefreshFailed:error:)]) { + [observer_ onAccessTokenRefreshFailed:identity error:error]; + } +} + +void ChromeIdentityServiceObserverBridge::OnProfileUpdate( + ChromeIdentity* identity) { + if ([observer_ respondsToSelector:@selector(onProfileUpdate:)]) + [observer_ onProfileUpdate:identity]; +} diff --git a/ios/chrome/browser/signin/chrome_identity_service_observer_bridge_unittest.mm b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge_unittest.mm new file mode 100644 index 0000000..154071ba --- /dev/null +++ b/ios/chrome/browser/signin/chrome_identity_service_observer_bridge_unittest.mm @@ -0,0 +1,117 @@ +// Copyright 2015 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/chrome/browser/signin/chrome_identity_service_observer_bridge.h" + +#include "base/mac/scoped_nsobject.h" +#include "base/memory/scoped_ptr.h" +#import "ios/public/provider/chrome/browser/signin/chrome_identity.h" +#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" +#include "testing/platform_test.h" + +@interface TestChromeIdentityServiceObserver + : NSObject<ChromeIdentityServiceObserver> +@property(nonatomic) BOOL onIdentityListChangedCalled; +@property(nonatomic) BOOL onAccessTokenRefreshFailedCalled; +@property(nonatomic) BOOL onProfileUpdateCalled; +@property(nonatomic, assign) ChromeIdentity* identity; +@property(nonatomic) ios::AccessTokenErrorReason error; +@property(nonatomic, readonly) + ios::ChromeIdentityService::Observer* observerBridge; +@end + +@implementation TestChromeIdentityServiceObserver { + scoped_ptr<ios::ChromeIdentityService::Observer> observer_bridge_; +} + +@synthesize onIdentityListChangedCalled = _onIdentityListChangedCalled; +@synthesize onAccessTokenRefreshFailedCalled = + _onAccessTokenRefreshFailedCalled; +@synthesize onProfileUpdateCalled = _onProfileUpdateCalled; +@synthesize identity = _identity; +@synthesize error = _error; + +- (instancetype)init { + if (self == [super init]) { + observer_bridge_.reset(new ChromeIdentityServiceObserverBridge(self)); + } + return self; +} + +- (ios::ChromeIdentityService::Observer*)observerBridge { + return observer_bridge_.get(); +} + +#pragma mark - ios::ChromeIdentityService::Observer + +- (void)onIdentityListChanged { + _onIdentityListChangedCalled = YES; +} + +- (void)onAccessTokenRefreshFailed:(ChromeIdentity*)identity + error:(ios::AccessTokenErrorReason)error { + _onAccessTokenRefreshFailedCalled = YES; + _error = error; + _identity = identity; +} + +- (void)onProfileUpdate:(ChromeIdentity*)identity { + _onProfileUpdateCalled = YES; + _identity = identity; +} + +@end + +#pragma mark - ChromeIdentityServiceObserverBridgeTest + +class ChromeIdentityServiceObserverBridgeTest : public PlatformTest { + protected: + ChromeIdentityServiceObserverBridgeTest() + : test_observer_([[TestChromeIdentityServiceObserver alloc] init]) {} + + ios::ChromeIdentityService::Observer* GetObserverBridge() { + return [test_observer_ observerBridge]; + } + + TestChromeIdentityServiceObserver* GetTestObserver() { + return test_observer_; + } + + private: + base::scoped_nsobject<TestChromeIdentityServiceObserver> test_observer_; +}; + +// Tests that |onIdentityListChanged| is forwarded. +TEST_F(ChromeIdentityServiceObserverBridgeTest, onIdentityListChanged) { + ASSERT_FALSE(GetTestObserver().onIdentityListChangedCalled); + GetObserverBridge()->OnIdentityListChanged(); + EXPECT_TRUE(GetTestObserver().onIdentityListChangedCalled); + EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); + EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); +} + +// Tests that |onAccessTokenRefreshFailed| is forwarded. +TEST_F(ChromeIdentityServiceObserverBridgeTest, onAccessTokenRefreshFailed) { + base::scoped_nsobject<ChromeIdentity> identity([[ChromeIdentity alloc] init]); + ios::AccessTokenErrorReason error = + ios::AccessTokenErrorReason::UNKNOWN_ERROR; + ASSERT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); + GetObserverBridge()->OnAccessTokenRefreshFailed(identity, error); + EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); + EXPECT_TRUE(GetTestObserver().onAccessTokenRefreshFailedCalled); + EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); + EXPECT_EQ(identity, GetTestObserver().identity); + EXPECT_EQ(error, GetTestObserver().error); +} + +// Tests that |onProfileUpdate| is forwarded. +TEST_F(ChromeIdentityServiceObserverBridgeTest, onProfileUpdate) { + base::scoped_nsobject<ChromeIdentity> identity([[ChromeIdentity alloc] init]); + ASSERT_FALSE(GetTestObserver().onProfileUpdateCalled); + GetObserverBridge()->OnProfileUpdate(identity); + EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); + EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); + EXPECT_TRUE(GetTestObserver().onProfileUpdateCalled); + EXPECT_EQ(identity, GetTestObserver().identity); +} diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp index 8d87468..d1ea95e 100644 --- a/ios/chrome/ios_chrome.gyp +++ b/ios/chrome/ios_chrome.gyp @@ -285,6 +285,8 @@ 'browser/search_engines/ui_thread_search_terms_data.h', 'browser/signin/account_tracker_service_factory.cc', 'browser/signin/account_tracker_service_factory.h', + 'browser/signin/chrome_identity_service_observer_bridge.h', + 'browser/signin/chrome_identity_service_observer_bridge.mm', 'browser/signin/constants.h', 'browser/signin/constants.mm', 'browser/signin/gaia_auth_fetcher_ios.h', diff --git a/ios/chrome/ios_chrome_tests.gyp b/ios/chrome/ios_chrome_tests.gyp index c71ded6..79b4a65 100644 --- a/ios/chrome/ios_chrome_tests.gyp +++ b/ios/chrome/ios_chrome_tests.gyp @@ -49,6 +49,7 @@ 'browser/net/image_fetcher_unittest.mm', 'browser/net/metrics_network_client_unittest.mm', 'browser/net/retryable_url_fetcher_unittest.mm', + 'browser/signin/chrome_identity_service_observer_bridge_unittest.mm', 'browser/signin/gaia_auth_fetcher_ios_unittest.mm', 'browser/snapshots/snapshot_cache_unittest.mm', 'browser/snapshots/snapshots_util_unittest.mm', diff --git a/ios/provider/ios_provider_chrome.gyp b/ios/provider/ios_provider_chrome.gyp index 8cb07fb..55ba5a2 100644 --- a/ios/provider/ios_provider_chrome.gyp +++ b/ios/provider/ios_provider_chrome.gyp @@ -22,6 +22,10 @@ '../public/provider/chrome/browser/geolocation_updater_provider.mm', '../public/provider/chrome/browser/keyed_service_provider.cc', '../public/provider/chrome/browser/keyed_service_provider.h', + '../public/provider/chrome/browser/signin/chrome_identity.h', + '../public/provider/chrome/browser/signin/chrome_identity.mm', + '../public/provider/chrome/browser/signin/chrome_identity_service.h', + '../public/provider/chrome/browser/signin/chrome_identity_service.mm', '../public/provider/chrome/browser/string_provider.h', '../public/provider/chrome/browser/ui/infobar_view_delegate.h', '../public/provider/chrome/browser/ui/infobar_view_protocol.h', diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.cc b/ios/public/provider/chrome/browser/chrome_browser_provider.cc index c3c9c0b..4de4fa6 100644 --- a/ios/public/provider/chrome/browser/chrome_browser_provider.cc +++ b/ios/public/provider/chrome/browser/chrome_browser_provider.cc @@ -58,6 +58,10 @@ InfoBarViewPlaceholder ChromeBrowserProvider::CreateInfoBarView( return nullptr; } +ChromeIdentityService* ChromeBrowserProvider::GetChromeIdentityService() { + return nullptr; +} + StringProvider* ChromeBrowserProvider::GetStringProvider() { return nullptr; } diff --git a/ios/public/provider/chrome/browser/chrome_browser_provider.h b/ios/public/provider/chrome/browser/chrome_browser_provider.h index 794ea5e..a5e53c2 100644 --- a/ios/public/provider/chrome/browser/chrome_browser_provider.h +++ b/ios/public/provider/chrome/browser/chrome_browser_provider.h @@ -46,6 +46,7 @@ namespace ios { class ChromeBrowserProvider; class ChromeBrowserStateManager; +class ChromeIdentityService; class GeolocationUpdaterProvider; class StringProvider; class UpdatableResourceProvider; @@ -78,6 +79,8 @@ class ChromeBrowserProvider { virtual InfoBarViewPlaceholder CreateInfoBarView( CGRect frame, InfoBarViewDelegate* delegate); + // Returns an instance of a Chrome identity service. + virtual ChromeIdentityService* GetChromeIdentityService(); // Returns an instance of a string provider. virtual StringProvider* GetStringProvider(); virtual GeolocationUpdaterProvider* GetGeolocationUpdaterProvider(); diff --git a/ios/public/provider/chrome/browser/signin/chrome_identity.h b/ios/public/provider/chrome/browser/signin/chrome_identity.h new file mode 100644 index 0000000..381d63a --- /dev/null +++ b/ios/public/provider/chrome/browser/signin/chrome_identity.h @@ -0,0 +1,36 @@ +// Copyright 2015 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. + +#ifndef IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_H_ +#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_H_ + +#import <Foundation/Foundation.h> + +// A single identity used for signing in. +// Identity is the equivalent of an account. A user may have multiple identities +// or accounts associated with a single device. +@interface ChromeIdentity : NSObject + +// Identity/account email address. This can be shown to the user, but is not a +// unique identifier (@see gaiaID). +@property(nonatomic, readonly) NSString* userEmail; + +// The unique GAIA user identifier for this identity/account. +// You may use this as a unique identifier to remember a particular identity. +@property(nonatomic, readonly) NSString* gaiaID; + +// Returns the full name of the identity. +// Could be nil if no full name has been fetched for this account yet. +@property(nonatomic, readonly) NSString* userFullName; + +// Cached Hashed Gaia ID. This is used to pass the currently signed in account +// between apps. +@property(nonatomic, readonly) NSString* hashedGaiaID; + +// Whether the ChromeIdentity object has been signed in. +@property(nonatomic, readonly) BOOL isSignedIn; + +@end + +#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_H_ diff --git a/ios/public/provider/chrome/browser/signin/chrome_identity.mm b/ios/public/provider/chrome/browser/signin/chrome_identity.mm new file mode 100644 index 0000000..7e23b16 --- /dev/null +++ b/ios/public/provider/chrome/browser/signin/chrome_identity.mm @@ -0,0 +1,36 @@ +// Copyright 2015 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/chrome_identity.h" + +#include "base/logging.h" + +@implementation ChromeIdentity + +- (NSString*)userEmail { + NOTREACHED(); + return nil; +} + +- (NSString*)gaiaID { + NOTREACHED(); + return nil; +} + +- (NSString*)userFullName { + NOTREACHED(); + return nil; +} + +- (NSString*)hashedGaiaID { + NOTREACHED(); + return nil; +} + +- (BOOL)isSignedIn { + NOTREACHED(); + return false; +} + +@end diff --git a/ios/public/provider/chrome/browser/signin/chrome_identity_service.h b/ios/public/provider/chrome/browser/signin/chrome_identity_service.h new file mode 100644 index 0000000..01e8ced --- /dev/null +++ b/ios/public/provider/chrome/browser/signin/chrome_identity_service.h @@ -0,0 +1,158 @@ +// Copyright 2015 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. + +#ifndef IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_H_ +#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_H_ + +#include <set> +#include <string> +#include <vector> + +#include "base/macros.h" +#include "base/observer_list.h" + +@class ChromeIdentity; +@class NSArray; +@class NSDate; +@class NSError; +@class NSString; +@class UIImage; + +namespace ios { + +// Callback passed to method |SigninIdentity()|. +typedef void (^SigninIdentityCallback)(ChromeIdentity* identity, + NSError* error); + +// Callback passed to method |GetAccessTokenForScopes()| that returns the +// information of the obtained access token to the caller. +typedef void (^AccessTokenCallback)(NSString* token, + NSDate* expiration, + NSError* error); + +// Callback passed to method |ForgetIdentity()|. |error| is nil if the operation +// completed with success. +typedef void (^ForgetIdentityCallback)(NSError* error); + +// Callback passed to method |GetAvatarForIdentity()|. +typedef void (^GetAvatarCallback)(UIImage* avatar); + +// Describes the reason for an access token error. +enum class AccessTokenErrorReason { INVALID_GRANT, UNKNOWN_ERROR }; + +// ChromeIdentityService abstracts the signin flow on iOS. +class ChromeIdentityService { + public: + // Observer handling events related to the ChromeIdentityService. + class Observer { + public: + Observer() {} + virtual ~Observer() {} + + // Handles identity list changed events. + virtual void OnIdentityListChanged() {} + + // Handles access token refresh failed events. + // |identity| is the the identity for which the access token refresh failed. + virtual void OnAccessTokenRefreshFailed(ChromeIdentity* identity, + AccessTokenErrorReason error) {} + + // Called when profile information or the profile image is updated. + virtual void OnProfileUpdate(ChromeIdentity* identity) {} + + private: + DISALLOW_COPY_AND_ASSIGN(Observer); + }; + + ChromeIdentityService(); + virtual ~ChromeIdentityService(); + + // Returns YES if |identity| is valid and if the service has it in its list of + // identitites. + virtual bool IsValidIdentity(ChromeIdentity* identity) const; + + // Returns the chrome identity having the email equal to |email| or |nil| if + // no matching identity is found. + virtual ChromeIdentity* GetIdentityWithEmail(const std::string& email) const; + + // Returns the chrome identity having the gaia ID equal to |gaia_id| or |nil| + // if no matching identity is found. + virtual ChromeIdentity* GetIdentityWithGaiaID( + const std::string& gaia_id) const; + + // Returns the canonicalized emails for all identities. + virtual std::vector<std::string> GetCanonicalizeEmailsForAllIdentities() + const; + + // Returns true if there is at least one identity. + virtual bool HasIdentities() const; + + // Returns all ChromeIdentity objects in an array. + virtual NSArray* GetAllIdentities() const; + + // Returns all ChromeIdentity objects sorted by the ordering used in the + // account manager, which is typically based on the keychain ordering of + // accounts. + virtual NSArray* GetAllIdentitiesSortedForDisplay() const; + + // Forgets the given identity on the device. This method logs the user out. + // It is asynchronous because it needs to contact the server to revoke the + // authentication token. + // This may be called on an arbitrary thread, but callback will always be on + // the main thread. + virtual void ForgetIdentity(ChromeIdentity* identity, + ForgetIdentityCallback callback); + + // Asynchronously retrieves access tokens for the given user email and scopes. + // Uses the default client id and client secret. + virtual void GetAccessToken(const std::string& email, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback); + + // Asynchronously retrieves access tokens for the given user email and scopes. + virtual void GetAccessToken(const std::string& email, + const std::string& client_id, + const std::string& client_secret, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback); + + // Allow the user to sign in with an identity already seen on this device. + virtual void SigninIdentity(ChromeIdentity* identity, + SigninIdentityCallback callback); + + // Fetches the profile avatar, from the cache or the network. + // For high resolution iPads, returns large images (200 x 200) to avoid + // pixelization. Calls back on the main thread. + virtual void GetAvatarForIdentity(ChromeIdentity* identity, + GetAvatarCallback callback); + + // Synchronously returns any cached avatar, or nil. + // GetAvatarForIdentity() should be generally used instead of this method. + virtual UIImage* GetCachedAvatarForIdentity(ChromeIdentity* identity); + + // Adds and removes observers. + void AddObserver(Observer* observer); + void RemoveObserver(Observer* observer); + + protected: + // Fires |OnIdentityListChanged| on all observers. + void FireIdentityListChanged(); + + // Fires |OnAccessTokenRefreshFailed| on all observers, with the corresponding + // identity and error reason. + void FireAccessTokenRefreshFailed(ChromeIdentity* identity, + AccessTokenErrorReason error); + + // Fires |OnProfileUpdate| on all observers, with the corresponding identity. + void FireProfileDidUpdate(ChromeIdentity* identity); + + private: + base::ObserverList<Observer, true> observer_list_; + + DISALLOW_COPY_AND_ASSIGN(ChromeIdentityService); +}; + +} // namespace ios + +#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_H_ diff --git a/ios/public/provider/chrome/browser/signin/chrome_identity_service.mm b/ios/public/provider/chrome/browser/signin/chrome_identity_service.mm new file mode 100644 index 0000000..460a89b --- /dev/null +++ b/ios/public/provider/chrome/browser/signin/chrome_identity_service.mm @@ -0,0 +1,93 @@ +// Copyright 2015 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. + +#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" + +namespace ios { + +ChromeIdentityService::ChromeIdentityService() {} + +ChromeIdentityService::~ChromeIdentityService() {} + +bool ChromeIdentityService::IsValidIdentity(ChromeIdentity* identity) const { + return false; +} + +ChromeIdentity* ChromeIdentityService::GetIdentityWithEmail( + const std::string& email) const { + return nil; +} + +ChromeIdentity* ChromeIdentityService::GetIdentityWithGaiaID( + const std::string& gaia_id) const { + return nil; +} + +std::vector<std::string> +ChromeIdentityService::GetCanonicalizeEmailsForAllIdentities() const { + return std::vector<std::string>(); +} + +bool ChromeIdentityService::HasIdentities() const { + return false; +} + +NSArray* ChromeIdentityService::GetAllIdentities() const { + return nil; +} + +NSArray* ChromeIdentityService::GetAllIdentitiesSortedForDisplay() const { + return nil; +} + +void ChromeIdentityService::ForgetIdentity(ChromeIdentity* identity, + ForgetIdentityCallback callback) {} + +void ChromeIdentityService::GetAccessToken( + const std::string& email, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback) {} + +void ChromeIdentityService::GetAccessToken( + const std::string& email, + const std::string& client_id, + const std::string& client_secret, + const std::set<std::string>& scopes, + const AccessTokenCallback& callback) {} + +void ChromeIdentityService::SigninIdentity(ChromeIdentity* identity, + SigninIdentityCallback callback) {} + +void ChromeIdentityService::GetAvatarForIdentity(ChromeIdentity* identity, + GetAvatarCallback callback) {} + +UIImage* ChromeIdentityService::GetCachedAvatarForIdentity( + ChromeIdentity* identity) { + return nil; +} + +void ChromeIdentityService::AddObserver(Observer* observer) { + observer_list_.AddObserver(observer); +} + +void ChromeIdentityService::RemoveObserver(Observer* observer) { + observer_list_.RemoveObserver(observer); +} + +void ChromeIdentityService::FireIdentityListChanged() { + FOR_EACH_OBSERVER(Observer, observer_list_, OnIdentityListChanged()); +} + +void ChromeIdentityService::FireAccessTokenRefreshFailed( + ChromeIdentity* identity, + AccessTokenErrorReason error) { + FOR_EACH_OBSERVER(Observer, observer_list_, + OnAccessTokenRefreshFailed(identity, error)); +} + +void ChromeIdentityService::FireProfileDidUpdate(ChromeIdentity* identity) { + FOR_EACH_OBSERVER(Observer, observer_list_, OnProfileUpdate(identity)); +} + +} // namespace ios diff --git a/ios/public/test/test_chrome_browser_provider.h b/ios/public/test/test_chrome_browser_provider.h index 698fa65..d11ea48 100644 --- a/ios/public/test/test_chrome_browser_provider.h +++ b/ios/public/test/test_chrome_browser_provider.h @@ -22,10 +22,12 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider { static TestChromeBrowserProvider* GetTestProvider(); // ChromeBrowserProvider: + ChromeIdentityService* GetChromeIdentityService() override; StringProvider* GetStringProvider() override; const char* GetChromeUIScheme() override; private: + scoped_ptr<ChromeIdentityService> chrome_identity_service_; scoped_ptr<FakeStringProvider> string_provider_; DISALLOW_COPY_AND_ASSIGN(TestChromeBrowserProvider); diff --git a/ios/public/test/test_chrome_browser_provider.mm b/ios/public/test/test_chrome_browser_provider.mm index afcf24c..ddaa16f 100644 --- a/ios/public/test/test_chrome_browser_provider.mm +++ b/ios/public/test/test_chrome_browser_provider.mm @@ -5,6 +5,7 @@ #include "ios/public/test/test_chrome_browser_provider.h" #include "base/logging.h" +#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" #include "ios/public/test/fake_string_provider.h" namespace { @@ -14,8 +15,8 @@ const char kUIScheme[] = "uischeme"; namespace ios { TestChromeBrowserProvider::TestChromeBrowserProvider() - : string_provider_(new FakeStringProvider) { -} + : chrome_identity_service_(new ios::ChromeIdentityService), + string_provider_(new FakeStringProvider) {} TestChromeBrowserProvider::~TestChromeBrowserProvider() { } @@ -27,6 +28,10 @@ TestChromeBrowserProvider* TestChromeBrowserProvider::GetTestProvider() { return static_cast<TestChromeBrowserProvider*>(provider); } +ChromeIdentityService* TestChromeBrowserProvider::GetChromeIdentityService() { + return chrome_identity_service_.get(); +} + StringProvider* TestChromeBrowserProvider::GetStringProvider() { return string_provider_.get(); } |