Chromium Code Reviews| Index: components/safe_browsing/password_protection/password_protection_request.h |
| diff --git a/components/safe_browsing/password_protection/password_protection_request.h b/components/safe_browsing/password_protection/password_protection_request.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7d0f77c64181b0caccbc3055b7326a44b6e815e1 |
| --- /dev/null |
| +++ b/components/safe_browsing/password_protection/password_protection_request.h |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_ |
| +#define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "components/safe_browsing/password_protection/password_protection_service.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "net/url_request/url_request_status.h" |
| + |
| +class GURL; |
| + |
| +namespace safe_browsing { |
| + |
| +class PasswordProtectionRequest : public net::URLFetcherDelegate { |
| + public: |
| + // The outcome of the request. These values are used for UMA. |
| + // DO NOT CHANGE THE ORDERING OF THESE VALUES. |
| + enum RequestOutcome { |
| + UNKNOWN = 0, |
| + SUCCEEDED = 1, |
| + CANCELED = 2, |
| + TIMEDOUT = 3, |
| + MATCHED_WHITELIST = 4, |
| + RESPONSE_ALREADY_CACHED = 5, |
| + NO_EXTENDED_REPORTING = 6, |
| + INCOGNITO = 7, |
| + REQUEST_MALFORMED = 8, |
| + FETCH_FAILED = 9, |
| + RESPONSE_MALFORMED = 10, |
| + SERVICE_DESTROYED = 11, |
| + 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. :-)
|
| + }; |
| + |
| + PasswordProtectionRequest(const GURL& main_frame_url, |
| + LoginReputationClientRequest::TriggerType type, |
| + bool is_extended_reporting, |
| + bool is_incognito, |
| + base::WeakPtr<PasswordProtectionService> pps, |
| + int request_timeout_in_ms); |
| + |
| + ~PasswordProtectionRequest() override; |
| + |
| + base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() { |
| + return weakptr_factory_.GetWeakPtr(); |
| + } |
| + |
| + // Starts processing request by checking extended reporting and incognito |
| + // conditions. |
| + void Start(); |
| + |
| + // Cancels the current request. |timed_out| indicates if this cancellation is |
| + // due to timeout. This function will call Finish() to destroy |this|. |
| + void Cancel(bool timed_out); |
| + |
| + GURL main_frame_url() const { return main_frame_url_; } |
| + |
| + bool is_incognito() const { return is_incognito_; } |
| + |
| + // net::URLFetcherDelegate override. |
| + // Processes the received response. |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + private: |
| + // 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.
|
| + void StartTimeout(); |
| + |
| + // |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.
|
| + void Finish(RequestOutcome outcome, |
| + std::unique_ptr<LoginReputationClientResponse> response); |
| + |
| + void CheckWhitelistsOnUIThread(); |
| + |
| + // If |main_frame_url_| matches whitelist, call Finish() immediately; |
| + // otherwise call CheckCachedVerdicts(). |
| + void OnWhitelistCheckDone(bool match_whitelist); |
| + |
| + // Looks up cached verdicts. If verdict is already cached, call SendRequest(); |
| + // otherwise call Finish(). |
| + void CheckCachedVerdicts(); |
| + |
| + void SendRequest(); |
| + |
| + GURL main_frame_url_; |
| + LoginReputationClientRequest::TriggerType request_type_; |
| + 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.
|
| + bool is_incognito_; |
| + base::TimeTicks request_start_time_; |
| + base::TimeTicks timeout_start_time_; |
| + std::unique_ptr<net::URLFetcher> fetcher_; |
| + base::WeakPtr<PasswordProtectionService> password_protection_service_; |
| + int request_timeout_in_ms_; |
| + base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest); |
| +}; |
| + |
| +} // namespace safe_browsing |
| + |
| +#endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_ |