summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/identity_provider.cc
diff options
context:
space:
mode:
authorbartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 19:46:53 +0000
committerbartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 19:46:53 +0000
commita263ff59f18b9ab39601fafe4e60e44e9a20d20f (patch)
tree027c91e3e5811572d8d9bc111f962ca69a61d0e7 /google_apis/gaia/identity_provider.cc
parent2442605058353f23d08db64f39cff92c48f7e8e6 (diff)
downloadchromium_src-a263ff59f18b9ab39601fafe4e60e44e9a20d20f.zip
chromium_src-a263ff59f18b9ab39601fafe4e60e44e9a20d20f.tar.gz
chromium_src-a263ff59f18b9ab39601fafe4e60e44e9a20d20f.tar.bz2
Rename InvalidationAuthProvider to IdentityProvider
The InvalidationAuthProvider is useful outside the area of invalidation: It provides an abstract interface for accessing the logged-in GAIA account and receiving notifications about login/logout events. This CL renames the InvalidationAuthProvider to IdentityProvider and places it in the gaia_apis component. This change is a prerequisite for CL 225403021, which will use the IdentityProvider in GCM. BUG=362083 TEST=Updated tests TBR=atwilson (for chrome/browser/sync/test/integration/sync_test.cc) Review URL: https://codereview.chromium.org/235273002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/identity_provider.cc')
-rw-r--r--google_apis/gaia/identity_provider.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/google_apis/gaia/identity_provider.cc b/google_apis/gaia/identity_provider.cc
new file mode 100644
index 0000000..842891e
--- /dev/null
+++ b/google_apis/gaia/identity_provider.cc
@@ -0,0 +1,71 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gaia/identity_provider.h"
+
+IdentityProvider::Observer::~Observer() {}
+
+IdentityProvider::~IdentityProvider() {}
+
+void IdentityProvider::AddActiveAccountRefreshTokenObserver(
+ OAuth2TokenService::Observer* observer) {
+ OAuth2TokenService* token_service = GetTokenService();
+ if (!token_service || token_service_observers_.HasObserver(observer))
+ return;
+
+ token_service_observers_.AddObserver(observer);
+ if (++token_service_observer_count_ == 1)
+ token_service->AddObserver(this);
+}
+
+void IdentityProvider::RemoveActiveAccountRefreshTokenObserver(
+ OAuth2TokenService::Observer* observer) {
+ OAuth2TokenService* token_service = GetTokenService();
+ if (!token_service || !token_service_observers_.HasObserver(observer))
+ return;
+
+ token_service_observers_.RemoveObserver(observer);
+ if (--token_service_observer_count_ == 0)
+ token_service->RemoveObserver(this);
+}
+
+void IdentityProvider::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void IdentityProvider::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void IdentityProvider::OnRefreshTokenAvailable(const std::string& account_id) {
+ if (account_id != GetActiveAccountId())
+ return;
+ FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
+ token_service_observers_,
+ OnRefreshTokenAvailable(account_id));
+}
+
+void IdentityProvider::OnRefreshTokenRevoked(const std::string& account_id) {
+ if (account_id != GetActiveAccountId())
+ return;
+ FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
+ token_service_observers_,
+ OnRefreshTokenRevoked(account_id));
+}
+
+void IdentityProvider::OnRefreshTokensLoaded() {
+ FOR_EACH_OBSERVER(OAuth2TokenService::Observer,
+ token_service_observers_,
+ OnRefreshTokensLoaded());
+}
+
+IdentityProvider::IdentityProvider() : token_service_observer_count_(0) {}
+
+void IdentityProvider::FireOnActiveAccountLogin() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogin());
+}
+
+void IdentityProvider::FireOnActiveAccountLogout() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnActiveAccountLogout());
+}