Commit 4e699456 authored by edchin's avatar edchin Committed by Chromium LUCI CQ

[ios][PhishGuard] Create PasswordProtectionServiceBase

This CL creates a base class that will hold cross-platform code.
The derived class PasswordProtectionService (in /content) will
have content-specific code.

This CL keeps the base class in the same file to make the review
easier. A followup CL will move the base class (and unittest) into
separate files.

* moves navigation throttle code to derived class.
* moves some content-specific functions to derived class.

Bug: 1147967
Change-Id: I1fa606f241225680bd33b7828fdfc6b588ad415d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2576079Reviewed-by: default avatarBettina Dea <bdea@chromium.org>
Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835830}
parent f84561d6
...@@ -112,7 +112,7 @@ PasswordProtectionRequest::PasswordProtectionRequest( ...@@ -112,7 +112,7 @@ PasswordProtectionRequest::PasswordProtectionRequest(
matching_reused_credentials, matching_reused_credentials,
LoginReputationClientRequest::TriggerType type, LoginReputationClientRequest::TriggerType type,
bool password_field_exists, bool password_field_exists,
PasswordProtectionService* pps, PasswordProtectionServiceBase* pps,
int request_timeout_in_ms) int request_timeout_in_ms)
: web_contents_(web_contents), : web_contents_(web_contents),
main_frame_url_(main_frame_url), main_frame_url_(main_frame_url),
...@@ -526,7 +526,7 @@ void PasswordProtectionRequest::SendRequest() { ...@@ -526,7 +526,7 @@ void PasswordProtectionRequest::SendRequest() {
})"); })");
auto resource_request = std::make_unique<network::ResourceRequest>(); auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = resource_request->url =
PasswordProtectionService::GetPasswordProtectionRequestUrl(); PasswordProtectionServiceBase::GetPasswordProtectionRequestUrl();
resource_request->method = "POST"; resource_request->method = "POST";
resource_request->load_flags = net::LOAD_DISABLE_CACHE; resource_request->load_flags = net::LOAD_DISABLE_CACHE;
url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request), url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
...@@ -593,7 +593,7 @@ void PasswordProtectionRequest::Finish( ...@@ -593,7 +593,7 @@ void PasswordProtectionRequest::Finish(
DCHECK(CurrentlyOnThread(ThreadID::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
tracker_.TryCancelAll(); tracker_.TryCancelAll();
// If the request is canceled, the PasswordProtectionService is already // If the request is canceled, the PasswordProtectionServiceBase is already
// partially destroyed, and we won't be able to log accurate metrics. // partially destroyed, and we won't be able to log accurate metrics.
if (outcome != RequestOutcome::CANCELED) { if (outcome != RequestOutcome::CANCELED) {
ReusedPasswordAccountType password_account_type = ReusedPasswordAccountType password_account_type =
......
...@@ -63,9 +63,9 @@ using DeleteOnUIThread = ...@@ -63,9 +63,9 @@ using DeleteOnUIThread =
// A request for checking if an unfamiliar login form or a password reuse event // A request for checking if an unfamiliar login form or a password reuse event
// is safe. PasswordProtectionRequest objects are owned by // is safe. PasswordProtectionRequest objects are owned by
// PasswordProtectionService indicated by |password_protection_service_|. // PasswordProtectionServiceBase indicated by |password_protection_service_|.
// PasswordProtectionService is RefCountedThreadSafe such that it can post task // PasswordProtectionServiceBase is RefCountedThreadSafe such that it can post
// safely between IO and UI threads. It can only be destroyed on UI thread. // task safely between IO and UI threads. It can only be destroyed on UI thread.
// //
// PasswordProtectionRequest flow: // PasswordProtectionRequest flow:
// Step| Thread | Task // Step| Thread | Task
...@@ -97,7 +97,7 @@ class PasswordProtectionRequest ...@@ -97,7 +97,7 @@ class PasswordProtectionRequest
matching_reused_credentials, matching_reused_credentials,
LoginReputationClientRequest::TriggerType type, LoginReputationClientRequest::TriggerType type,
bool password_field_exists, bool password_field_exists,
PasswordProtectionService* pps, PasswordProtectionServiceBase* pps,
int request_timeout_in_ms); int request_timeout_in_ms);
// Not copyable or movable // Not copyable or movable
...@@ -280,9 +280,9 @@ class PasswordProtectionRequest ...@@ -280,9 +280,9 @@ class PasswordProtectionRequest
// SimpleURLLoader instance for sending request and receiving response. // SimpleURLLoader instance for sending request and receiving response.
std::unique_ptr<network::SimpleURLLoader> url_loader_; std::unique_ptr<network::SimpleURLLoader> url_loader_;
// The PasswordProtectionService instance owns |this|. // The PasswordProtectionServiceBase instance owns |this|.
// Can only be accessed on UI thread. // Can only be accessed on UI thread.
PasswordProtectionService* password_protection_service_; PasswordProtectionServiceBase* password_protection_service_;
// The outcome of the password protection request. // The outcome of the password protection request.
RequestOutcome request_outcome_; RequestOutcome request_outcome_;
......
...@@ -61,19 +61,19 @@ using ReusedPasswordType = ...@@ -61,19 +61,19 @@ using ReusedPasswordType =
using password_manager::metrics_util::PasswordType; using password_manager::metrics_util::PasswordType;
// Manage password protection pings and verdicts. There is one instance of this // Manage password protection pings and verdicts. There is one instance of this
// class per profile. Therefore, every PasswordProtectionService instance is // class per profile. Therefore, every PasswordProtectionServiceBase instance is
// associated with a unique HistoryService instance and a unique // associated with a unique HistoryService instance and a unique
// HostContentSettingsMap instance. // HostContentSettingsMap instance.
class PasswordProtectionService : public history::HistoryServiceObserver { class PasswordProtectionServiceBase : public history::HistoryServiceObserver {
public: public:
PasswordProtectionService( PasswordProtectionServiceBase(
const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
history::HistoryService* history_service); history::HistoryService* history_service);
~PasswordProtectionService() override; ~PasswordProtectionServiceBase() override;
base::WeakPtr<PasswordProtectionService> GetWeakPtr() { base::WeakPtr<PasswordProtectionServiceBase> GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
...@@ -186,12 +186,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -186,12 +186,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
virtual bool UserClickedThroughSBInterstitial( virtual bool UserClickedThroughSBInterstitial(
PasswordProtectionRequest* request) = 0; PasswordProtectionRequest* request) = 0;
// Called when a new navigation is starting. Create throttle if there is a
// pending sync password reuse ping or if there is a modal warning dialog
// showing in the corresponding web contents.
std::unique_ptr<PasswordProtectionNavigationThrottle>
MaybeCreateNavigationThrottle(content::NavigationHandle* navigation_handle);
// Returns if the warning UI is enabled. // Returns if the warning UI is enabled.
bool IsWarningEnabled(ReusedPasswordAccountType password_type); bool IsWarningEnabled(ReusedPasswordAccountType password_type);
...@@ -294,6 +288,9 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -294,6 +288,9 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
virtual AccountInfo GetAccountInfo() const = 0; virtual AccountInfo GetAccountInfo() const = 0;
// Returns the URL where PasswordProtectionRequest instances send requests.
static GURL GetPasswordProtectionRequestUrl();
protected: protected:
friend class PasswordProtectionRequest; friend class PasswordProtectionRequest;
...@@ -336,9 +333,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -336,9 +333,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
return url_loader_factory_; return url_loader_factory_;
} }
// Returns the URL where PasswordProtectionRequest instances send requests.
static GURL GetPasswordProtectionRequestUrl();
// Gets the request timeout in milliseconds. // Gets the request timeout in milliseconds.
static int GetRequestTimeoutInMS(); static int GetRequestTimeoutInMS();
...@@ -405,10 +399,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -405,10 +399,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
PasswordType password_type, PasswordType password_type,
const LoginReputationClientResponse*) = 0; const LoginReputationClientResponse*) = 0;
void RemoveWarningRequestsByWebContents(content::WebContents* web_contents);
bool IsModalWarningShowingInWebContents(content::WebContents* web_contents);
// Determines if we should show chrome://reset-password interstitial based on // Determines if we should show chrome://reset-password interstitial based on
// the reused |password_type| and the |main_frame_url|. // the reused |password_type| and the |main_frame_url|.
virtual bool CanShowInterstitial(ReusedPasswordAccountType password_type, virtual bool CanShowInterstitial(ReusedPasswordAccountType password_type,
...@@ -437,6 +427,13 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -437,6 +427,13 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
return common_spoofed_domains_; return common_spoofed_domains_;
} }
// Set of pending PasswordProtectionRequests that are still waiting for
// verdict.
std::set<scoped_refptr<PasswordProtectionRequest>> pending_requests_;
// Set of PasswordProtectionRequests that are triggering modal warnings.
std::set<scoped_refptr<PasswordProtectionRequest>> warning_requests_;
private: private:
friend class PasswordProtectionServiceTest; friend class PasswordProtectionServiceTest;
friend class TestPasswordProtectionService; friend class TestPasswordProtectionService;
...@@ -509,13 +506,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -509,13 +506,6 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
// cookie store. // cookie store.
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// Set of pending PasswordProtectionRequests that are still waiting for
// verdict.
std::set<scoped_refptr<PasswordProtectionRequest>> pending_requests_;
// Set of PasswordProtectionRequests that are triggering modal warnings.
std::set<scoped_refptr<PasswordProtectionRequest>> warning_requests_;
// List of most commonly spoofed domains to default to on the password warning // List of most commonly spoofed domains to default to on the password warning
// dialog. // dialog.
std::list<std::string> common_spoofed_domains_; std::list<std::string> common_spoofed_domains_;
...@@ -528,8 +518,24 @@ class PasswordProtectionService : public history::HistoryServiceObserver { ...@@ -528,8 +518,24 @@ class PasswordProtectionService : public history::HistoryServiceObserver {
// we need CancelableTaskTracker to cancel tasks posted to IO thread. // we need CancelableTaskTracker to cancel tasks posted to IO thread.
base::CancelableTaskTracker tracker_; base::CancelableTaskTracker tracker_;
base::WeakPtrFactory<PasswordProtectionService> weak_factory_{this}; base::WeakPtrFactory<PasswordProtectionServiceBase> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(PasswordProtectionService); DISALLOW_COPY_AND_ASSIGN(PasswordProtectionServiceBase);
};
class PasswordProtectionService : public PasswordProtectionServiceBase {
using PasswordProtectionServiceBase::PasswordProtectionServiceBase;
public:
// Called when a new navigation is starting. Create throttle if there is a
// pending sync password reuse ping or if there is a modal warning dialog
// showing in the corresponding web contents.
std::unique_ptr<PasswordProtectionNavigationThrottle>
MaybeCreateNavigationThrottle(content::NavigationHandle* navigation_handle);
protected:
void RemoveWarningRequestsByWebContents(content::WebContents* web_contents);
bool IsModalWarningShowingInWebContents(content::WebContents* web_contents);
}; };
} // namespace safe_browsing } // namespace safe_browsing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment