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

Side by Side Diff: components/safe_browsing/password_protection/password_protection_request.h

Issue 2773483003: Create PasswordProtectionRequest to handle password pings (Closed)
Patch Set: Address lpz's comments Created 3 years, 9 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
OLDNEW
(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 // A request for checking if an unfamiliar login form or a password reuse event
20 // is safe. PasswordProtectionRequest objects are owned by
21 // PasswordProtectionService indicated by |password_protection_service_|.
22 class PasswordProtectionRequest : public net::URLFetcherDelegate {
23 public:
24 // The outcome of the request. These values are used for UMA.
25 // DO NOT CHANGE THE ORDERING OF THESE VALUES.
26 enum RequestOutcome {
27 UNKNOWN = 0,
28 SUCCEEDED = 1,
29 CANCELED = 2,
30 TIMEDOUT = 3,
31 MATCHED_WHITELIST = 4,
32 RESPONSE_ALREADY_CACHED = 5,
33 NO_EXTENDED_REPORTING = 6,
34 INCOGNITO = 7,
35 REQUEST_MALFORMED = 8,
36 FETCH_FAILED = 9,
37 RESPONSE_MALFORMED = 10,
38 SERVICE_DESTROYED = 11,
39 MAX_OUTCOME
40 };
41
42 PasswordProtectionRequest(const GURL& main_frame_url,
43 LoginReputationClientRequest::TriggerType type,
44 bool is_extended_reporting,
45 bool is_incognito,
46 base::WeakPtr<PasswordProtectionService> pps,
47 int request_timeout_in_ms);
48
49 ~PasswordProtectionRequest() override;
50
51 base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
52 return weakptr_factory_.GetWeakPtr();
53 }
54
55 // Starts processing request by checking extended reporting and incognito
56 // conditions.
57 void Start();
58
59 // Cancels the current request. |timed_out| indicates if this cancellation is
60 // due to timeout. This function will call Finish() to destroy |this|.
61 void Cancel(bool timed_out);
62
63 // net::URLFetcherDelegate override.
64 // Processes the received response.
65 void OnURLFetchComplete(const net::URLFetcher* source) override;
66
67 GURL main_frame_url() const { return main_frame_url_; }
68
69 bool is_incognito() const { return is_incognito_; }
70
71 private:
72 // If |main_frame_url_| matches whitelist, call Finish() immediately;
73 // otherwise call CheckCachedVerdicts().
74 void OnWhitelistCheckDone(bool match_whitelist);
75
76 // Looks up cached verdicts. If verdict is already cached, call SendRequest();
77 // otherwise call Finish().
78 void CheckCachedVerdicts();
79
80 // Initiates network request to Safe Browsing backend.
81 void SendRequest();
82
83 // Start a timer to cancel the request if it takes too long.
84 void StartTimeout();
85
86 // |this| will be destroyed after calling this function.
87 void Finish(RequestOutcome outcome,
88 std::unique_ptr<LoginReputationClientResponse> response);
89
90 void CheckWhitelistsOnUIThread();
91
92 // Main frame URL of the login form.
93 GURL main_frame_url_;
94
95 // If this request is for unfamiliar login page or for a password reuse event.
96 const LoginReputationClientRequest::TriggerType request_type_;
97
98 // If user is opted-in Safe Browsing Extended Reporting.
99 const bool is_extended_reporting_;
100
101 // If current session is in incognito mode.
102 const bool is_incognito_;
103
104 // When request is sent.
105 base::TimeTicks request_start_time_;
106
107 // URLFetcher instance for sending request and receiving response.
108 std::unique_ptr<net::URLFetcher> fetcher_;
109
110 // The PasswordProtectionService instance owns |this|.
111 base::WeakPtr<PasswordProtectionService> password_protection_service_;
112
113 // If we haven't receive response after this period of time, we cancel this
114 // request.
115 const int request_timeout_in_ms_;
116
117 base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_;
118 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
119 };
120
121 } // namespace safe_browsing
122
123 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQU EST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698