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

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

Issue 15977002: Add ManagedUserTokenFetcher to fetch scoped-down tokens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 6 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 | Annotate | Revision Log
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 // A set of scopes in OAuth2 authentication. 75 // A set of scopes in OAuth2 authentication.
76 typedef std::set<std::string> ScopeSet; 76 typedef std::set<std::string> ScopeSet;
77 77
78 explicit OAuth2TokenService(net::URLRequestContextGetter* getter); 78 explicit OAuth2TokenService(net::URLRequestContextGetter* getter);
79 virtual ~OAuth2TokenService(); 79 virtual ~OAuth2TokenService();
80 80
81 // Checks in the cache for a valid access token, and if not found starts 81 // Checks in the cache for a valid access token, and if not found starts
82 // a request for an OAuth2 access token using the OAuth2 refresh token 82 // a request for an OAuth2 access token using the OAuth2 refresh token
83 // maintained by this instance. The caller owns the returned Request. 83 // maintained by this instance. The caller owns the returned Request.
84 // |scopes| is the set of scopes to get an access token for, |consumer| is 84 // |scopes| is the set of scopes to get an access token for. If the set is
85 // the object that will be called back with results if the returned request 85 // empty, the returned access token will have the same scope as the refresh
86 // is not deleted. 86 // token.
87 // |consumer| is the object that will be called back with results if the
88 // returned request is not deleted.
87 virtual scoped_ptr<Request> StartRequest(const ScopeSet& scopes, 89 virtual scoped_ptr<Request> StartRequest(const ScopeSet& scopes,
88 Consumer* consumer); 90 Consumer* consumer);
89 91
90 // Returns true if a refresh token exists. If false, calls to 92 // Returns true if a refresh token exists. If false, calls to
91 // |StartRequest| will result in a Consumer::OnGetTokenFailure callback. 93 // |StartRequest| will result in a Consumer::OnGetTokenFailure callback.
92 bool RefreshTokenIsAvailable(); 94 bool RefreshTokenIsAvailable();
93 95
94 // Mark an OAuth2 access token as invalid. This should be done if the token 96 // Mark an OAuth2 access token as invalid. This should be done if the token
95 // was received from this class, but was not accepted by the server (e.g., 97 // was received from this class, but was not accepted by the server (e.g.,
96 // the server returned 401 Unauthorized). The token will be removed from the 98 // the server returned 401 Unauthorized). The token will be removed from the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Informs |consumer_| that this request is completed. 143 // Informs |consumer_| that this request is completed.
142 void InformConsumer(const GoogleServiceAuthError& error, 144 void InformConsumer(const GoogleServiceAuthError& error,
143 const std::string& access_token, 145 const std::string& access_token,
144 const base::Time& expiration_date); 146 const base::Time& expiration_date);
145 147
146 private: 148 private:
147 // |consumer_| to call back when this request completes. 149 // |consumer_| to call back when this request completes.
148 Consumer* const consumer_; 150 Consumer* const consumer_;
149 }; 151 };
150 152
151 // Informs the consumer of |request| fetch results.
152 static void InformConsumer(base::WeakPtr<RequestImpl> request,
153 const GoogleServiceAuthError& error,
154 const std::string& access_token,
155 const base::Time& expiration_date);
156
157 private: 153 private:
158 // Class that fetches an OAuth2 access token for a given set of scopes and 154 // Class that fetches an OAuth2 access token for a given set of scopes and
159 // OAuth2 refresh token. 155 // OAuth2 refresh token.
160 class Fetcher; 156 class Fetcher;
161 friend class Fetcher; 157 friend class Fetcher;
162 158
163 // Struct that contains the information of an OAuth2 access token. 159 // Struct that contains the information of an OAuth2 access token.
164 struct CacheEntry { 160 struct CacheEntry {
165 std::string access_token; 161 std::string access_token;
166 base::Time expiration_date; 162 base::Time expiration_date;
(...skipping 26 matching lines...) Expand all
193 // token. 189 // token.
194 typedef std::pair<std::string, ScopeSet> FetchParameters; 190 typedef std::pair<std::string, ScopeSet> FetchParameters;
195 // A map from fetch parameters to a fetcher that is fetching an OAuth2 access 191 // A map from fetch parameters to a fetcher that is fetching an OAuth2 access
196 // token using these parameters. 192 // token using these parameters.
197 std::map<FetchParameters, Fetcher*> pending_fetchers_; 193 std::map<FetchParameters, Fetcher*> pending_fetchers_;
198 194
199 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); 195 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService);
200 }; 196 };
201 197
202 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_ 198 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698