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

Unified Diff: components/safe_browsing/password_protection/password_protection_request.h

Issue 2817533004: Improve PasswordProtectionService and PasswordProtectionRequest (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
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
index 52be0c11eb444afd7f49c03d47cda3df0ca10d26..e6f5a32982e91de4e16d44b98de0923ccf3752f4 100644
--- a/components/safe_browsing/password_protection/password_protection_request.h
+++ b/components/safe_browsing/password_protection/password_protection_request.h
@@ -7,7 +7,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/task/cancelable_task_tracker.h"
#include "components/safe_browsing/password_protection/password_protection_service.h"
+#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_status.h"
@@ -19,7 +21,9 @@ namespace safe_browsing {
// A request for checking if an unfamiliar login form or a password reuse event
// is safe. PasswordProtectionRequest objects are owned by
// PasswordProtectionService indicated by |password_protection_service_|.
-class PasswordProtectionRequest : public net::URLFetcherDelegate {
+class PasswordProtectionRequest
+ : public base::RefCountedThreadSafe<PasswordProtectionRequest>,
+ public net::URLFetcherDelegate {
public:
// The outcome of the request. These values are used for UMA.
// DO NOT CHANGE THE ORDERING OF THESE VALUES.
@@ -39,14 +43,13 @@ class PasswordProtectionRequest : public net::URLFetcherDelegate {
MAX_OUTCOME
};
- 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;
+ PasswordProtectionRequest(
+ const GURL& main_frame_url,
+ LoginReputationClientRequest::TriggerType type,
+ std::unique_ptr<PasswordProtectionFrames> pending_password_frames,
+ base::WeakPtr<PasswordProtectionService> pps,
+ scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
+ int request_timeout_in_ms);
base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
return weakptr_factory_.GetWeakPtr();
@@ -66,12 +69,17 @@ class PasswordProtectionRequest : public net::URLFetcherDelegate {
GURL main_frame_url() const { return main_frame_url_; }
- bool is_incognito() const { return is_incognito_; }
+ protected:
+ ~PasswordProtectionRequest() override;
private:
+ friend class base::RefCountedThreadSafe<PasswordProtectionRequest>;
+
+ void CheckWhitelistOnUIThread();
+
// If |main_frame_url_| matches whitelist, call Finish() immediately;
// otherwise call CheckCachedVerdicts().
Nathan Parker 2017/04/17 20:28:02 Comment on why this is a ptr. Does null mean some
Jialiu Lin 2017/04/18 00:58:26 Done.
- void OnWhitelistCheckDone(bool match_whitelist);
+ void OnWhitelistCheckDone(const bool* match_whitelist);
// Looks up cached verdicts. If verdict is already cached, call SendRequest();
// otherwise call Finish().
@@ -90,19 +98,13 @@ class PasswordProtectionRequest : public net::URLFetcherDelegate {
void Finish(RequestOutcome outcome,
std::unique_ptr<LoginReputationClientResponse> response);
- void CheckWhitelistsOnUIThread();
-
// Main frame URL of the login form.
GURL main_frame_url_;
// If this request is for unfamiliar login page or for a password reuse event.
const LoginReputationClientRequest::TriggerType request_type_;
- // If user is opted-in Safe Browsing Extended Reporting.
- const bool is_extended_reporting_;
-
- // If current session is in incognito mode.
- const bool is_incognito_;
+ std::unique_ptr<PasswordProtectionFrames> pending_password_frames_;
// When request is sent.
base::TimeTicks request_start_time_;
@@ -111,14 +113,22 @@ class PasswordProtectionRequest : public net::URLFetcherDelegate {
std::unique_ptr<net::URLFetcher> fetcher_;
// The PasswordProtectionService instance owns |this|.
+ // Can only be accessed on UI thread.
base::WeakPtr<PasswordProtectionService> password_protection_service_;
+ // Safe Browsing database manager used to look up CSD whitelist.
+ // Can only be accessed on IO thread.
+ scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
+
// If we haven't receive response after this period of time, we cancel this
// request.
const int request_timeout_in_ms_;
std::unique_ptr<LoginReputationClientRequest> request_proto_;
+ // Needed for canceling tasks posted to different threads.
+ base::CancelableTaskTracker tracker_;
+
base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
};

Powered by Google App Engine
This is Rietveld 408576698