Commit d78473d4 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Add Observer to //ios/chrome's IdentityManagerFactory

IdentityManagerFactoryObserver is a parallel interface to //ios/chrome's
SigninManagerFactoryObserver. It will be used to replace usage of
that observer in follow up CLs.

BUG=927343

hange-Id: I5d32caf0fa0c24b692b6d5ccaf6f8d191818fd74
Change-Id: I801a883aa72ee69e3686fff58ddd4b5c893c799c
Reviewed-on: https://chromium-review.googlesource.com/c/1448473
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#628325}
parent 925f0a11
......@@ -36,6 +36,7 @@ source_set("signin") {
"gaia_cookie_manager_service_factory.h",
"identity_manager_factory.cc",
"identity_manager_factory.h",
"identity_manager_factory_observer.h",
"identity_service_creator.cc",
"identity_service_creator.h",
"ios_chrome_signin_client.h",
......
......@@ -12,6 +12,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/account_tracker_service_factory.h"
#include "ios/chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory_observer.h"
#include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "ios/chrome/browser/signin/signin_manager_factory.h"
#include "services/identity/public/cpp/accounts_mutator.h"
......@@ -75,8 +76,33 @@ IdentityManagerFactory* IdentityManagerFactory::GetInstance() {
return instance.get();
}
void IdentityManagerFactory::AddObserver(
IdentityManagerFactoryObserver* observer) {
observer_list_.AddObserver(observer);
}
void IdentityManagerFactory::RemoveObserver(
IdentityManagerFactoryObserver* observer) {
observer_list_.RemoveObserver(observer);
}
std::unique_ptr<KeyedService> IdentityManagerFactory::BuildServiceInstanceFor(
web::BrowserState* browser_state) const {
return std::make_unique<IdentityManagerWrapper>(
auto identity_manager = std::make_unique<IdentityManagerWrapper>(
ios::ChromeBrowserState::FromBrowserState(browser_state));
for (auto& observer : observer_list_)
observer.IdentityManagerCreated(identity_manager.get());
return identity_manager;
}
void IdentityManagerFactory::BrowserStateShutdown(web::BrowserState* context) {
auto* identity_manager = static_cast<IdentityManagerWrapper*>(
GetServiceForBrowserState(context, false));
if (identity_manager) {
for (auto& observer : observer_list_)
observer.IdentityManagerShutdown(identity_manager);
}
BrowserStateKeyedServiceFactory::BrowserStateShutdown(context);
}
......@@ -7,8 +7,11 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
class IdentityManagerFactoryObserver;
namespace identity {
class IdentityManager;
}
......@@ -29,15 +32,25 @@ class IdentityManagerFactory : public BrowserStateKeyedServiceFactory {
// Returns an instance of the IdentityManagerFactory singleton.
static IdentityManagerFactory* GetInstance();
// Methods to register or remove observers of IdentityManager
// creation/shutdown.
void AddObserver(IdentityManagerFactoryObserver* observer);
void RemoveObserver(IdentityManagerFactoryObserver* observer);
private:
friend class base::NoDestructor<IdentityManagerFactory>;
IdentityManagerFactory();
~IdentityManagerFactory() override;
// List of observers. Checks that list is empty on destruction.
mutable base::ObserverList<IdentityManagerFactoryObserver, true>::Unchecked
observer_list_;
// BrowserStateKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* browser_state) const override;
void BrowserStateShutdown(web::BrowserState* context) override;
DISALLOW_COPY_AND_ASSIGN(IdentityManagerFactory);
};
......
// Copyright 2019 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_IDENTITY_MANAGER_FACTORY_OBSERVER_H_
#define IOS_CHROME_BROWSER_SIGNIN_IDENTITY_MANAGER_FACTORY_OBSERVER_H_
#include "base/macros.h"
namespace identity {
class IdentityManager;
}
// Observer for IdentityManagerFactory.
class IdentityManagerFactoryObserver {
public:
IdentityManagerFactoryObserver() {}
virtual ~IdentityManagerFactoryObserver() {}
// Called when an IdentityManager instance is created.
virtual void IdentityManagerCreated(identity::IdentityManager* manager) {}
// Called when a IdentityManager instance is being shut down. Observers
// of |manager| should remove themselves at this point.
virtual void IdentityManagerShutdown(identity::IdentityManager* manager) {}
private:
DISALLOW_COPY_AND_ASSIGN(IdentityManagerFactoryObserver);
};
#endif // IOS_CHROME_BROWSER_SIGNIN_IDENTITY_MANAGER_FACTORY_OBSERVER_H_
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