diff --git a/chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service.cc b/chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service.cc index 0da5979d24cd60..ad44684b46b363 100644 --- a/chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service.cc +++ b/chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service.cc @@ -76,14 +76,13 @@ void ChromeTailoredSecurityService::ShowSyncNotification(bool is_enabled) { if (!web_contents) return; - // Since the Android UX is a notice, we simply enable Enhanced Protection - // here. + // Since the Android UX is a notice, we simply set Safe Browsing state. SetSafeBrowsingState(profile_->GetPrefs(), - SafeBrowsingState::ENHANCED_PROTECTION, - /*is_esb_enabled_in_sync=*/true); + is_enabled ? SafeBrowsingState::ENHANCED_PROTECTION + : SafeBrowsingState::STANDARD_PROTECTION, + /*is_esb_enabled_in_sync=*/is_enabled); - message_ = std::make_unique(); - message_->DisplayMessage( + message_ = std::make_unique( web_contents, is_enabled, base::BindOnce(&ChromeTailoredSecurityService::MessageDismissed, // Unretained is safe because |this| owns |message_|. diff --git a/chrome/browser/safe_browsing/tailored_security/consented_message_android.cc b/chrome/browser/safe_browsing/tailored_security/consented_message_android.cc index a50dbbccd5a7ca..b3e8b374a2890e 100644 --- a/chrome/browser/safe_browsing/tailored_security/consented_message_android.cc +++ b/chrome/browser/safe_browsing/tailored_security/consented_message_android.cc @@ -27,24 +27,13 @@ void LogOutcome(TailoredSecurityOutcome outcome, bool enable) { } // namespace -TailoredSecurityConsentedModalAndroid::TailoredSecurityConsentedModalAndroid() = - default; - -TailoredSecurityConsentedModalAndroid:: - ~TailoredSecurityConsentedModalAndroid() { - DismissMessageInternal(messages::DismissReason::UNKNOWN); -} - -void TailoredSecurityConsentedModalAndroid::DisplayMessage( +TailoredSecurityConsentedModalAndroid::TailoredSecurityConsentedModalAndroid( content::WebContents* web_contents, bool enable, - base::OnceClosure dismiss_callback) { - if (message_) { - return; - } - web_contents_ = web_contents; - is_enable_message_ = enable; - dismiss_callback_ = std::move(dismiss_callback); + base::OnceClosure dismiss_callback) + : web_contents_(web_contents), + dismiss_callback_(std::move(dismiss_callback)), + is_enable_message_(enable) { message_ = std::make_unique( is_enable_message_ ? messages::MessageIdentifier::TAILORED_SECURITY_ENABLED @@ -90,13 +79,17 @@ void TailoredSecurityConsentedModalAndroid::DisplayMessage( LogOutcome(TailoredSecurityOutcome::kShown, is_enable_message_); } +TailoredSecurityConsentedModalAndroid:: + ~TailoredSecurityConsentedModalAndroid() { + DismissMessageInternal(messages::DismissReason::UNKNOWN); +} + void TailoredSecurityConsentedModalAndroid::DismissMessageInternal( messages::DismissReason dismiss_reason) { if (!message_) return; messages::MessageDispatcherBridge::Get()->DismissMessage(message_.get(), dismiss_reason); - std::move(dismiss_callback_).Run(); } void TailoredSecurityConsentedModalAndroid::HandleSettingsClicked() { @@ -110,12 +103,12 @@ void TailoredSecurityConsentedModalAndroid::HandleMessageDismissed( messages::DismissReason dismiss_reason) { LogOutcome(TailoredSecurityOutcome::kDismissed, is_enable_message_); message_.reset(); - std::move(dismiss_callback_).Run(); + if (dismiss_callback_) + std::move(dismiss_callback_).Run(); } void TailoredSecurityConsentedModalAndroid::HandleMessageAccepted() { LogOutcome(TailoredSecurityOutcome::kAccepted, is_enable_message_); - std::move(dismiss_callback_).Run(); } } // namespace safe_browsing diff --git a/chrome/browser/safe_browsing/tailored_security/consented_message_android.h b/chrome/browser/safe_browsing/tailored_security/consented_message_android.h index 55f07e4f0eaf1d..80a4d0fd05e830 100644 --- a/chrome/browser/safe_browsing/tailored_security/consented_message_android.h +++ b/chrome/browser/safe_browsing/tailored_security/consented_message_android.h @@ -19,14 +19,12 @@ namespace safe_browsing { class TailoredSecurityConsentedModalAndroid { public: - TailoredSecurityConsentedModalAndroid(); - ~TailoredSecurityConsentedModalAndroid(); - // Show the message for the given `web_contents`, when the Tailored security // setting has been `enabled`. - void DisplayMessage(content::WebContents* web_contents, - bool enabled, - base::OnceClosure dismiss_callback); + TailoredSecurityConsentedModalAndroid(content::WebContents* web_contents, + bool enabled, + base::OnceClosure dismiss_callback); + ~TailoredSecurityConsentedModalAndroid(); private: void DismissMessageInternal(messages::DismissReason dismiss_reason);