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

Side by Side Diff: chrome/browser/signin/oauth2_token_service.h

Issue 12880014: Get OAuth2TokenService working on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable unit test on Android -- it doesn't make sense. Created 7 years, 9 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
6 #define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_ 6 #define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // deleted. 92 // deleted.
93 // Note the refresh token has been collected from TokenService when this 93 // Note the refresh token has been collected from TokenService when this
94 // method returns, and the request can continue even if TokenService clears 94 // method returns, and the request can continue even if TokenService clears
95 // its tokens after this method returns. This means that outstanding 95 // its tokens after this method returns. This means that outstanding
96 // StartRequest actions will still complete even if the user signs out in the 96 // StartRequest actions will still complete even if the user signs out in the
97 // meantime. 97 // meantime.
98 virtual scoped_ptr<Request> StartRequest( 98 virtual scoped_ptr<Request> StartRequest(
99 const ScopeSet& scopes, 99 const ScopeSet& scopes,
100 OAuth2TokenService::Consumer* consumer); 100 OAuth2TokenService::Consumer* consumer);
101 101
102 // Mark an OAuth2 access token as invalid. This should be done if the token
103 // was received from this class, but was not accepted by the server (e.g.,
104 // the server returned 401 Unauthorized). The token will be removed from the
105 // cache for the given scopes.
106 void InvalidateToken(const ScopeSet& scopes,
107 const std::string& invalid_token);
108
102 // content::NotificationObserver 109 // content::NotificationObserver
103 virtual void Observe(int type, 110 virtual void Observe(int type,
104 const content::NotificationSource& source, 111 const content::NotificationSource& source,
105 const content::NotificationDetails& details) OVERRIDE; 112 const content::NotificationDetails& details) OVERRIDE;
106 113
107 // SigninGlobalError::AuthStatusProvider implementation. 114 // SigninGlobalError::AuthStatusProvider implementation.
108 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; 115 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE;
109 116
110 private: 117 private:
111 // Class that fetches an OAuth2 access token for a given set of scopes and 118 // Class that fetches an OAuth2 access token for a given set of scopes and
112 // OAuth2 refresh token. 119 // OAuth2 refresh token.
113 class Fetcher; 120 class Fetcher;
114 friend class Fetcher; 121 friend class Fetcher;
115 // Implementation of Request. 122 // Implementation of Request.
116 class RequestImpl; 123 class RequestImpl;
117 124
118 // Informs the consumer of |request| fetch results. 125 // Informs the consumer of |request| fetch results.
119 static void InformConsumer( 126 static void InformConsumer(
120 base::WeakPtr<OAuth2TokenService::RequestImpl> request, 127 base::WeakPtr<OAuth2TokenService::RequestImpl> request,
121 GoogleServiceAuthError error, 128 const GoogleServiceAuthError& error,
122 std::string access_token, 129 const std::string& access_token,
123 base::Time expiration_date); 130 const base::Time& expiration_date);
124 131
125 // Struct that contains the information of an OAuth2 access token. 132 // Struct that contains the information of an OAuth2 access token.
126 struct CacheEntry { 133 struct CacheEntry {
127 std::string access_token; 134 std::string access_token;
128 base::Time expiration_date; 135 base::Time expiration_date;
129 }; 136 };
130 137
131 // Returns a currently valid OAuth2 access token for the given set of scopes, 138 // Returns a currently valid OAuth2 access token for the given set of scopes,
132 // or NULL if none have been cached. Note the user of this method should 139 // or NULL if none have been cached. Note the user of this method should
133 // ensure no entry with the same |scopes| is added before the usage of the 140 // ensure no entry with the same |scopes| is added before the usage of the
134 // returned entry is done. 141 // returned entry is done.
135 const CacheEntry* GetCacheEntry(const ScopeSet& scopes); 142 const CacheEntry* GetCacheEntry(const ScopeSet& scopes);
143
136 // Registers a new access token in the cache if |refresh_token| is the one 144 // Registers a new access token in the cache if |refresh_token| is the one
137 // currently held by TokenService. 145 // currently held by TokenService.
138 void RegisterCacheEntry(const std::string& refresh_token, 146 void RegisterCacheEntry(const std::string& refresh_token,
139 const ScopeSet& scopes, 147 const ScopeSet& scopes,
140 const std::string& access_token, 148 const std::string& access_token,
141 const base::Time& expiration_date); 149 const base::Time& expiration_date);
142 150
151 // Removes an access token for the given set of scopes from the cache.
152 // Returns true if the entry was removed, otherwise false.
153 bool RemoveCacheEntry(const OAuth2TokenService::ScopeSet& scopes,
154 const std::string& token_to_remove);
155
156
143 // Called when |fetcher| finishes fetching. 157 // Called when |fetcher| finishes fetching.
144 void OnFetchComplete(Fetcher* fetcher); 158 void OnFetchComplete(Fetcher* fetcher);
145 159
146 // Updates the internal cache of the result from the most-recently-completed 160 // Updates the internal cache of the result from the most-recently-completed
147 // auth request (used for reporting errors to the user). 161 // auth request (used for reporting errors to the user).
148 void UpdateAuthError(const GoogleServiceAuthError& error); 162 void UpdateAuthError(const GoogleServiceAuthError& error);
149 163
150 // The profile with which this instance was initialized, or NULL. 164 // The profile with which this instance was initialized, or NULL.
151 Profile* profile_; 165 Profile* profile_;
152 166
(...skipping 14 matching lines...) Expand all
167 // token using these parameters. 181 // token using these parameters.
168 std::map<FetchParameters, Fetcher*> pending_fetchers_; 182 std::map<FetchParameters, Fetcher*> pending_fetchers_;
169 183
170 // Registrar for notifications from the TokenService. 184 // Registrar for notifications from the TokenService.
171 content::NotificationRegistrar registrar_; 185 content::NotificationRegistrar registrar_;
172 186
173 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); 187 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService);
174 }; 188 };
175 189
176 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_ 190 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/web_history_service.cc ('k') | chrome/browser/signin/oauth2_token_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698