cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / google_apis / gaia / oauth2_token_service_delegate.h
blob3a2d39fb246962cbd73e173aa390b4cf5de5831b
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"
12 namespace net {
13 class URLRequestContextGetter;
16 class SigninClient;
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 {
22 public:
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 bool RefreshTokenHasError(const std::string& account_id) const;
33 virtual void UpdateAuthError(const std::string& account_id,
34 const GoogleServiceAuthError& error) {}
36 virtual std::vector<std::string> GetAccounts();
37 virtual void RevokeAllCredentials(){};
39 virtual void InvalidateAccessToken(const std::string& account_id,
40 const std::string& client_id,
41 const std::set<std::string>& scopes,
42 const std::string& access_token) {}
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;
51 void ValidateAccountId(const std::string& account_id) const;
53 // Add or remove observers of this token service.
54 void AddObserver(OAuth2TokenService::Observer* observer);
55 void RemoveObserver(OAuth2TokenService::Observer* observer);
57 protected:
58 // Called by subclasses to notify observers.
59 virtual void FireRefreshTokenAvailable(const std::string& account_id);
60 virtual void FireRefreshTokenRevoked(const std::string& account_id);
61 virtual void FireRefreshTokensLoaded();
63 // Helper class to scope batch changes.
64 class ScopedBatchChange {
65 public:
66 explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate);
67 ~ScopedBatchChange();
69 private:
70 OAuth2TokenServiceDelegate* delegate_; // Weak.
71 DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange);
74 // This function is called by derived classes to help implement
75 // RefreshTokenHasError(). It centralizes the code for determining if
76 // |error| is worthy of being reported as an error for purposes of
77 // RefreshTokenHasError().
78 static bool IsError(const GoogleServiceAuthError& error);
80 private:
81 // List of observers to notify when refresh token availability changes.
82 // Makes sure list is empty on destruction.
83 base::ObserverList<OAuth2TokenService::Observer, true> observer_list_;
85 void StartBatchChanges();
86 void EndBatchChanges();
88 // The depth of batch changes.
89 int batch_change_depth_;
91 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegate);
94 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_