[OOBE][SmartPrivacyProtection]: Update screen structure

- Remove Bind/Unbind logic;
- Remove OnViewDestroyed;
- Remove show_on_init;
- Migrate to OnUserAction with args list and external API prefix;

Bug: 1324940, 1309022, 1298392
Change-Id: I35c48e358264ef48b38efb3a0438b1cb2bb1df6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3644671
Reviewed-by: Roman Sorokin <rsorokin@chromium.org>
Commit-Queue: Danila Kuzmin <dkuzmin@google.com>
Cr-Commit-Position: refs/heads/main@{#1003053}
diff --git a/chrome/browser/ash/login/screens/smart_privacy_protection_screen.cc b/chrome/browser/ash/login/screens/smart_privacy_protection_screen.cc
index 3faa5f9..6fec768 100644
--- a/chrome/browser/ash/login/screens/smart_privacy_protection_screen.cc
+++ b/chrome/browser/ash/login/screens/smart_privacy_protection_screen.cc
@@ -32,27 +32,14 @@
 }
 
 SmartPrivacyProtectionScreen::SmartPrivacyProtectionScreen(
-    SmartPrivacyProtectionView* view,
+    base::WeakPtr<SmartPrivacyProtectionView> view,
     const ScreenExitCallback& exit_callback)
     : BaseScreen(SmartPrivacyProtectionView::kScreenId,
                  OobeScreenPriority::DEFAULT),
-      view_(view),
-      exit_callback_(exit_callback) {
-  DCHECK(view);
-  if (view_)
-    view_->Bind(this);
-}
+      view_(std::move(view)),
+      exit_callback_(exit_callback) {}
 
-SmartPrivacyProtectionScreen::~SmartPrivacyProtectionScreen() {
-  if (view_)
-    view_->Unbind();
-}
-
-void SmartPrivacyProtectionScreen::OnViewDestroyed(
-    SmartPrivacyProtectionView* view) {
-  if (view_ == view)
-    view_ = nullptr;
-}
+SmartPrivacyProtectionScreen::~SmartPrivacyProtectionScreen() = default;
 
 bool SmartPrivacyProtectionScreen::MaybeSkip(WizardContext* context) {
   // SmartPrivacyProtectionScreen lets user set two settings simultaneously:
@@ -72,13 +59,10 @@
     view_->Show();
 }
 
-void SmartPrivacyProtectionScreen::HideImpl() {
-  if (view_)
-    view_->Hide();
-}
+void SmartPrivacyProtectionScreen::HideImpl() {}
 
-void SmartPrivacyProtectionScreen::OnUserActionDeprecated(
-    const std::string& action_id) {
+void SmartPrivacyProtectionScreen::OnUserAction(const base::Value::List& args) {
+  const std::string& action_id = args[0].GetString();
   if (action_id == kUserActionFeatureTurnOn) {
     Profile* profile = ProfileManager::GetActiveUserProfile();
     profile->GetPrefs()->SetBoolean(
@@ -95,7 +79,7 @@
   } else if (action_id == kUserActionShowLearnMore) {
     // TODO(crbug.com/1293320): add p-link once available
   } else {
-    BaseScreen::OnUserActionDeprecated(action_id);
+    BaseScreen::OnUserAction(args);
   }
 }
 
diff --git a/chrome/browser/ash/login/screens/smart_privacy_protection_screen.h b/chrome/browser/ash/login/screens/smart_privacy_protection_screen.h
index 6c5c43a9..abe8c09 100644
--- a/chrome/browser/ash/login/screens/smart_privacy_protection_screen.h
+++ b/chrome/browser/ash/login/screens/smart_privacy_protection_screen.h
@@ -28,7 +28,7 @@
   static std::string GetResultString(Result result);
 
   using ScreenExitCallback = base::RepeatingCallback<void(Result result)>;
-  SmartPrivacyProtectionScreen(SmartPrivacyProtectionView* view,
+  SmartPrivacyProtectionScreen(base::WeakPtr<SmartPrivacyProtectionView> view,
                                const ScreenExitCallback& exit_callback);
 
   SmartPrivacyProtectionScreen(const SmartPrivacyProtectionScreen&) = delete;
@@ -37,9 +37,6 @@
 
   ~SmartPrivacyProtectionScreen() override;
 
-  // This method is called, when view is being destroyed.
-  void OnViewDestroyed(SmartPrivacyProtectionView* view);
-
   void set_exit_callback_for_testing(const ScreenExitCallback& callback) {
     exit_callback_ = callback;
   }
@@ -49,9 +46,9 @@
   bool MaybeSkip(WizardContext* context) override;
   void ShowImpl() override;
   void HideImpl() override;
-  void OnUserActionDeprecated(const std::string& action_id) override;
+  void OnUserAction(const base::Value::List& args) override;
 
-  SmartPrivacyProtectionView* view_;
+  base::WeakPtr<SmartPrivacyProtectionView> view_;
 
   ScreenExitCallback exit_callback_;
 };
diff --git a/chrome/browser/ash/login/wizard_controller.cc b/chrome/browser/ash/login/wizard_controller.cc
index 6144d6f4..34544d2 100644
--- a/chrome/browser/ash/login/wizard_controller.cc
+++ b/chrome/browser/ash/login/wizard_controller.cc
@@ -775,7 +775,7 @@
   }
 
   append(std::make_unique<SmartPrivacyProtectionScreen>(
-      oobe_ui->GetView<SmartPrivacyProtectionScreenHandler>(),
+      oobe_ui->GetView<SmartPrivacyProtectionScreenHandler>()->AsWeakPtr(),
       base::BindRepeating(&WizardController::OnSmartPrivacyProtectionScreenExit,
                           weak_factory_.GetWeakPtr())));
 
diff --git a/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.cc
index bb8d11df..2c414a2 100644
--- a/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.cc
@@ -7,48 +7,21 @@
 #include "ash/constants/ash_features.h"
 #include "base/values.h"
 #include "chrome/browser/ash/login/oobe_screen.h"
-#include "chrome/browser/ash/login/screens/smart_privacy_protection_screen.h"
 #include "chrome/grit/generated_resources.h"
 #include "components/login/localized_values_builder.h"
 
 namespace chromeos {
 
-constexpr StaticOobeScreenId SmartPrivacyProtectionView::kScreenId;
-
 SmartPrivacyProtectionScreenHandler::SmartPrivacyProtectionScreenHandler()
-    : BaseScreenHandler(kScreenId) {
-  set_user_acted_method_path_deprecated(
-      "login.SmartPrivacyProtectionScreen.userActed");
-}
+    : BaseScreenHandler(kScreenId) {}
 
-SmartPrivacyProtectionScreenHandler::~SmartPrivacyProtectionScreenHandler() {
-  if (screen_)
-    screen_->OnViewDestroyed(this);
-}
+SmartPrivacyProtectionScreenHandler::~SmartPrivacyProtectionScreenHandler() =
+    default;
 
 void SmartPrivacyProtectionScreenHandler::Show() {
-  if (!IsJavascriptAllowed()) {
-    show_on_init_ = true;
-    return;
-  }
   ShowInWebUI();
 }
 
-void SmartPrivacyProtectionScreenHandler::Hide() {
-  show_on_init_ = false;
-}
-
-void SmartPrivacyProtectionScreenHandler::Bind(
-    ash::SmartPrivacyProtectionScreen* screen) {
-  screen_ = screen;
-  BaseScreenHandler::SetBaseScreenDeprecated(screen_);
-}
-
-void SmartPrivacyProtectionScreenHandler::Unbind() {
-  screen_ = nullptr;
-  BaseScreenHandler::SetBaseScreenDeprecated(nullptr);
-}
-
 void SmartPrivacyProtectionScreenHandler::DeclareLocalizedValues(
     ::login::LocalizedValuesBuilder* builder) {
   builder->Add("smartPrivacyProtectionScreenTitle",
@@ -77,14 +50,4 @@
             base::Value(ash::features::IsSnoopingProtectionEnabled()));
 }
 
-void SmartPrivacyProtectionScreenHandler::InitializeDeprecated() {
-  if (!IsJavascriptAllowed() || !screen_)
-    return;
-
-  if (show_on_init_) {
-    Show();
-    show_on_init_ = false;
-  }
-}
-
 }  // namespace chromeos
diff --git a/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.h
index ef93770e..d6508d2 100644
--- a/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.h
+++ b/chrome/browser/ui/webui/chromeos/login/smart_privacy_protection_screen_handler.h
@@ -16,18 +16,16 @@
 namespace chromeos {
 
 // Interface between SmartPrivacyProtection screen and its representation,
-// either WebUI or Views one. Note, do not forget to call OnViewDestroyed in the
-// dtor.
-class SmartPrivacyProtectionView {
+// either WebUI or Views one.
+class SmartPrivacyProtectionView
+    : public base::SupportsWeakPtr<SmartPrivacyProtectionView> {
  public:
-  constexpr static StaticOobeScreenId kScreenId{"smart-privacy-protection"};
+  inline constexpr static StaticOobeScreenId kScreenId{
+      "smart-privacy-protection", "SmartPrivacyProtectionScreen"};
 
   virtual ~SmartPrivacyProtectionView() {}
 
   virtual void Show() = 0;
-  virtual void Hide() = 0;
-  virtual void Bind(ash::SmartPrivacyProtectionScreen* screen) = 0;
-  virtual void Unbind() = 0;
 };
 
 // WebUI implementation of SmartPrivacyProtectionView. It is used to interact
@@ -48,21 +46,11 @@
 
   // SmartPrivacyProtectionView implementation:
   void Show() override;
-  void Hide() override;
-  void Bind(ash::SmartPrivacyProtectionScreen* screen) override;
-  void Unbind() override;
 
   // BaseScreenHandler implementation:
   void DeclareLocalizedValues(
       ::login::LocalizedValuesBuilder* builder) override;
   void GetAdditionalParameters(base::Value::Dict* dict) override;
-  void InitializeDeprecated() override;
-
- private:
-  ash::SmartPrivacyProtectionScreen* screen_ = nullptr;
-
-  // Keeps whether screen should be shown right after initialization.
-  bool show_on_init_ = false;
 };
 
 }  // namespace chromeos