Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / google_apis / gaia / identity_provider.cc
blobbe698ffbfa0cf487ff4a312b86473092d8f4b3d7
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 "base/profiler/scoped_tracker.h"
6 #include "google_apis/gaia/identity_provider.h"
8 IdentityProvider::Observer::~Observer() {}
10 IdentityProvider::~IdentityProvider() {}
12 void IdentityProvider::AddActiveAccountRefreshTokenObserver(
13 OAuth2TokenService::Observer* observer) {
14 OAuth2TokenService* token_service = GetTokenService();
15 if (!token_service || token_service_observers_.HasObserver(observer))
16 return;
18 token_service_observers_.AddObserver(observer);
19 if (++token_service_observer_count_ == 1)
20 token_service->AddObserver(this);
23 void IdentityProvider::RemoveActiveAccountRefreshTokenObserver(
24 OAuth2TokenService::Observer* observer) {
25 OAuth2TokenService* token_service = GetTokenService();
26 if (!token_service || !token_service_observers_.HasObserver(observer))
27 return;
29 token_service_observers_.RemoveObserver(observer);
30 if (--token_service_observer_count_ == 0)
31 token_service->RemoveObserver(this);
34 void IdentityProvider::AddObserver(Observer* observer) {
35 observers_.AddObserver(observer);
38 void IdentityProvider::RemoveObserver(Observer* observer) {
39 observers_.RemoveObserver(observer);
42 void IdentityProvider::OnRefreshTokenAvailable(const std::string& account_id) {
43 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
44 // fixed.
45 tracked_objects::ScopedTracker tracking_profile(
46 FROM_HERE_WITH_EXPLICIT_FUNCTION(
47 "422460 IdentityProvider::OnRefreshTokenAvailable"));
49 if (account_id != GetActiveAccountId())
50 return;
51 FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
52 token_service_observers_,
53 OnRefreshTokenAvailable(account_id));
56 void IdentityProvider::OnRefreshTokenRevoked(const std::string& account_id) {
57 if (account_id != GetActiveAccountId())
58 return;
59 FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
60 token_service_observers_,
61 OnRefreshTokenRevoked(account_id));
64 void IdentityProvider::OnRefreshTokensLoaded() {
65 FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
66 token_service_observers_,
67 OnRefreshTokensLoaded());
70 IdentityProvider::IdentityProvider() : token_service_observer_count_(0) {}
72 void IdentityProvider::FireOnActiveAccountLogin() {
73 FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogin());
76 void IdentityProvider::FireOnActiveAccountLogout() {
77 FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogout());