Commit add4a3fc authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

[ios] Migrate bookmark_promo_controller.mm to use IdentityManagerObserverBridge

Remove the custom C++ class IdentityManagerObserver and rely on the
new API from //services/identity/public/objc instead.

Bug: 903262
Change-Id: I32c3d46bbd6c1cd45c092c859ef303d9cd6b240f
Reviewed-on: https://chromium-review.googlesource.com/c/1326151
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607701}
parent 8203409e
...@@ -101,6 +101,7 @@ source_set("bookmarks") { ...@@ -101,6 +101,7 @@ source_set("bookmarks") {
"//ios/third_party/material_roboto_font_loader_ios", "//ios/third_party/material_roboto_font_loader_ios",
"//ios/web", "//ios/web",
"//services/identity/public/cpp", "//services/identity/public/cpp",
"//services/identity/public/objc",
"//ui/base", "//ui/base",
"//ui/gfx", "//ui/gfx",
"//url", "//url",
......
...@@ -13,63 +13,26 @@ ...@@ -13,63 +13,26 @@
#import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h" #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h"
#import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/objc/identity_manager_observer_bridge.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace { @interface BookmarkPromoController ()<SigninPromoViewConsumer,
class IdentityManagerObserver; IdentityManagerObserverBridgeDelegate> {
} // namespace
@interface BookmarkPromoController ()<SigninPromoViewConsumer> {
bool _isIncognito; bool _isIncognito;
ios::ChromeBrowserState* _browserState; ios::ChromeBrowserState* _browserState;
std::unique_ptr<IdentityManagerObserver> _identityManagerObserver; std::unique_ptr<identity::IdentityManagerObserverBridge>
_identityManagerObserverBridge;
} }
// Mediator to use for the sign-in promo view displayed in the bookmark view. // Mediator to use for the sign-in promo view displayed in the bookmark view.
@property(nonatomic, readwrite, strong) @property(nonatomic, readwrite, strong)
SigninPromoViewMediator* signinPromoViewMediator; SigninPromoViewMediator* signinPromoViewMediator;
// IdentityManagerObserver Callbacks
// Called when a user signs into Google services such as sync.
- (void)onPrimaryAccountSetWithAccountId:(const std::string&)account_id
username:(const std::string&)username;
// Called when the currently signed-in user for a user has been signed out.
- (void)onPrimaryAccountClearedWithAccountId:(const std::string&)account_id
username:(const std::string&)username;
@end @end
namespace {
class IdentityManagerObserver : public identity::IdentityManager::Observer {
public:
IdentityManagerObserver(BookmarkPromoController* controller)
: controller_(controller) {}
void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override {
[controller_
onPrimaryAccountSetWithAccountId:primary_account_info.account_id
username:primary_account_info.email];
}
void OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) override {
[controller_
onPrimaryAccountClearedWithAccountId:previous_primary_account_info
.account_id
username:previous_primary_account_info
.email];
}
private:
__weak BookmarkPromoController* controller_;
};
} // namespace
@implementation BookmarkPromoController @implementation BookmarkPromoController
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
...@@ -88,10 +51,9 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer { ...@@ -88,10 +51,9 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer {
_isIncognito = browserState->IsOffTheRecord(); _isIncognito = browserState->IsOffTheRecord();
if (!_isIncognito) { if (!_isIncognito) {
_browserState = browserState; _browserState = browserState;
_identityManagerObserver.reset(new IdentityManagerObserver(self)); _identityManagerObserverBridge.reset(
identity::IdentityManager* identityManager = new identity::IdentityManagerObserverBridge(
IdentityManagerFactory::GetForBrowserState(_browserState); IdentityManagerFactory::GetForBrowserState(_browserState), self));
identityManager->AddObserver(_identityManagerObserver.get());
_signinPromoViewMediator = [[SigninPromoViewMediator alloc] _signinPromoViewMediator = [[SigninPromoViewMediator alloc]
initWithBrowserState:_browserState initWithBrowserState:_browserState
accessPoint:signin_metrics::AccessPoint:: accessPoint:signin_metrics::AccessPoint::
...@@ -106,12 +68,8 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer { ...@@ -106,12 +68,8 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer {
- (void)dealloc { - (void)dealloc {
[_signinPromoViewMediator signinPromoViewRemoved]; [_signinPromoViewMediator signinPromoViewRemoved];
if (!_isIncognito) { if (!_isIncognito)
DCHECK(_browserState); _identityManagerObserverBridge.reset();
identity::IdentityManager* identityManager =
IdentityManagerFactory::GetForBrowserState(_browserState);
identityManager->RemoveObserver(_identityManagerObserver.get());
}
} }
- (void)hidePromoCell { - (void)hidePromoCell {
...@@ -143,18 +101,16 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer { ...@@ -143,18 +101,16 @@ class IdentityManagerObserver : public identity::IdentityManager::Observer {
} }
} }
#pragma mark - IdentityManagerObserver #pragma mark - IdentityManagerObserverBridgeDelegate
// Called when a user signs into Google services such as sync. // Called when a user signs into Google services such as sync.
- (void)onPrimaryAccountSetWithAccountId:(const std::string&)account_id - (void)onPrimaryAccountSet:(const AccountInfo&)primaryAccountInfo {
username:(const std::string&)username {
if (!self.signinPromoViewMediator.isSigninInProgress) if (!self.signinPromoViewMediator.isSigninInProgress)
self.shouldShowSigninPromo = NO; self.shouldShowSigninPromo = NO;
} }
// Called when the currently signed-in user for a user has been signed out. // Called when the currently signed-in user for a user has been signed out.
- (void)onPrimaryAccountClearedWithAccountId:(const std::string&)account_id - (void)onPrimaryAccountCleared:(const AccountInfo&)previousPrimaryAccountInfo {
username:(const std::string&)username {
[self updateShouldShowSigninPromo]; [self updateShouldShowSigninPromo];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment