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

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

Issue 2773483003: Create PasswordProtectionRequest to handle password pings (Closed)
Patch Set: Add one more unittest 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 class PasswordProtectionRequest : public net::URLFetcherDelegate {
lpz 2017/03/24 15:40:48 add class comments nit: and maybe doc the rest of
Jialiu Lin 2017/03/24 18:10:18 Done.
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
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 timer to cancel the request if it takes too long.
70 void StartTimeout();
71
72 // |this| will be destroyed after calling this function.
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 const LoginReputationClientRequest::TriggerType request_type_;
90 const bool is_extended_reporting_;
91 const bool is_incognito_;
92 base::TimeTicks request_start_time_;
93 std::unique_ptr<net::URLFetcher> fetcher_;
94 base::WeakPtr<PasswordProtectionService> password_protection_service_;
95 const int request_timeout_in_ms_;
96 base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_;
97 DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
98 };
99
100 } // namespace safe_browsing
101
102 #endif // COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQU EST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698