OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_NET_GAIA_GAIA_OAUTH_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_NET_GAIA_GAIA_OAUTH_FETCHER_H_ |
6 #define CHROME_BROWSER_NET_GAIA_GAIA_OAUTH_FETCHER_H_ | 6 #define CHROME_BROWSER_NET_GAIA_GAIA_OAUTH_FETCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 13 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/common/url_fetcher_delegate.h" | |
18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" |
19 | 19 |
20 struct ChromeCookieDetails; | 20 struct ChromeCookieDetails; |
21 | 21 |
22 class Browser; | 22 class Browser; |
23 class Profile; | 23 class Profile; |
24 | 24 |
25 namespace net { | 25 namespace net { |
| 26 class URLFetcher; |
26 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
27 class URLRequestStatus; | 28 class URLRequestStatus; |
28 typedef std::vector<std::string> ResponseCookies; | 29 typedef std::vector<std::string> ResponseCookies; |
29 } | 30 } |
30 | 31 |
31 // Authenticate a user using Gaia's OAuth1 and OAuth2 support. | 32 // Authenticate a user using Gaia's OAuth1 and OAuth2 support. |
32 // | 33 // |
33 // Users of this class typically desire an OAuth2 Access token scoped for a | 34 // Users of this class typically desire an OAuth2 Access token scoped for a |
34 // specific service. This will typically start with either an interactive | 35 // specific service. This will typically start with either an interactive |
35 // login, using StartGetOAuthToken, or with a long-lived OAuth1 all-scope | 36 // login, using StartGetOAuthToken, or with a long-lived OAuth1 all-scope |
36 // token obtained through a previous login or other means, using | 37 // token obtained through a previous login or other means, using |
37 // StartOAuthGetAccessToken. In fact, one can start with any of these | 38 // StartOAuthGetAccessToken. In fact, one can start with any of these |
38 // routines: | 39 // routines: |
39 // StartGetOAuthToken() | 40 // StartGetOAuthToken() |
40 // StartOAuthGetAccessToken() | 41 // StartOAuthGetAccessToken() |
41 // StartOAuthWrapBridge() | 42 // StartOAuthWrapBridge() |
42 // StartUserInfo() | 43 // StartUserInfo() |
43 // with the expectation that each of these calls the next Start* routine in | 44 // with the expectation that each of these calls the next Start* routine in |
44 // the sequence, except for StartUserInfo as it's the last one. | 45 // the sequence, except for StartUserInfo as it's the last one. |
45 // | 46 // |
46 // This class can handle one request at a time, and all calls through an | 47 // This class can handle one request at a time, and all calls through an |
47 // instance should be serialized. | 48 // instance should be serialized. |
48 class GaiaOAuthFetcher : public content::URLFetcherDelegate, | 49 class GaiaOAuthFetcher : public net::URLFetcherDelegate, |
49 public content::NotificationObserver { | 50 public content::NotificationObserver { |
50 public: | 51 public: |
51 // Defines steps of OAuth process performed by this class. | 52 // Defines steps of OAuth process performed by this class. |
52 typedef enum { | 53 typedef enum { |
53 OAUTH1_LOGIN, | 54 OAUTH1_LOGIN, |
54 OAUTH1_REQUEST_TOKEN, | 55 OAUTH1_REQUEST_TOKEN, |
55 OAUTH1_ALL_ACCESS_TOKEN, | 56 OAUTH1_ALL_ACCESS_TOKEN, |
56 OAUTH2_SERVICE_ACCESS_TOKEN, | 57 OAUTH2_SERVICE_ACCESS_TOKEN, |
57 USER_INFO, | 58 USER_INFO, |
58 OAUTH2_REVOKE_TOKEN, | 59 OAUTH2_REVOKE_TOKEN, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 const content::NotificationDetails& details) OVERRIDE; | 130 const content::NotificationDetails& details) OVERRIDE; |
130 | 131 |
131 // Called when a cookie, e. g. oauth_token, changes | 132 // Called when a cookie, e. g. oauth_token, changes |
132 virtual void OnCookieChanged(Profile* profile, | 133 virtual void OnCookieChanged(Profile* profile, |
133 ChromeCookieDetails* cookie_details); | 134 ChromeCookieDetails* cookie_details); |
134 | 135 |
135 // Called when a cookie, e. g. oauth_token, changes | 136 // Called when a cookie, e. g. oauth_token, changes |
136 virtual void OnBrowserClosing(Browser* profile, | 137 virtual void OnBrowserClosing(Browser* profile, |
137 bool detail); | 138 bool detail); |
138 | 139 |
139 // Implementation of content::URLFetcherDelegate | 140 // Implementation of net::URLFetcherDelegate |
140 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 141 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
141 | 142 |
142 // StartGetOAuthToken (or other Start* routine) been called, but results | 143 // StartGetOAuthToken (or other Start* routine) been called, but results |
143 // are not back yet. | 144 // are not back yet. |
144 virtual bool HasPendingFetch() const; | 145 virtual bool HasPendingFetch() const; |
145 | 146 |
146 // Stop any URL fetches in progress. | 147 // Stop any URL fetches in progress. |
147 virtual void CancelRequest(); | 148 virtual void CancelRequest(); |
148 | 149 |
149 protected: | 150 protected: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 const std::string& oauth1_access_token_secret); | 231 const std::string& oauth1_access_token_secret); |
231 | 232 |
232 // Given parameters, create a OAuthWrapBridge request body. | 233 // Given parameters, create a OAuthWrapBridge request body. |
233 static std::string MakeOAuthWrapBridgeBody( | 234 static std::string MakeOAuthWrapBridgeBody( |
234 const std::string& oauth1_access_token, | 235 const std::string& oauth1_access_token, |
235 const std::string& oauth1_access_token_secret, | 236 const std::string& oauth1_access_token_secret, |
236 const std::string& wrap_token_duration, | 237 const std::string& wrap_token_duration, |
237 const std::string& oauth2_service_scope); | 238 const std::string& oauth2_service_scope); |
238 | 239 |
239 // Create a fetcher useable for making any Gaia OAuth request. | 240 // Create a fetcher useable for making any Gaia OAuth request. |
240 static content::URLFetcher* CreateGaiaFetcher( | 241 static net::URLFetcher* CreateGaiaFetcher( |
241 net::URLRequestContextGetter* getter, | 242 net::URLRequestContextGetter* getter, |
242 const GURL& gaia_gurl_, | 243 const GURL& gaia_gurl_, |
243 const std::string& body, | 244 const std::string& body, |
244 const std::string& headers, | 245 const std::string& headers, |
245 bool send_cookies, | 246 bool send_cookies, |
246 content::URLFetcherDelegate* delegate); | 247 net::URLFetcherDelegate* delegate); |
247 | 248 |
248 bool ShouldAutoFetch(RequestType fetch_step); | 249 bool ShouldAutoFetch(RequestType fetch_step); |
249 | 250 |
250 // These fields are common to GaiaOAuthFetcher, same every request | 251 // These fields are common to GaiaOAuthFetcher, same every request |
251 GaiaOAuthConsumer* const consumer_; | 252 GaiaOAuthConsumer* const consumer_; |
252 net::URLRequestContextGetter* const getter_; | 253 net::URLRequestContextGetter* const getter_; |
253 Profile* profile_; | 254 Profile* profile_; |
254 Browser* popup_; | 255 Browser* popup_; |
255 content::NotificationRegistrar registrar_; | 256 content::NotificationRegistrar registrar_; |
256 | 257 |
257 // While a fetch is going on: | 258 // While a fetch is going on: |
258 scoped_ptr<content::URLFetcher> fetcher_; | 259 scoped_ptr<net::URLFetcher> fetcher_; |
259 std::string request_body_; | 260 std::string request_body_; |
260 std::string request_headers_; | 261 std::string request_headers_; |
261 std::string service_scope_; | 262 std::string service_scope_; |
262 bool fetch_pending_; | 263 bool fetch_pending_; |
263 RequestType auto_fetch_limit_; | 264 RequestType auto_fetch_limit_; |
264 | 265 |
265 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthFetcher); | 266 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthFetcher); |
266 }; | 267 }; |
267 | 268 |
268 #endif // CHROME_BROWSER_NET_GAIA_GAIA_OAUTH_FETCHER_H_ | 269 #endif // CHROME_BROWSER_NET_GAIA_GAIA_OAUTH_FETCHER_H_ |
OLD | NEW |