1 // Copyright 2015 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 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
8 #include "base/observer_list.h"
9 #include "google_apis/gaia/gaia_auth_util.h"
10 #include "google_apis/gaia/oauth2_token_service.h"
13 class URLRequestContextGetter
;
18 // Abstract base class to fetch and maintain refresh tokens from various
19 // entities. Concrete subclasses should implement RefreshTokenIsAvailable and
20 // CreateAccessTokenFetcher properly.
21 class OAuth2TokenServiceDelegate
{
23 OAuth2TokenServiceDelegate();
24 virtual ~OAuth2TokenServiceDelegate();
26 virtual OAuth2AccessTokenFetcher
* CreateAccessTokenFetcher(
27 const std::string
& account_id
,
28 net::URLRequestContextGetter
* getter
,
29 OAuth2AccessTokenConsumer
* consumer
) = 0;
31 virtual bool RefreshTokenIsAvailable(const std::string
& account_id
) const = 0;
32 virtual void UpdateAuthError(const std::string
& account_id
,
33 const GoogleServiceAuthError
& error
){};
35 virtual std::vector
<std::string
> GetAccounts();
36 virtual void RevokeAllCredentials(){};
38 virtual void InvalidateAccessToken(const std::string
& account_id
,
39 const std::string
& client_id
,
40 const std::set
<std::string
>& scopes
,
41 const std::string
& access_token
) {}
43 virtual void Shutdown() {}
44 virtual void LoadCredentials(const std::string
& primary_account_id
) {}
45 virtual void UpdateCredentials(const std::string
& account_id
,
46 const std::string
& refresh_token
) {}
47 virtual void RevokeCredentials(const std::string
& account_id
) {}
48 virtual net::URLRequestContextGetter
* GetRequestContext() const;
50 void ValidateAccountId(const std::string
& account_id
) const;
52 // Add or remove observers of this token service.
53 void AddObserver(OAuth2TokenService::Observer
* observer
);
54 void RemoveObserver(OAuth2TokenService::Observer
* observer
);
57 // Called by subclasses to notify observers.
58 virtual void FireRefreshTokenAvailable(const std::string
& account_id
);
59 virtual void FireRefreshTokenRevoked(const std::string
& account_id
);
60 virtual void FireRefreshTokensLoaded();
62 // Helper class to scope batch changes.
63 class ScopedBatchChange
{
65 explicit ScopedBatchChange(OAuth2TokenServiceDelegate
* delegate
);
69 OAuth2TokenServiceDelegate
* delegate_
; // Weak.
70 DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange
);
74 // List of observers to notify when refresh token availability changes.
75 // Makes sure list is empty on destruction.
76 base::ObserverList
<OAuth2TokenService::Observer
, true> observer_list_
;
78 void StartBatchChanges();
79 void EndBatchChanges();
81 // The depth of batch changes.
82 int batch_change_depth_
;
84 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegate
);
87 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_