Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_ | |
| 6 #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "components/safe_browsing/password_protection/password_protection_servi ce.h" | |
| 11 #include "net/url_request/url_fetcher.h" | |
| 12 #include "net/url_request/url_fetcher_delegate.h" | |
| 13 #include "net/url_request/url_request_status.h" | |
| 14 | |
| 15 class GURL; | |
| 16 | |
| 17 namespace safe_browsing { | |
| 18 | |
| 19 class PasswordProtectionRequest : public net::URLFetcherDelegate { | |
| 20 public: | |
| 21 // The outcome of the request. These values are used for UMA. | |
| 22 // DO NOT CHANGE THE ORDERING OF THESE VALUES. | |
| 23 enum RequestOutcome { | |
| 24 UNKNOWN = 0, | |
| 25 SUCCEEDED = 1, | |
| 26 CANCELED = 2, | |
| 27 TIMEDOUT = 3, | |
| 28 MATCHED_WHITELIST = 4, | |
| 29 RESPONSE_ALREADY_CACHED = 5, | |
| 30 NO_EXTENDED_REPORTING = 6, | |
| 31 INCOGNITO = 7, | |
| 32 REQUEST_MALFORMED = 8, | |
| 33 FETCH_FAILED = 9, | |
| 34 RESPONSE_MALFORMED = 10, | |
| 35 SERVICE_DESTROYED = 11, | |
| 36 MAX_OUTCOME | |
|
Nathan Parker
2017/03/24 00:41:50
Don't forget histograms.xml
Jialiu Lin
2017/03/24 01:42:43
histograms enums are always numbered. :-)
| |
| 37 }; | |
| 38 | |
| 39 PasswordProtectionRequest(const GURL& main_frame_url, | |
| 40 LoginReputationClientRequest::TriggerType type, | |
| 41 bool is_extended_reporting, | |
| 42 bool is_incognito, | |
| 43 base::WeakPtr<PasswordProtectionService> pps, | |
| 44 int request_timeout_in_ms); | |
| 45 | |
| 46 ~PasswordProtectionRequest() override; | |
| 47 | |
| 48 base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() { | |
| 49 return weakptr_factory_.GetWeakPtr(); | |
| 50 } | |
| 51 | |
| 52 // Starts processing request by checking extended reporting and incognito | |
| 53 // conditions. | |
| 54 void Start(); | |
| 55 | |
| 56 // Cancels the current request. |timed_out| indicates if this cancellation is | |
| 57 // due to timeout. This function will call Finish() to destroy |this|. | |
| 58 void Cancel(bool timed_out); | |
| 59 | |
| 60 GURL main_frame_url() const { return main_frame_url_; } | |
| 61 | |
| 62 bool is_incognito() const { return is_incognito_; } | |
| 63 | |
| 64 // net::URLFetcherDelegate override. | |
| 65 // Processes the received response. | |
| 66 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 67 | |
| 68 private: | |
| 69 // Start a timeout to cancel the request if it takes too long. | |
|
Nathan Parker
2017/03/24 00:41:50
nit: s/timeout/timer
Jialiu Lin
2017/03/24 01:42:43
Done.
| |
| 70 void StartTimeout(); | |
| 71 | |
| 72 // |this| will be gone after calling this function. | |
|
Nathan Parker
2017/03/24 00:41:50
s/gone/destroyed
Jialiu Lin
2017/03/24 01:42:43
Done.
| |
| 73 void Finish(RequestOutcome outcome, | |
| 74 std::unique_ptr<LoginReputationClientResponse> response); | |
| 75 | |
| 76 void CheckWhitelistsOnUIThread(); | |
| 77 | |
| 78 // If |main_frame_url_| matches whitelist, call Finish() immediately; | |
| 79 // otherwise call CheckCachedVerdicts(). | |
| 80 void OnWhitelistCheckDone(bool match_whitelist); | |
| 81 | |
| 82 // Looks up cached verdicts. If verdict is already cached, call SendRequest(); | |
| 83 // otherwise call Finish(). | |
| 84 void CheckCachedVerdicts(); | |
| 85 | |
| 86 void SendRequest(); | |
| 87 | |
| 88 GURL main_frame_url_; | |
| 89 LoginReputationClientRequest::TriggerType request_type_; | |
| 90 bool is_extended_reporting_; | |
|
Nathan Parker
2017/03/24 00:41:50
Can some of these be const?
Jialiu Lin
2017/03/24 01:42:43
Oh yes! Done.
| |
| 91 bool is_incognito_; | |
| 92 base::TimeTicks request_start_time_; | |
| 93 base::TimeTicks timeout_start_time_; | |
| 94 std::unique_ptr<net::URLFetcher> fetcher_; | |
| 95 base::WeakPtr<PasswordProtectionService> password_protection_service_; | |
| 96 int request_timeout_in_ms_; | |
| 97 base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_; | |
| 98 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest); | |
| 99 }; | |
| 100 | |
| 101 } // namespace safe_browsing | |
| 102 | |
| 103 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQU EST_H_ | |
| OLD | NEW |