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(
pps->GetUrlDisplayExperiment();
}
PasswordProtectionRequest::~PasswordProtectionRequest() {
weakptr_factory_.InvalidateWeakPtrs();
}
PasswordProtectionRequest::~PasswordProtectionRequest() = default;
void PasswordProtectionRequest::Start() {
DCHECK(CurrentlyOnThread(ThreadID::UI));
......@@ -162,8 +160,7 @@ void PasswordProtectionRequest::CheckWhitelist() {
// 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-
// check is required.
auto result_callback =
base::BindOnce(&OnWhitelistCheckDoneOnIO, GetWeakPtr());
auto result_callback = base::BindOnce(&OnWhitelistCheckDoneOnIO, AsWeakPtr());
tracker_.PostTask(
GetTaskRunner(ThreadID::IO).get(), FROM_HERE,
base::BindOnce(&AllowlistCheckerClient::StartCheckCsdWhitelist,
......@@ -396,7 +393,7 @@ void PasswordProtectionRequest::SendRequest() {
url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
password_protection_service_->url_loader_factory().get(),
base::BindOnce(&PasswordProtectionRequest::OnURLLoaderComplete,
GetWeakPtr()));
AsWeakPtr()));
}
void PasswordProtectionRequest::StartTimeout() {
......@@ -409,8 +406,7 @@ void PasswordProtectionRequest::StartTimeout() {
GetTaskRunner(ThreadID::UI)
->PostDelayedTask(
FROM_HERE,
base::BindOnce(&PasswordProtectionRequest::Cancel, GetWeakPtr(),
true),
base::BindOnce(&PasswordProtectionRequest::Cancel, AsWeakPtr(), true),
base::TimeDelta::FromMilliseconds(request_timeout_in_ms_));
}
......@@ -528,7 +524,7 @@ PasswordProtectionRequestContent::PasswordProtectionRequestContent(
request_timeout_in_ms),
web_contents_(web_contents) {
request_canceler_ =
RequestCanceler::CreateRequestCanceler(GetWeakPtr(), web_contents);
RequestCanceler::CreateRequestCanceler(AsWeakPtr(), web_contents);
}
PasswordProtectionRequestContent::~PasswordProtectionRequestContent() = default;
......@@ -549,13 +545,13 @@ void PasswordProtectionRequestContent::GetDomFeatures() {
phishing_detector_->StartPhishingDetection(
main_frame_url(),
base::BindRepeating(&PasswordProtectionRequestContent::OnGetDomFeatures,
GetWeakPtr()));
AsWeakPtr()));
GetTaskRunner(ThreadID::UI)
->PostDelayedTask(
FROM_HERE,
base::BindOnce(
&PasswordProtectionRequestContent::OnGetDomFeatureTimeout,
GetWeakPtr()),
AsWeakPtr()),
base::TimeDelta::FromMilliseconds(kDomFeatureTimeoutMs));
dom_feature_start_time_ = base::TimeTicks::Now();
}
......@@ -648,7 +644,7 @@ void PasswordProtectionRequestContent::CollectVisualFeatures() {
view->CopyFromSurface(
gfx::Rect(), gfx::Size(),
base::BindOnce(&PasswordProtectionRequestContent::OnScreenshotTaken,
GetWeakPtr()));
AsWeakPtr()));
}
void PasswordProtectionRequestContent::OnScreenshotTaken(
......@@ -661,7 +657,7 @@ void PasswordProtectionRequestContent::OnScreenshotTaken(
base::BindOnce(&ExtractVisualFeatures, screenshot),
base::BindOnce(
&PasswordProtectionRequestContent::OnVisualFeatureCollectionDone,
GetWeakPtr()));
AsWeakPtr()));
}
void PasswordProtectionRequestContent::OnVisualFeatureCollectionDone(
......
......@@ -83,17 +83,14 @@ using DeleteOnUIThread =
class PasswordProtectionRequest
: public CancelableRequest,
public base::RefCountedThreadSafe<PasswordProtectionRequest,
DeleteOnUIThread> {
DeleteOnUIThread>,
public base::SupportsWeakPtr<PasswordProtectionRequest> {
public:
// Not copyable or movable
PasswordProtectionRequest(const PasswordProtectionRequest&) = delete;
PasswordProtectionRequest& operator=(const PasswordProtectionRequest&) =
delete;
base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
return weakptr_factory_.GetWeakPtr();
}
// Starts processing request by checking extended reporting and incognito
// conditions.
void Start();
......@@ -295,8 +292,6 @@ class PasswordProtectionRequest
// If a request is sent, this is the token returned by the WebUI.
int web_ui_token_;
base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_{this};
};
class PasswordProtectionRequestContent : public PasswordProtectionRequest {
......@@ -318,8 +313,8 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest {
content::WebContents* web_contents() const { return web_contents_; }
base::WeakPtr<PasswordProtectionRequestContent> GetWeakPtr() {
return weakptr_factory_.GetWeakPtr();
base::WeakPtr<PasswordProtectionRequestContent> AsWeakPtr() {
return base::AsWeakPtr(this);
}
private:
......@@ -383,8 +378,6 @@ class PasswordProtectionRequestContent : public PasswordProtectionRequest {
// successfully gathering the features.
bool dom_features_collection_complete_;
#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
base::WeakPtrFactory<PasswordProtectionRequestContent> weakptr_factory_{this};
};
} // 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