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