Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_DICE_RESPONSE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ | 6 #define CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 10 | 11 |
| 11 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 12 #include "google_apis/gaia/gaia_auth_consumer.h" | 13 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 13 | 14 |
| 14 namespace signin { | 15 namespace signin { |
| 15 struct DiceResponseParams; | 16 struct DiceResponseParams; |
| 16 } | 17 } |
| 17 | 18 |
| 18 class AccountTrackerService; | 19 class AccountTrackerService; |
| 19 class GaiaAuthFetcher; | 20 class GaiaAuthFetcher; |
| 21 class GoogleServiceAuthError; | |
| 20 class SigninClient; | 22 class SigninClient; |
| 21 class ProfileOAuth2TokenService; | 23 class ProfileOAuth2TokenService; |
| 22 class Profile; | 24 class Profile; |
| 23 | 25 |
| 24 // Processes the Dice responses from Gaia. | 26 // Processes the Dice responses from Gaia. |
| 25 class DiceResponseHandler : public GaiaAuthConsumer, public KeyedService { | 27 class DiceResponseHandler : public KeyedService { |
| 26 public: | 28 public: |
| 27 // Returns the DiceResponseHandler associated with this profile. | 29 // Returns the DiceResponseHandler associated with this profile. |
| 28 // May return nullptr if there is none (e.g. in incognito). | 30 // May return nullptr if there is none (e.g. in incognito). |
| 29 static DiceResponseHandler* GetForProfile(Profile* profile); | 31 static DiceResponseHandler* GetForProfile(Profile* profile); |
| 30 | 32 |
| 31 DiceResponseHandler(SigninClient* signin_client, | 33 DiceResponseHandler(SigninClient* signin_client, |
| 32 ProfileOAuth2TokenService* profile_oauth2_token_service, | 34 ProfileOAuth2TokenService* profile_oauth2_token_service, |
| 33 AccountTrackerService* account_tracker_service); | 35 AccountTrackerService* account_tracker_service); |
| 34 ~DiceResponseHandler() override; | 36 ~DiceResponseHandler() override; |
| 35 | 37 |
| 36 // Must be called when receiving a Dice response header. | 38 // Must be called when receiving a Dice response header. |
| 37 void ProcessDiceHeader(const signin::DiceResponseParams& dice_params); | 39 void ProcessDiceHeader(const signin::DiceResponseParams& dice_params); |
| 38 | 40 |
| 39 private: | 41 private: |
| 42 // Helper class to fetch a refresh token from an authorization code. | |
| 43 class DiceTokenFetcher : public GaiaAuthConsumer { | |
| 44 public: | |
| 45 DiceTokenFetcher(const std::string& gaia_id, | |
| 46 const std::string& email, | |
| 47 const std::string& authorization_code, | |
| 48 SigninClient* signin_client, | |
| 49 DiceResponseHandler* dice_response_handler); | |
| 50 ~DiceTokenFetcher() override; | |
| 51 | |
| 52 const std::string& gaia_id() const { return gaia_id_; } | |
| 53 const std::string& email() const { return email_; } | |
| 54 | |
| 55 private: | |
| 56 // GaiaAuthConsumer implementation: | |
| 57 void OnClientOAuthSuccess( | |
| 58 const GaiaAuthConsumer::ClientOAuthResult& result) override; | |
| 59 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override; | |
| 60 | |
| 61 std::string gaia_id_; | |
| 62 std::string email_; | |
| 63 DiceResponseHandler* dice_response_handler_; | |
| 64 std::unique_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
|
msarda
2017/06/22 09:51:31
Add DISALLOW_COPY_AND_ASSIGN(DiceTokenFetcher);
| |
| 65 }; | |
| 66 | |
| 67 // Deletes the token fetcher. | |
| 68 void DeleteTokenFetcher(DiceTokenFetcher* token_fetcher); | |
| 69 | |
| 40 // Process the Dice signin action. | 70 // Process the Dice signin action. |
| 41 void ProcessDiceSigninHeader(const std::string& gaia_id, | 71 void ProcessDiceSigninHeader(const std::string& gaia_id, |
| 42 const std::string& email, | 72 const std::string& email, |
| 43 const std::string& authorization_code); | 73 const std::string& authorization_code); |
| 44 | 74 |
| 45 // GaiaAuthConsumer implementation: | 75 // Called after token exchange on SIGNIN. |
|
msarda
2017/06/22 09:51:32
I do not understand what SIGNIN means here. Maybe
droger
2017/06/22 11:54:20
I meant DiceAction::SIGNIN. Clarified comment.
| |
| 46 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; | 76 void OnTokenExchangeSuccess( |
| 47 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override; | 77 DiceTokenFetcher* token_fetcher, |
| 78 const std::string& gaia_id, | |
| 79 const std::string& email, | |
| 80 const GaiaAuthConsumer::ClientOAuthResult& result); | |
| 81 void OnTokenExchangeFailure(DiceTokenFetcher* token_fetcher, | |
| 82 const GoogleServiceAuthError& error); | |
| 48 | 83 |
| 49 std::unique_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
| 50 std::string gaia_id_; | |
| 51 std::string email_; | |
| 52 SigninClient* signin_client_; | 84 SigninClient* signin_client_; |
| 53 ProfileOAuth2TokenService* profile_oauth2_token_service_; | 85 ProfileOAuth2TokenService* profile_oauth2_token_service_; |
| 54 AccountTrackerService* account_tracker_service_; | 86 AccountTrackerService* account_tracker_service_; |
| 87 std::vector<std::unique_ptr<DiceTokenFetcher>> token_fetchers_; | |
|
msarda
2017/06/22 09:51:32
Add Add DISALLOW_COPY_AND_ASSIGN( DiceResponseHand
droger
2017/06/22 11:54:20
Done.
| |
| 55 }; | 88 }; |
| 56 | 89 |
| 57 #endif // CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ | 90 #endif // CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ |
| OLD | NEW |