1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_
6 #define IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_
7 
8 #import <Foundation/Foundation.h>
9 
10 #include "base/macros.h"
11 #include "base/scoped_observer.h"
12 #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
13 
14 // Objective-C protocol mirroring ChromeIdentityService::Observer.
15 @protocol ChromeIdentityServiceObserver<NSObject>
16 @optional
17 - (void)identityListChanged;
18 - (void)accessTokenRefreshFailed:(ChromeIdentity*)identity
19                         userInfo:(NSDictionary*)userInfo;
20 - (void)profileUpdate:(ChromeIdentity*)identity;
21 - (void)chromeIdentityServiceWillBeDestroyed;
22 @end
23 
24 // Simple observer bridge that forwards all events to its delegate observer.
25 class ChromeIdentityServiceObserverBridge
26     : public ios::ChromeIdentityService::Observer {
27  public:
28   explicit ChromeIdentityServiceObserverBridge(
29       id<ChromeIdentityServiceObserver> observer);
30   ~ChromeIdentityServiceObserverBridge() override;
31 
32  private:
33   // ios::ChromeIdentityService::Observer implementation.
34   void OnIdentityListChanged() override;
35   void OnAccessTokenRefreshFailed(ChromeIdentity* identity,
36                                   NSDictionary* user_info) override;
37   void OnProfileUpdate(ChromeIdentity* identity) override;
38   void OnChromeIdentityServiceWillBeDestroyed() override;
39 
40   __weak id<ChromeIdentityServiceObserver> observer_ = nil;
41   ScopedObserver<ios::ChromeIdentityService,
42                  ios::ChromeIdentityService::Observer>
43       scoped_observer_{this};
44 
45   DISALLOW_COPY_AND_ASSIGN(ChromeIdentityServiceObserverBridge);
46 };
47 
48 #endif  // IOS_CHROME_BROWSER_SIGNIN_CHROME_IDENTITY_SERVICE_OBSERVER_BRIDGE_H_
49