1 // Copyright 2014 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.
5 #include "google_apis/gaia/identity_provider.h"
7 IdentityProvider::Observer::~Observer() {}
9 IdentityProvider::~IdentityProvider() {}
11 void IdentityProvider::AddActiveAccountRefreshTokenObserver(
12 OAuth2TokenService::Observer
* observer
) {
13 OAuth2TokenService
* token_service
= GetTokenService();
14 if (!token_service
|| token_service_observers_
.HasObserver(observer
))
17 token_service_observers_
.AddObserver(observer
);
18 if (++token_service_observer_count_
== 1)
19 token_service
->AddObserver(this);
22 void IdentityProvider::RemoveActiveAccountRefreshTokenObserver(
23 OAuth2TokenService::Observer
* observer
) {
24 OAuth2TokenService
* token_service
= GetTokenService();
25 if (!token_service
|| !token_service_observers_
.HasObserver(observer
))
28 token_service_observers_
.RemoveObserver(observer
);
29 if (--token_service_observer_count_
== 0)
30 token_service
->RemoveObserver(this);
33 void IdentityProvider::AddObserver(Observer
* observer
) {
34 observers_
.AddObserver(observer
);
37 void IdentityProvider::RemoveObserver(Observer
* observer
) {
38 observers_
.RemoveObserver(observer
);
41 void IdentityProvider::OnRefreshTokenAvailable(const std::string
& account_id
) {
42 if (account_id
!= GetActiveAccountId())
44 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
,
45 token_service_observers_
,
46 OnRefreshTokenAvailable(account_id
));
49 void IdentityProvider::OnRefreshTokenRevoked(const std::string
& account_id
) {
50 if (account_id
!= GetActiveAccountId())
52 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
,
53 token_service_observers_
,
54 OnRefreshTokenRevoked(account_id
));
57 void IdentityProvider::OnRefreshTokensLoaded() {
58 FOR_EACH_OBSERVER(OAuth2TokenService::Observer
,
59 token_service_observers_
,
60 OnRefreshTokensLoaded());
63 IdentityProvider::IdentityProvider() : token_service_observer_count_(0) {}
65 void IdentityProvider::FireOnActiveAccountLogin() {
66 FOR_EACH_OBSERVER(Observer
, observers_
, OnActiveAccountLogin());
69 void IdentityProvider::FireOnActiveAccountLogout() {
70 FOR_EACH_OBSERVER(Observer
, observers_
, OnActiveAccountLogout());