Commit 5889e4bb authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Add Observer to //chrome's IdentityManagerFactory

IdentityManagerFactory::Observer is a parallel interface to//chrome's
SigninManagerFactory::Observer. It will be used to replace usage of
that observer in follow up CLs.

BUG=927341

Change-Id: Id377b5b5e20e00b49811302b0ab26a611af1d3d4
Reviewed-on: https://chromium-review.googlesource.com/c/1448754
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#628316}
parent 376a7724
......@@ -123,7 +123,30 @@ IdentityManagerFactory::BuildAuthenticatedServiceInstanceForTesting(
return identity_manager;
}
void IdentityManagerFactory::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void IdentityManagerFactory::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
KeyedService* IdentityManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new IdentityManagerWrapper(Profile::FromBrowserContext(context));
auto identity_manager = std::make_unique<IdentityManagerWrapper>(
Profile::FromBrowserContext(context));
for (Observer& observer : observer_list_)
observer.IdentityManagerCreated(identity_manager.get());
return identity_manager.release();
}
void IdentityManagerFactory::BrowserContextShutdown(
content::BrowserContext* context) {
auto* identity_manager = static_cast<IdentityManagerWrapper*>(
GetServiceForBrowserContext(context, false));
if (identity_manager) {
for (Observer& observer : observer_list_)
observer.IdentityManagerShutdown(identity_manager);
}
BrowserContextKeyedServiceFactory::BrowserContextShutdown(context);
}
......@@ -9,6 +9,7 @@
#include <string>
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace identity {
......@@ -21,6 +22,21 @@ class Profile;
// Profiles.
class IdentityManagerFactory : public BrowserContextKeyedServiceFactory {
public:
class Observer {
public:
// Called when a IdentityManager instance is created.
virtual void IdentityManagerCreated(
identity::IdentityManager* identity_manager) {}
// Called when a IdentityManager instance is being shut down. Observers
// of |identity_manager| should remove themselves at this point.
virtual void IdentityManagerShutdown(
identity::IdentityManager* identity_manager) {}
protected:
virtual ~Observer() {}
};
static identity::IdentityManager* GetForProfile(Profile* profile);
static identity::IdentityManager* GetForProfileIfExists(
const Profile* profile);
......@@ -37,6 +53,11 @@ class IdentityManagerFactory : public BrowserContextKeyedServiceFactory {
const std::string& refresh_token,
content::BrowserContext* context);
// Methods to register or remove observers of IdentityManager
// creation/shutdown.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
friend struct base::DefaultSingletonTraits<IdentityManagerFactory>;
......@@ -46,6 +67,10 @@ class IdentityManagerFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
void BrowserContextShutdown(content::BrowserContext* profile) override;
// List of observers. Checks that list is empty on destruction.
mutable base::ObserverList<Observer, true>::Unchecked observer_list_;
DISALLOW_COPY_AND_ASSIGN(IdentityManagerFactory);
};
......
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