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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
7
8 #include "base/observer_list.h"
9 #include "google_apis/gaia/gaia_auth_util.h"
10 #include "google_apis/gaia/oauth2_token_service.h"
11
12 namespace net {
13 class URLRequestContextGetter;
14 }
15
16 class SigninClient;
17
18 // ProfileOAuth2TokenServiceDelegate provides an alternative to
19 // ProfileOAuth2TokenService. It allows token to be fetched from other external
20 // entity such as a OS level accounts database.
21 class OAuth2TokenServiceDelegate {
22 public:
23 OAuth2TokenServiceDelegate();
24 virtual ~OAuth2TokenServiceDelegate();
25
26 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
27 const std::string& account_id,
28 net::URLRequestContextGetter* getter,
29 OAuth2AccessTokenConsumer* consumer) = 0;
30
31 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0;
32 virtual std::string GetRefreshToken(const std::string& account_id) const = 0;
33 virtual void UpdateAuthError(const std::string& account_id,
34 const GoogleServiceAuthError& error) = 0;
35
36 virtual std::vector<std::string> GetAccounts() = 0;
37 virtual void RevokeAllCredentials() = 0;
38
39 virtual void InvalidateOAuth2Token(const std::string& account_id,
40 const std::string& client_id,
41 const std::set<std::string>& scopes,
42 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.
43
44 virtual void Shutdown() {}
45 virtual void LoadCredentials(const std::string& primary_account_id) {}
46 virtual void UpdateCredentials(const std::string& account_id,
47 const std::string& refresh_token) {}
48 virtual void RevokeCredentials(const std::string& account_id) {}
49 virtual net::URLRequestContextGetter* GetRequestContext() const;
50
51 void ValidateAccountId(const std::string& account_id) const {
52 DCHECK(!account_id.empty());
53
54 // If the account is given as an email, make sure its a canonical email.
55 // Note that some tests don't use email strings as account id, and after
56 // the gaia id migration it won't be an email. So only check for
57 // canonicalization if the account_id is suspected to be an email.
58 if (account_id.find('@') != std::string::npos)
59 DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id);
60 }
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.
61
62 // Add or remove observers of this token service.
63 void AddObserver(OAuth2TokenService::Observer* observer);
64 void RemoveObserver(OAuth2TokenService::Observer* observer);
65
66 protected:
67 // Called by subclasses to notify observers.
68 virtual void FireRefreshTokenAvailable(const std::string& account_id);
69 virtual void FireRefreshTokenRevoked(const std::string& account_id);
70 virtual void FireRefreshTokensLoaded();
71
72 // Helper class to scope batch changes.
73 class ScopedBatchChange {
74 public:
75 explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate);
76 ~ScopedBatchChange();
77
78 private:
79 OAuth2TokenServiceDelegate* delegate_; // Weak.
80 DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange);
81 };
82
83 private:
84 // List of observers to notify when refresh token availability changes.
85 // Makes sure list is empty on destruction.
86 ObserverList<OAuth2TokenService::Observer, true> observer_list_;
87
88 void StartBatchChanges();
89 void EndBatchChanges();
90
91 // The depth of batch changes.
92 int batch_change_depth_;
93 };
94
95 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698