Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Side by Side Diff: chrome/browser/signin/dice_response_handler.h

Issue 2951263002: [Signin] Add timeout to Dice token exchange requests (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/signin/dice_response_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <vector>
11 11
12 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/keyed_service/core/keyed_service.h"
14 #include "google_apis/gaia/gaia_auth_consumer.h" 15 #include "google_apis/gaia/gaia_auth_consumer.h"
15 16
16 namespace signin { 17 namespace signin {
17 struct DiceResponseParams; 18 struct DiceResponseParams;
18 } 19 }
19 20
20 class AccountTrackerService; 21 class AccountTrackerService;
21 class GaiaAuthFetcher; 22 class GaiaAuthFetcher;
22 class GoogleServiceAuthError; 23 class GoogleServiceAuthError;
23 class SigninClient; 24 class SigninClient;
24 class ProfileOAuth2TokenService; 25 class ProfileOAuth2TokenService;
25 class Profile; 26 class Profile;
26 27
28 // Exposed for testing.
29 extern const int kDiceTokenFetchTimeoutSeconds;
30
27 // Processes the Dice responses from Gaia. 31 // Processes the Dice responses from Gaia.
28 class DiceResponseHandler : public KeyedService { 32 class DiceResponseHandler : public KeyedService {
29 public: 33 public:
30 // Returns the DiceResponseHandler associated with this profile. 34 // Returns the DiceResponseHandler associated with this profile.
31 // May return nullptr if there is none (e.g. in incognito). 35 // May return nullptr if there is none (e.g. in incognito).
32 static DiceResponseHandler* GetForProfile(Profile* profile); 36 static DiceResponseHandler* GetForProfile(Profile* profile);
33 37
34 DiceResponseHandler(SigninClient* signin_client, 38 DiceResponseHandler(SigninClient* signin_client,
35 ProfileOAuth2TokenService* profile_oauth2_token_service, 39 ProfileOAuth2TokenService* profile_oauth2_token_service,
36 AccountTrackerService* account_tracker_service); 40 AccountTrackerService* account_tracker_service);
37 ~DiceResponseHandler() override; 41 ~DiceResponseHandler() override;
38 42
39 // Must be called when receiving a Dice response header. 43 // Must be called when receiving a Dice response header.
40 void ProcessDiceHeader(const signin::DiceResponseParams& dice_params); 44 void ProcessDiceHeader(const signin::DiceResponseParams& dice_params);
41 45
46 // Returns the number of pending DiceTokenFetchers. Exposed for testing.
47 size_t GetPendingDiceTokenFetchersCountForTesting() const;
48
42 private: 49 private:
43 // Helper class to fetch a refresh token from an authorization code. 50 // Helper class to fetch a refresh token from an authorization code.
44 class DiceTokenFetcher : public GaiaAuthConsumer { 51 class DiceTokenFetcher : public GaiaAuthConsumer {
45 public: 52 public:
46 DiceTokenFetcher(const std::string& gaia_id, 53 DiceTokenFetcher(const std::string& gaia_id,
47 const std::string& email, 54 const std::string& email,
48 const std::string& authorization_code, 55 const std::string& authorization_code,
49 SigninClient* signin_client, 56 SigninClient* signin_client,
50 DiceResponseHandler* dice_response_handler); 57 DiceResponseHandler* dice_response_handler);
51 ~DiceTokenFetcher() override; 58 ~DiceTokenFetcher() override;
52 59
53 const std::string& gaia_id() const { return gaia_id_; } 60 const std::string& gaia_id() const { return gaia_id_; }
54 const std::string& email() const { return email_; } 61 const std::string& email() const { return email_; }
55 const std::string& authorization_code() const { 62 const std::string& authorization_code() const {
56 return authorization_code_; 63 return authorization_code_;
57 } 64 }
58 65
59 private: 66 private:
67 // Called by |timeout_closure_| when the request times out.
68 void OnTimeout();
69
60 // GaiaAuthConsumer implementation: 70 // GaiaAuthConsumer implementation:
61 void OnClientOAuthSuccess( 71 void OnClientOAuthSuccess(
62 const GaiaAuthConsumer::ClientOAuthResult& result) override; 72 const GaiaAuthConsumer::ClientOAuthResult& result) override;
63 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override; 73 void OnClientOAuthFailure(const GoogleServiceAuthError& error) override;
64 74
65 std::string gaia_id_; 75 std::string gaia_id_;
66 std::string email_; 76 std::string email_;
67 std::string authorization_code_; 77 std::string authorization_code_;
68 DiceResponseHandler* dice_response_handler_; 78 DiceResponseHandler* dice_response_handler_;
79 base::CancelableClosure timeout_closure_;
69 std::unique_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; 80 std::unique_ptr<GaiaAuthFetcher> gaia_auth_fetcher_;
70 81
71 DISALLOW_COPY_AND_ASSIGN(DiceTokenFetcher); 82 DISALLOW_COPY_AND_ASSIGN(DiceTokenFetcher);
72 }; 83 };
73 84
74 // Deletes the token fetcher. 85 // Deletes the token fetcher.
75 void DeleteTokenFetcher(DiceTokenFetcher* token_fetcher); 86 void DeleteTokenFetcher(DiceTokenFetcher* token_fetcher);
76 87
77 // Process the Dice signin action. 88 // Process the Dice signin action.
78 void ProcessDiceSigninHeader(const std::string& gaia_id, 89 void ProcessDiceSigninHeader(const std::string& gaia_id,
(...skipping 12 matching lines...) Expand all
91 102
92 SigninClient* signin_client_; 103 SigninClient* signin_client_;
93 ProfileOAuth2TokenService* token_service_; 104 ProfileOAuth2TokenService* token_service_;
94 AccountTrackerService* account_tracker_service_; 105 AccountTrackerService* account_tracker_service_;
95 std::vector<std::unique_ptr<DiceTokenFetcher>> token_fetchers_; 106 std::vector<std::unique_ptr<DiceTokenFetcher>> token_fetchers_;
96 107
97 DISALLOW_COPY_AND_ASSIGN(DiceResponseHandler); 108 DISALLOW_COPY_AND_ASSIGN(DiceResponseHandler);
98 }; 109 };
99 110
100 #endif // CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_ 111 #endif // CHROME_BROWSER_SIGNIN_DICE_RESPONSE_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/signin/dice_response_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698