Home | History | Annotate | Download | only in gaia
      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.
      4 
      5 #include "google_apis/gaia/identity_provider.h"
      6 
      7 IdentityProvider::Observer::~Observer() {}
      8 
      9 IdentityProvider::~IdentityProvider() {}
     10 
     11 void IdentityProvider::AddActiveAccountRefreshTokenObserver(
     12     OAuth2TokenService::Observer* observer) {
     13   OAuth2TokenService* token_service = GetTokenService();
     14   if (!token_service || token_service_observers_.HasObserver(observer))
     15     return;
     16 
     17   token_service_observers_.AddObserver(observer);
     18   if (++token_service_observer_count_ == 1)
     19     token_service->AddObserver(this);
     20 }
     21 
     22 void IdentityProvider::RemoveActiveAccountRefreshTokenObserver(
     23     OAuth2TokenService::Observer* observer) {
     24   OAuth2TokenService* token_service = GetTokenService();
     25   if (!token_service || !token_service_observers_.HasObserver(observer))
     26     return;
     27 
     28   token_service_observers_.RemoveObserver(observer);
     29   if (--token_service_observer_count_ == 0)
     30     token_service->RemoveObserver(this);
     31 }
     32 
     33 void IdentityProvider::AddObserver(Observer* observer) {
     34   observers_.AddObserver(observer);
     35 }
     36 
     37 void IdentityProvider::RemoveObserver(Observer* observer) {
     38   observers_.RemoveObserver(observer);
     39 }
     40 
     41 void IdentityProvider::OnRefreshTokenAvailable(const std::string& account_id) {
     42   if (account_id != GetActiveAccountId())
     43     return;
     44   FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
     45                     token_service_observers_,
     46                     OnRefreshTokenAvailable(account_id));
     47 }
     48 
     49 void IdentityProvider::OnRefreshTokenRevoked(const std::string& account_id) {
     50   if (account_id != GetActiveAccountId())
     51     return;
     52   FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
     53                     token_service_observers_,
     54                     OnRefreshTokenRevoked(account_id));
     55 }
     56 
     57 void IdentityProvider::OnRefreshTokensLoaded() {
     58   FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
     59                     token_service_observers_,
     60                     OnRefreshTokensLoaded());
     61 }
     62 
     63 IdentityProvider::IdentityProvider() : token_service_observer_count_(0) {}
     64 
     65 void IdentityProvider::FireOnActiveAccountLogin() {
     66   FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogin());
     67 }
     68 
     69 void IdentityProvider::FireOnActiveAccountLogout() {
     70   FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogout());
     71 }
     72