Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: google_apis/gaia/oauth2_token_service_delegate.h

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update for google_apis_unittests Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: google_apis/gaia/oauth2_token_service_delegate.h
diff --git a/google_apis/gaia/oauth2_token_service_delegate.h b/google_apis/gaia/oauth2_token_service_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..82a8626851261d44c9eb217dfad6682ecc891b3d
--- /dev/null
+++ b/google_apis/gaia/oauth2_token_service_delegate.h
@@ -0,0 +1,95 @@
+// 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.
+
+#ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
+#define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
+
+#include "base/observer_list.h"
+#include "google_apis/gaia/gaia_auth_util.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+class SigninClient;
+
+// ProfileOAuth2TokenServiceDelegate provides an alternative to
+// ProfileOAuth2TokenService. It allows token to be fetched from other external
+// entity such as a OS level accounts database.
+class OAuth2TokenServiceDelegate {
+ public:
+ OAuth2TokenServiceDelegate();
+ virtual ~OAuth2TokenServiceDelegate();
+
+ virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
+ const std::string& account_id,
+ net::URLRequestContextGetter* getter,
+ OAuth2AccessTokenConsumer* consumer) = 0;
+
+ virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0;
+ virtual std::string GetRefreshToken(const std::string& account_id) const = 0;
+ virtual void UpdateAuthError(const std::string& account_id,
+ const GoogleServiceAuthError& error) = 0;
+
+ virtual std::vector<std::string> GetAccounts() = 0;
+ virtual void RevokeAllCredentials() = 0;
+
+ virtual void InvalidateOAuth2Token(const std::string& account_id,
+ const std::string& client_id,
+ const std::set<std::string>& scopes,
+ const std::string& access_token){};
Roger Tawa OOO till Jul 10th 2015/05/28 14:54:44 "OAuth2Token" is not descriptive enough. Let's cl
gogerald1 2015/06/03 18:12:59 Done.
+
+ virtual void Shutdown() {}
+ virtual void LoadCredentials(const std::string& primary_account_id) {}
+ virtual void UpdateCredentials(const std::string& account_id,
+ const std::string& refresh_token) {}
+ virtual void RevokeCredentials(const std::string& account_id) {}
+ virtual net::URLRequestContextGetter* GetRequestContext() const;
+
+ void ValidateAccountId(const std::string& account_id) const {
+ DCHECK(!account_id.empty());
+
+ // If the account is given as an email, make sure its a canonical email.
+ // Note that some tests don't use email strings as account id, and after
+ // the gaia id migration it won't be an email. So only check for
+ // canonicalization if the account_id is suspected to be an email.
+ if (account_id.find('@') != std::string::npos)
+ DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id);
+ }
Roger Tawa OOO till Jul 10th 2015/05/28 14:54:44 Should put the implementation of this function in
gogerald1 2015/06/03 18:12:59 Done.
+
+ // Add or remove observers of this token service.
+ void AddObserver(OAuth2TokenService::Observer* observer);
+ void RemoveObserver(OAuth2TokenService::Observer* observer);
+
+ protected:
+ // Called by subclasses to notify observers.
+ virtual void FireRefreshTokenAvailable(const std::string& account_id);
+ virtual void FireRefreshTokenRevoked(const std::string& account_id);
+ virtual void FireRefreshTokensLoaded();
+
+ // Helper class to scope batch changes.
+ class ScopedBatchChange {
+ public:
+ explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate);
+ ~ScopedBatchChange();
+
+ private:
+ OAuth2TokenServiceDelegate* delegate_; // Weak.
+ DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange);
+ };
+
+ private:
+ // List of observers to notify when refresh token availability changes.
+ // Makes sure list is empty on destruction.
+ ObserverList<OAuth2TokenService::Observer, true> observer_list_;
+
+ void StartBatchChanges();
+ void EndBatchChanges();
+
+ // The depth of batch changes.
+ int batch_change_depth_;
+};
+
+#endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698