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

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

Issue 2817533004: Improve PasswordProtectionService and PasswordProtectionRequest (Closed)
Patch Set: address nparker's comments Created 3 years, 8 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
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 COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_
6 #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_ 6 #define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST _H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/task/cancelable_task_tracker.h"
10 #include "components/safe_browsing/password_protection/password_protection_servi ce.h" 11 #include "components/safe_browsing/password_protection/password_protection_servi ce.h"
12 #include "content/public/browser/browser_thread.h"
11 #include "net/url_request/url_fetcher.h" 13 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_fetcher_delegate.h" 14 #include "net/url_request/url_fetcher_delegate.h"
13 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
14 16
15 class GURL; 17 class GURL;
16 18
17 namespace safe_browsing { 19 namespace safe_browsing {
18 20
19 // A request for checking if an unfamiliar login form or a password reuse event 21 // A request for checking if an unfamiliar login form or a password reuse event
20 // is safe. PasswordProtectionRequest objects are owned by 22 // is safe. PasswordProtectionRequest objects are owned by
21 // PasswordProtectionService indicated by |password_protection_service_|. 23 // PasswordProtectionService indicated by |password_protection_service_|.
22 class PasswordProtectionRequest : public net::URLFetcherDelegate { 24 class PasswordProtectionRequest
25 : public base::RefCountedThreadSafe<PasswordProtectionRequest>,
26 public net::URLFetcherDelegate {
23 public: 27 public:
24 // The outcome of the request. These values are used for UMA. 28 // The outcome of the request. These values are used for UMA.
25 // DO NOT CHANGE THE ORDERING OF THESE VALUES. 29 // DO NOT CHANGE THE ORDERING OF THESE VALUES.
26 enum RequestOutcome { 30 enum RequestOutcome {
27 UNKNOWN = 0, 31 UNKNOWN = 0,
28 SUCCEEDED = 1, 32 SUCCEEDED = 1,
29 CANCELED = 2, 33 CANCELED = 2,
30 TIMEDOUT = 3, 34 TIMEDOUT = 3,
31 MATCHED_WHITELIST = 4, 35 MATCHED_WHITELIST = 4,
32 RESPONSE_ALREADY_CACHED = 5, 36 RESPONSE_ALREADY_CACHED = 5,
33 NO_EXTENDED_REPORTING = 6, 37 NO_EXTENDED_REPORTING = 6,
34 INCOGNITO = 7, 38 INCOGNITO = 7,
35 REQUEST_MALFORMED = 8, 39 REQUEST_MALFORMED = 8,
36 FETCH_FAILED = 9, 40 FETCH_FAILED = 9,
37 RESPONSE_MALFORMED = 10, 41 RESPONSE_MALFORMED = 10,
38 SERVICE_DESTROYED = 11, 42 SERVICE_DESTROYED = 11,
39 MAX_OUTCOME 43 MAX_OUTCOME
40 }; 44 };
41 45
42 PasswordProtectionRequest(const GURL& main_frame_url, 46 PasswordProtectionRequest(
43 LoginReputationClientRequest::TriggerType type, 47 const GURL& main_frame_url,
44 bool is_extended_reporting, 48 LoginReputationClientRequest::TriggerType type,
45 bool is_incognito, 49 std::unique_ptr<PasswordProtectionFrames> pending_password_frames,
46 base::WeakPtr<PasswordProtectionService> pps, 50 base::WeakPtr<PasswordProtectionService> pps,
47 int request_timeout_in_ms); 51 int request_timeout_in_ms);
48
49 ~PasswordProtectionRequest() override;
50 52
51 base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() { 53 base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
52 return weakptr_factory_.GetWeakPtr(); 54 return weakptr_factory_.GetWeakPtr();
53 } 55 }
54 56
55 // Starts processing request by checking extended reporting and incognito 57 // Starts processing request by checking extended reporting and incognito
56 // conditions. 58 // conditions.
57 void Start(); 59 void Start();
58 60
59 // Cancels the current request. |timed_out| indicates if this cancellation is 61 // Cancels the current request. |timed_out| indicates if this cancellation is
60 // due to timeout. This function will call Finish() to destroy |this|. 62 // due to timeout. This function will call Finish() to destroy |this|.
61 void Cancel(bool timed_out); 63 void Cancel(bool timed_out);
62 64
63 // net::URLFetcherDelegate override. 65 // net::URLFetcherDelegate override.
64 // Processes the received response. 66 // Processes the received response.
65 void OnURLFetchComplete(const net::URLFetcher* source) override; 67 void OnURLFetchComplete(const net::URLFetcher* source) override;
66 68
67 GURL main_frame_url() const { return main_frame_url_; } 69 GURL main_frame_url() const { return main_frame_url_; }
68 70
69 bool is_incognito() const { return is_incognito_; } 71 protected:
72 ~PasswordProtectionRequest() override;
70 73
71 private: 74 private:
75 friend class base::RefCountedThreadSafe<PasswordProtectionRequest>;
76
77 void CheckWhitelistOnUIThread();
78
72 // If |main_frame_url_| matches whitelist, call Finish() immediately; 79 // If |main_frame_url_| matches whitelist, call Finish() immediately;
73 // otherwise call CheckCachedVerdicts(). 80 // otherwise call CheckCachedVerdicts(). Called on UI thread.
74 void OnWhitelistCheckDone(bool match_whitelist); 81 // |match_whitelist| points to the boolean value set on IO thread by
lpz 2017/04/18 14:43:27 nit: further to Nathan's comment, can we explain m
Jialiu Lin 2017/04/18 20:38:04 Done.
82 // PasswordProtectionService::CheckCsdWhitelistOnIOThread.
83 void OnWhitelistCheckDone(const bool* match_whitelist);
75 84
76 // Looks up cached verdicts. If verdict is already cached, call SendRequest(); 85 // Looks up cached verdicts. If verdict is already cached, call SendRequest();
77 // otherwise call Finish(). 86 // otherwise call Finish().
78 void CheckCachedVerdicts(); 87 void CheckCachedVerdicts();
79 88
80 // Fill |request_proto_| with appropriate values. 89 // Fill |request_proto_| with appropriate values.
81 void FillRequestProto(); 90 void FillRequestProto();
82 91
83 // Initiates network request to Safe Browsing backend. 92 // Initiates network request to Safe Browsing backend.
84 void SendRequest(); 93 void SendRequest();
85 94
86 // Start a timer to cancel the request if it takes too long. 95 // Start a timer to cancel the request if it takes too long.
87 void StartTimeout(); 96 void StartTimeout();
88 97
89 // |this| will be destroyed after calling this function. 98 // |this| will be destroyed after calling this function.
90 void Finish(RequestOutcome outcome, 99 void Finish(RequestOutcome outcome,
91 std::unique_ptr<LoginReputationClientResponse> response); 100 std::unique_ptr<LoginReputationClientResponse> response);
92 101
93 void CheckWhitelistsOnUIThread();
94
95 // Main frame URL of the login form. 102 // Main frame URL of the login form.
96 GURL main_frame_url_; 103 GURL main_frame_url_;
97 104
98 // If this request is for unfamiliar login page or for a password reuse event. 105 // If this request is for unfamiliar login page or for a password reuse event.
99 const LoginReputationClientRequest::TriggerType request_type_; 106 const LoginReputationClientRequest::TriggerType request_type_;
100 107
101 // If user is opted-in Safe Browsing Extended Reporting. 108 std::unique_ptr<PasswordProtectionFrames> pending_password_frames_;
102 const bool is_extended_reporting_;
103
104 // If current session is in incognito mode.
105 const bool is_incognito_;
106 109
107 // When request is sent. 110 // When request is sent.
108 base::TimeTicks request_start_time_; 111 base::TimeTicks request_start_time_;
109 112
110 // URLFetcher instance for sending request and receiving response. 113 // URLFetcher instance for sending request and receiving response.
111 std::unique_ptr<net::URLFetcher> fetcher_; 114 std::unique_ptr<net::URLFetcher> fetcher_;
112 115
113 // The PasswordProtectionService instance owns |this|. 116 // The PasswordProtectionService instance owns |this|.
117 // Can only be accessed on UI thread.
114 base::WeakPtr<PasswordProtectionService> password_protection_service_; 118 base::WeakPtr<PasswordProtectionService> password_protection_service_;
115 119
120 // Safe Browsing database manager used to look up CSD whitelist.
121 // Can only be accessed on IO thread.
122 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
123
116 // If we haven't receive response after this period of time, we cancel this 124 // If we haven't receive response after this period of time, we cancel this
117 // request. 125 // request.
118 const int request_timeout_in_ms_; 126 const int request_timeout_in_ms_;
119 127
120 std::unique_ptr<LoginReputationClientRequest> request_proto_; 128 std::unique_ptr<LoginReputationClientRequest> request_proto_;
121 129
130 // Needed for canceling tasks posted to different threads.
131 base::CancelableTaskTracker tracker_;
132
122 base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_; 133 base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_;
123 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest); 134 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
124 }; 135 };
125 136
126 } // namespace safe_browsing 137 } // namespace safe_browsing
127 138
128 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQU EST_H_ 139 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQU EST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698