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

Unified Diff: components/safe_browsing/password_protection/password_protection_service.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 side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing/password_protection/password_protection_service.h
diff --git a/components/safe_browsing/password_protection/password_protection_service.h b/components/safe_browsing/password_protection/password_protection_service.h
index 351c5ef09cb8783168db27c77d22ff4a73e51f1c..92db7622e495e85e618099a060c38683f286aafc 100644
--- a/components/safe_browsing/password_protection/password_protection_service.h
+++ b/components/safe_browsing/password_protection/password_protection_service.h
@@ -5,6 +5,9 @@
#ifndef COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE_H_
#define COMPONENTS_SAFE_BROWSING_PASSWORD_PROTECTION_PASSWORD_PROTECTION_SERVICE_H_
+#include <unordered_set>
+
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
@@ -13,6 +16,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/safe_browsing/csd.pb.h"
+#include "net/url_request/url_request_context_getter.h"
namespace history {
class HistoryService;
@@ -23,11 +27,15 @@ class GURL;
namespace safe_browsing {
class SafeBrowsingDatabaseManager;
+class PasswordProtectionRequest;
class PasswordProtectionService : history::HistoryServiceObserver {
public:
- explicit PasswordProtectionService(
- const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager);
+ using CheckCsdWhitelistCallback = base::Callback<void(bool)>;
+
+ PasswordProtectionService(
+ const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter);
~PasswordProtectionService() override;
@@ -35,16 +43,20 @@ class PasswordProtectionService : history::HistoryServiceObserver {
// Currently called by PasswordReuseDetectionManager on UI thread.
void RecordPasswordReuse(const GURL& url);
+ void CheckCsdWhitelistOnIOThread(const GURL& url,
+ const CheckCsdWhitelistCallback& callback);
+
base::WeakPtr<PasswordProtectionService> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
- // Looks up |settings|, and returns the verdict of |url|. Can be called on any
- // thread. If verdict is not available or is expired, return
- // VERDICT_TYPE_UNSPECIFIED.
+ // Looks up |settings| to find the cached verdict response. If verdict is not
+ // available or is expired, return VERDICT_TYPE_UNSPECIFIED. Can be called on
+ // any thread.
LoginReputationClientResponse::VerdictType GetCachedVerdict(
const HostContentSettingsMap* settings,
- const GURL& url);
+ const GURL& url,
+ LoginReputationClientResponse* out_response);
// Stores |verdict| in |settings| based on |url|, |verdict| and
// |receive_time|.
@@ -53,8 +65,41 @@ class PasswordProtectionService : history::HistoryServiceObserver {
const base::Time& receive_time,
HostContentSettingsMap* settings);
+ // Creates an instance of PasswordProtectionRequest and call Start() on that
+ // instance. This function also insert this request object in |requests_| for
+ // record keeping.
+ void StartRequest(const GURL& main_frame_url,
+ LoginReputationClientRequest::TriggerType type,
+ bool is_extended_reporting,
+ bool is_incognito);
+
+ // Called by a PasswordProtectionRequest instance when it finishes to remove
+ // itself from |requests_|.
+ virtual void RequestFinished(
+ PasswordProtectionRequest* request,
+ std::unique_ptr<LoginReputationClientResponse> response);
+
+ // Cancels all requests in |requests_|, empties it, and releases references to
+ // the requests.
+ void CancelPendingRequests();
+
+ // Gets the total number of verdict (no matter expired or not) we cached for
+ // current active profile.
+ virtual size_t GetStoredVerdictCount();
+
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter() {
+ return request_context_getter_;
+ }
+
+ // Returns the URL where PasswordProtectionRequest instances send requests.
+ static GURL GetPasswordProtectionRequestUrl();
+
+ // Gets the request timeout in milliseconds.
+ static int GetRequestTimeoutInMS();
+
protected:
- // Called on UI thread.
+ friend class PasswordProtectionRequest;
+
// Increases "PasswordManager.PasswordReuse.MainFrameMatchCsdWhitelist" UMA
// metric based on input.
void OnMatchCsdWhiteListResult(bool match_whitelist);
@@ -114,6 +159,17 @@ class PasswordProtectionService : history::HistoryServiceObserver {
const LoginReputationClientResponse* verdict,
const base::Time& receive_time);
+ // Stored verdict count for each HostContentSettingsMap.
+ std::unordered_map<HostContentSettingsMap*, size_t> stored_verdict_counts_;
+
+ // The context we use to issue network requests. This request_context_getter
+ // is obtained from SafeBrowsingService so that we can use the Safe Browsing
+ // cookie store.
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
+
+ // Set of pending PasswordProtectionRequests.
+ std::unordered_set<std::unique_ptr<PasswordProtectionRequest>> requests_;
+
scoped_refptr<SafeBrowsingDatabaseManager> database_manager_;
base::WeakPtrFactory<PasswordProtectionService> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService);

Powered by Google App Engine
This is Rietveld 408576698