Skip to content

Commit

Permalink
[DTC] Fix consent dialog dangling pointer
Browse files Browse the repository at this point in the history
Fix dialog crashes when clicking on "share signals" due to dangling pointer.

(cherry picked from commit 56e4006)

Bug: 1462199, b:289412831
Change-Id: I5334c482274f7bff7093177437fc8c2bea4ede82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4662990
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Zonghan Xu <xzonghan@chromium.org>
Reviewed-by: Sébastien Lalancette <seblalancette@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1166511}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4673331
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5845@{#420}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
Zonghan Xu authored and Chromium LUCI CQ committed Jul 11, 2023
1 parent 0b98c53 commit b982568
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,17 @@ DeviceTrustNavigationThrottle::MayTriggerConsentDialog() {
return PROCEED;
}

consent_requester_->RequestConsent(
base::BindRepeating(&DeviceTrustNavigationThrottle::OnConsentPrefUpdated,
weak_ptr_factory_.GetWeakPtr()));
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(
[](base::WeakPtr<DeviceTrustNavigationThrottle> throttler) {
if (throttler) {
throttler->consent_requester_->RequestConsent(base::BindRepeating(
&DeviceTrustNavigationThrottle::OnConsentPrefUpdated,
throttler));
}
},
weak_ptr_factory_.GetWeakPtr()));

return DEFER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ TEST_F(DeviceTrustNavigationThrottleTest, BlockedByConsentDialog) {
.Times(1)
.WillOnce(Return());
EXPECT_EQ(NavigationThrottle::DEFER, throttle->WillStartRequest().action());

base::RunLoop().RunUntilIdle();
}

TEST_F(DeviceTrustNavigationThrottleTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void ConsentDialogCoordinator::OnConsentPreferenceUpdated(
if (dialog_widget_) {
dialog_widget_->CloseWithReason(
views::Widget::ClosedReason::kAcceptButtonClicked);
dialog_widget_ = nullptr;
}
callback.Run();
}
Expand Down

0 comments on commit b982568

Please sign in to comment.