Commit c75ca41f authored by edchin's avatar edchin Committed by Chromium LUCI CQ

[ios][PhishGuard] Remove redundant WeakPtrFactory in PasswordProtectionRequest derived class

Previous CL split PasswordProtectionRequest into base and derived classes.
A weakptr_factory was added to the derived class, but this is not
necessary. We can use base::AsWeakPtr(&derived) to get a weak ptr to
the derived instance.

Bug: 1147967
Change-Id: I7df37dbe13448a7359707238fbfb8ca18b62ed65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642744Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarBettina Dea <bdea@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845831}
parent 8e907715
...@@ -139,9 +139,7 @@ PasswordProtectionRequest::PasswordProtectionRequest( ...@@ -139,9 +139,7 @@ PasswordProtectionRequest::PasswordProtectionRequest(
pps->GetUrlDisplayExperiment(); pps->GetUrlDisplayExperiment();
} }
PasswordProtectionRequest::~PasswordProtectionRequest() { PasswordProtectionRequest::~PasswordProtectionRequest() = default;
weakptr_factory_.InvalidateWeakPtrs();
}
void PasswordProtectionRequest::Start() { void PasswordProtectionRequest::Start() {
DCHECK(CurrentlyOnThread(ThreadID::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
...@@ -162,8 +160,7 @@ void PasswordProtectionRequest::CheckWhitelist() { ...@@ -162,8 +160,7 @@ void PasswordProtectionRequest::CheckWhitelist() {
// Start a task on the IO thread to check the whitelist. It may // Start a task on the IO thread to check the whitelist. It may
// callback immediately on the IO thread or take some time if a full-hash- // callback immediately on the IO thread or take some time if a full-hash-
// check is required. // check is required.
auto result_callback = auto result_callback = base::BindOnce(&OnWhitelistCheckDoneOnIO, AsWeakPtr());
base::BindOnce(&OnWhitelistCheckDoneOnIO, GetWeakPtr());
tracker_.PostTask( tracker_.PostTask(
GetTaskRunner(ThreadID::IO).get(), FROM_HERE, GetTaskRunner(ThreadID::IO).get(), FROM_HERE,
base::BindOnce(&AllowlistCheckerClient::StartCheckCsdWhitelist, base::BindOnce(&AllowlistCheckerClient::StartCheckCsdWhitelist,
...@@ -396,7 +393,7 @@ void PasswordProtectionRequest::SendRequest() { ...@@ -396,7 +393,7 @@ void PasswordProtectionRequest::SendRequest() {
url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie( url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
password_protection_service_->url_loader_factory().get(), password_protection_service_->url_loader_factory().get(),
base::BindOnce(&PasswordProtectionRequest::OnURLLoaderComplete, base::BindOnce(&PasswordProtectionRequest::OnURLLoaderComplete,
GetWeakPtr())); AsWeakPtr()));
} }
void PasswordProtectionRequest::StartTimeout() { void PasswordProtectionRequest::StartTimeout() {
...@@ -409,8 +406,7 @@ void PasswordProtectionRequest::StartTimeout() { ...@@ -409,8 +406,7 @@ void PasswordProtectionRequest::StartTimeout() {
GetTaskRunner(ThreadID::UI) GetTaskRunner(ThreadID::UI)
->PostDelayedTask( ->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&PasswordProtectionRequest::Cancel, GetWeakPtr(), base::BindOnce(&PasswordProtectionRequest::Cancel, AsWeakPtr(), true),
true),
base::TimeDelta::FromMilliseconds(request_timeout_in_ms_)); base::TimeDelta::FromMilliseconds(request_timeout_in_ms_));
} }
...@@ -528,7 +524,7 @@ PasswordProtectionRequestContent::PasswordProtectionRequestContent( ...@@ -528,7 +524,7 @@ PasswordProtectionRequestContent::PasswordProtectionRequestContent(
request_timeout_in_ms), request_timeout_in_ms),
web_contents_(web_contents) { web_contents_(web_contents) {
request_canceler_ = request_canceler_ =
RequestCanceler::CreateRequestCanceler(GetWeakPtr(), web_contents); RequestCanceler::CreateRequestCanceler(AsWeakPtr(), web_contents);
} }
PasswordProtectionRequestContent::~PasswordProtectionRequestContent() = default; PasswordProtectionRequestContent::~PasswordProtectionRequestContent() = default;
...@@ -549,13 +545,13 @@ void PasswordProtectionRequestContent::GetDomFeatures() { ...@@ -549,13 +545,13 @@ void PasswordProtectionRequestContent::GetDomFeatures() {
phishing_detector_->StartPhishingDetection( phishing_detector_->StartPhishingDetection(
main_frame_url(), main_frame_url(),
base::BindRepeating(&PasswordProtectionRequestContent::OnGetDomFeatures, base::BindRepeating(&PasswordProtectionRequestContent::OnGetDomFeatures,
GetWeakPtr())); AsWeakPtr()));
GetTaskRunner(ThreadID::UI) GetTaskRunner(ThreadID::UI)
->PostDelayedTask( ->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindOnce(
&PasswordProtectionRequestContent::OnGetDomFeatureTimeout, &PasswordProtectionRequestContent::OnGetDomFeatureTimeout,
GetWeakPtr()), AsWeakPtr()),
base::TimeDelta::FromMilliseconds(kDomFeatureTimeoutMs)); base::TimeDelta::FromMilliseconds(kDomFeatureTimeoutMs));
dom_feature_start_time_ = base::TimeTicks::Now(); dom_feature_start_time_ = base::TimeTicks::Now();
} }
...@@ -648,7 +644,7 @@ void PasswordProtectionRequestContent::CollectVisualFeatures() { ...@@ -648,7 +644,7 @@ void PasswordProtectionRequestContent::CollectVisualFeatures() {
view->CopyFromSurface( view->CopyFromSurface(
gfx::Rect(), gfx::Size(), gfx::Rect(), gfx::Size(),
base::BindOnce(&PasswordProtectionRequestContent::OnScreenshotTaken, base::BindOnce(&PasswordProtectionRequestContent::OnScreenshotTaken,
GetWeakPtr())); AsWeakPtr()));
} }
void PasswordProtectionRequestContent::OnScreenshotTaken( void PasswordProtectionRequestContent::OnScreenshotTaken(
...@@ -661,7 +657,7 @@ void PasswordProtectionRequestContent::OnScreenshotTaken( ...@@ -661,7 +657,7 @@ void PasswordProtectionRequestContent::OnScreenshotTaken(
base::BindOnce(&ExtractVisualFeatures, screenshot), base::BindOnce(&ExtractVisualFeatures, screenshot),
base::BindOnce( base::BindOnce(
&PasswordProtectionRequestContent::OnVisualFeatureCollectionDone, &PasswordProtectionRequestContent::OnVisualFeatureCollectionDone,
GetWeakPtr())); AsWeakPtr()));
} }
void PasswordProtectionRequestContent::OnVisualFeatureCollectionDone( void PasswordProtectionRequestContent::OnVisualFeatureCollectionDone(
......
...@@ -83,17 +83,14 @@ using DeleteOnUIThread = ...@@ -83,17 +83,14 @@ using DeleteOnUIThread =
class PasswordProtectionRequest class PasswordProtectionRequest
: public CancelableRequest, : public CancelableRequest,
public base::RefCountedThreadSafe<PasswordProtectionRequest, public base::RefCountedThreadSafe<PasswordProtectionRequest,
DeleteOnUIThread> { DeleteOnUIThread>,
public base::SupportsWeakPtr<PasswordProtectionRequest> {
public: public:
// Not copyable or movable // Not copyable or movable
PasswordProtectionRequest(const PasswordProtectionRequest&) = delete; PasswordProtectionRequest(const PasswordProtectionRequest&) = delete;
PasswordProtectionRequest& operator=(const PasswordProtectionRequest&) = PasswordProtectionRequest& operator=(const PasswordProtectionRequest&) =
delete; delete;
base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
return weakptr_factory_.GetWeakPtr();
}
// Starts processing request by checking extended reporting and incognito // Starts processing request by checking extended reporting and incognito
// conditions. // conditions.
void Start(); void Start();
...@@ -295,8 +292,6 @@ class PasswordProtectionRequest ...@@ -295,8 +292,6 @@ class PasswordProtectionRequest
// If a request is sent, this is the token returned by the WebUI. // If a request is sent, this is the token returned by the WebUI.
int web_ui_token_; int web_ui_token_;
base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_{this};
}; };
class PasswordProtectionRequestContent : public PasswordProtectionRequest { class PasswordProtectionRequestContent : public PasswordProtectionRequest {
...@@ -318,8 +313,8 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest { ...@@ -318,8 +313,8 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest {
content::WebContents* web_contents() const { return web_contents_; } content::WebContents* web_contents() const { return web_contents_; }
base::WeakPtr<PasswordProtectionRequestContent> GetWeakPtr() { base::WeakPtr<PasswordProtectionRequestContent> AsWeakPtr() {
return weakptr_factory_.GetWeakPtr(); return base::AsWeakPtr(this);
} }
private: private:
...@@ -383,8 +378,6 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest { ...@@ -383,8 +378,6 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest {
// successfully gathering the features. // successfully gathering the features.
bool dom_features_collection_complete_; bool dom_features_collection_complete_;
#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE) #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
base::WeakPtrFactory<PasswordProtectionRequestContent> weakptr_factory_{this};
}; };
} // 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