OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SIGNIN_UBERTOKEN_FETCHER_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_UBERTOKEN_FETCHER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
| 11 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 12 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
| 13 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/notification_source.h" |
| 17 |
| 18 // Allow to retrieves an uber-auth token for the user. This class uses the |
| 19 // |TokenService| and considers that the user is already logged in. It will then |
| 20 // retrieve the OAuth2 refresh token, use it to generate an OAuth2 access token |
| 21 // and finally use this access token to generate the uber-auth token. |
| 22 // |
| 23 // This class should be used on a single thread, but it can be whichever thread |
| 24 // that you like. |
| 25 // |
| 26 // This class can handle one request at a time. |
| 27 |
| 28 class GoogleServiceAuthError; |
| 29 class Profile; |
| 30 |
| 31 // Callback for the |UbertokenFetcher| class. |
| 32 class UbertokenConsumer { |
| 33 public: |
| 34 UbertokenConsumer() {} |
| 35 virtual ~UbertokenConsumer() {} |
| 36 virtual void OnUbertokenSuccess(const std::string& token) {} |
| 37 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) {} |
| 38 }; |
| 39 |
| 40 // Allows to retrieve an uber-auth token. |
| 41 class UbertokenFetcher : public content::NotificationObserver, |
| 42 public gaia::GaiaOAuthClient::Delegate, |
| 43 public GaiaAuthConsumer { |
| 44 public: |
| 45 UbertokenFetcher(Profile* profile, UbertokenConsumer* consumer); |
| 46 virtual ~UbertokenFetcher(); |
| 47 |
| 48 // Start fetching the token. |
| 49 void StartFetchingToken(); |
| 50 |
| 51 // Overriden from gaia::GaiaOAuthClient::Delegate: |
| 52 virtual void OnGetTokensResponse(const std::string& refresh_token, |
| 53 const std::string& access_token, |
| 54 int expires_in_seconds) OVERRIDE; |
| 55 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 56 int expires_in_seconds) OVERRIDE; |
| 57 virtual void OnOAuthError() OVERRIDE; |
| 58 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 59 |
| 60 // Overriden from GaiaAuthConsumer |
| 61 virtual void OnUberAuthTokenSuccess(const std::string& token) OVERRIDE; |
| 62 virtual void OnUberAuthTokenFailure( |
| 63 const GoogleServiceAuthError& error) OVERRIDE; |
| 64 |
| 65 // Overriden from content::NotificationObserver: |
| 66 virtual void Observe(int type, |
| 67 const content::NotificationSource& source, |
| 68 const content::NotificationDetails& details) OVERRIDE; |
| 69 |
| 70 private: |
| 71 void StartFetchingUbertoken(); |
| 72 |
| 73 Profile* profile_; |
| 74 UbertokenConsumer* consumer_; |
| 75 content::NotificationRegistrar registrar_; |
| 76 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; |
| 77 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(UbertokenFetcher); |
| 80 }; |
| 81 |
| 82 #endif // CHROME_BROWSER_SIGNIN_UBERTOKEN_FETCHER_H_ |
OLD | NEW |