Home | History | Annotate | Download | only in signin
      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 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/signin/oauth2_token_service.h"
     10 #include "google_apis/gaia/gaia_auth_consumer.h"
     11 
     12 // Allow to retrieves an uber-auth token for the user. This class uses the
     13 // |OAuth2TokenService| and considers that the user is already logged in. It
     14 // will use the OAuth2 access token to generate the uber-auth token.
     15 //
     16 // This class should be used on a single thread, but it can be whichever thread
     17 // that you like.
     18 //
     19 // This class can handle one request at a time.
     20 
     21 class GaiaAuthFetcher;
     22 class GoogleServiceAuthError;
     23 class Profile;
     24 
     25 // Callback for the |UbertokenFetcher| class.
     26 class UbertokenConsumer {
     27  public:
     28   UbertokenConsumer() {}
     29   virtual ~UbertokenConsumer() {}
     30   virtual void OnUbertokenSuccess(const std::string& token) {}
     31   virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) {}
     32 };
     33 
     34 // Allows to retrieve an uber-auth token.
     35 class UbertokenFetcher : public GaiaAuthConsumer,
     36                          public OAuth2TokenService::Consumer {
     37  public:
     38   UbertokenFetcher(Profile* profile, UbertokenConsumer* consumer);
     39   virtual ~UbertokenFetcher();
     40 
     41   // Start fetching the token.
     42   void StartFetchingToken();
     43 
     44   // Overriden from GaiaAuthConsumer
     45   virtual void OnUberAuthTokenSuccess(const std::string& token) OVERRIDE;
     46   virtual void OnUberAuthTokenFailure(
     47       const GoogleServiceAuthError& error) OVERRIDE;
     48 
     49   // Overriden from OAuth2TokenService::Consumer:
     50   virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
     51                                  const std::string& access_token,
     52                                  const base::Time& expiration_time) OVERRIDE;
     53   virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
     54                                  const GoogleServiceAuthError& error) OVERRIDE;
     55 
     56  private:
     57   Profile* profile_;
     58   UbertokenConsumer* consumer_;
     59   scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_;
     60   scoped_ptr<OAuth2TokenService::Request> access_token_request_;
     61 
     62   DISALLOW_COPY_AND_ASSIGN(UbertokenFetcher);
     63 };
     64 
     65 #endif  // CHROME_BROWSER_SIGNIN_UBERTOKEN_FETCHER_H_
     66