Commit 449a12f7 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Chromium LUCI CQ

Kaleidoscope: add KaleidoscopeIdentityObserver to be notified about sign-in status changes.

This will complete the flow when calling SignIn() and will allow the UI to be
notified if the user signs in or out of the browser.

Bug: b/170751292
Change-Id: I64a7a45b50d545596cfafe3b3335a1de8d94f71c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551134
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832209}
parent 088f488c
......@@ -55,9 +55,12 @@ KaleidoscopeIdentityManagerImpl::KaleidoscopeIdentityManagerImpl(
}
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
identity_manager_->AddObserver(this);
}
KaleidoscopeIdentityManagerImpl::~KaleidoscopeIdentityManagerImpl() = default;
KaleidoscopeIdentityManagerImpl::~KaleidoscopeIdentityManagerImpl() {
identity_manager_->RemoveObserver(this);
}
void KaleidoscopeIdentityManagerImpl::GetCredentials(
GetCredentialsCallback cb) {
......@@ -145,3 +148,20 @@ void KaleidoscopeIdentityManagerImpl::SignIn() {
signin_metrics::AccessPoint::ACCESS_POINT_KALEIDOSCOPE);
#endif // defined(OS_CHROMEOS)
}
void KaleidoscopeIdentityManagerImpl::AddObserver(
mojo::PendingRemote<media::mojom::KaleidoscopeIdentityObserver> observer) {
identity_observers_.Add(std::move(observer));
}
void KaleidoscopeIdentityManagerImpl::OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) {
for (auto& observer : identity_observers_)
observer->OnSignedIn();
}
void KaleidoscopeIdentityManagerImpl::OnRefreshTokenRemovedForAccount(
const CoreAccountId& account_id) {
for (auto& observer : identity_observers_)
observer->OnSignedOut();
}
......@@ -8,9 +8,11 @@
#include <memory>
#include "chrome/browser/media/kaleidoscope/mojom/kaleidoscope.mojom.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace content {
class WebUI;
......@@ -25,7 +27,8 @@ class PrimaryAccountAccessTokenFetcher;
class Profile;
class KaleidoscopeIdentityManagerImpl
: public media::mojom::KaleidoscopeIdentityManager {
: public media::mojom::KaleidoscopeIdentityManager,
public signin::IdentityManager::Observer {
public:
KaleidoscopeIdentityManagerImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager> receiver,
......@@ -43,6 +46,15 @@ class KaleidoscopeIdentityManagerImpl
// media::mojom::KaleidoscopeIdentityManager implementation.
void GetCredentials(GetCredentialsCallback cb) override;
void SignIn() override;
void AddObserver(
mojo::PendingRemote<media::mojom::KaleidoscopeIdentityObserver> observer)
override;
// signin::IdentityManager::Observer implementation.
void OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) override;
void OnRefreshTokenRemovedForAccount(
const CoreAccountId& account_id) override;
private:
// Called when an access token request completes (successfully or not).
......@@ -64,6 +76,9 @@ class KaleidoscopeIdentityManagerImpl
content::WebUI* web_ui_ = nullptr;
Profile* profile_ = nullptr;
mojo::RemoteSet<media::mojom::KaleidoscopeIdentityObserver>
identity_observers_;
mojo::Receiver<media::mojom::KaleidoscopeIdentityManager> receiver_;
};
......
......@@ -119,7 +119,25 @@ interface KaleidoscopeIdentityManager {
GetCredentials() => (Credentials? credentials, CredentialsResult result);
// Will trigger a browser signin.
// The caller has to use KaleidoscopeIdentityObserver in order to be notified
// if the user signs in. This method doesn't notify the caller directly given
// that the user may take no action.
SignIn();
// Add an observer to be notified when the user signs in or out of Chrome.
AddObserver(pending_remote<KaleidoscopeIdentityObserver> observer);
};
// Interface to be implemented by clients of KaleidoscopeIdentityManager that
// want to be notified when a sign in or sign out occurs. This must be used in
// order to be notified if a call to SignIn() ultimately leads to the user
// signing in.
interface KaleidoscopeIdentityObserver {
// Called when the user signs in.
OnSignedIn();
// Called when the user signs out.
OnSignedOut();
};
enum GetCollectionsResult {
......
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