Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / ash / multi_device_setup / multi_device_notification_presenter.h
index 14cbbe8..e0e8d9a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -9,22 +9,22 @@
 #include <string>
 
 #include "ash/ash_export.h"
-#include "ash/session/session_observer.h"
-#include "base/macros.h"
+#include "ash/public/cpp/session/session_observer.h"
+#include "base/auto_reset.h"
+#include "base/functional/callback.h"
+#include "base/memory/raw_ptr.h"
 #include "base/memory/weak_ptr.h"
-#include "base/strings/string16.h"
-#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
-#include "mojo/public/cpp/bindings/binding.h"
+#include "chromeos/ash/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
+#include "mojo/public/cpp/bindings/receiver.h"
+#include "mojo/public/cpp/bindings/remote.h"
+#include "ui/message_center/message_center_observer.h"
 
 namespace message_center {
 class MessageCenter;
 class Notification;
+class RichNotificationData;
 }  // namespace message_center
 
-namespace service_manager {
-class Connector;
-}  // namespace service_manager
-
 namespace ash {
 
 // Presents notifications necessary for MultiDevice setup flow. It observes the
@@ -42,18 +42,35 @@ namespace ash {
 // Note that if one notification is showing and another one is triggered, the
 // old text is replaced (if it's different) and the notification pops up again.
 class ASH_EXPORT MultiDeviceNotificationPresenter
-    : public chromeos::multidevice_setup::mojom::AccountStatusChangeDelegate,
-      public SessionObserver {
+    : public multidevice_setup::mojom::AccountStatusChangeDelegate,
+      public SessionObserver,
+      public message_center::MessageCenterObserver {
  public:
-  MultiDeviceNotificationPresenter(
-      message_center::MessageCenter* message_center,
-      service_manager::Connector* connector);
+  explicit MultiDeviceNotificationPresenter(
+      message_center::MessageCenter* message_center);
+
+  MultiDeviceNotificationPresenter(const MultiDeviceNotificationPresenter&) =
+      delete;
+  MultiDeviceNotificationPresenter& operator=(
+      const MultiDeviceNotificationPresenter&) = delete;
+
   ~MultiDeviceNotificationPresenter() override;
 
+  // Disables notifications for tests.
+  static std::unique_ptr<base::AutoReset<bool>>
+  DisableNotificationsForTesting();
+
   // Removes the notification created by NotifyPotentialHostExists() or does
   // nothing if that notification is not currently displayed.
   void RemoveMultiDeviceSetupNotification();
 
+  void UpdateIsSetupNotificationInteracted(
+      bool is_setup_notificaton_interacted);
+
+  // MultiDevice setup notification ID. Public so it can be accessed from
+  // phone_hub_tray.cc
+  static const char kSetupNotificationId[];
+
  protected:
   // multidevice_setup::mojom::AccountStatusChangeDelegate:
   void OnPotentialHostExistsForNewUser() override;
@@ -62,26 +79,26 @@ class ASH_EXPORT MultiDeviceNotificationPresenter
       const std::string& new_host_device_name) override;
   void OnNewChromebookAddedForExistingUser(
       const std::string& new_host_device_name) override;
+  void OnBecameEligibleForWifiSync() override;
 
   // SessionObserver:
   void OnUserSessionAdded(const AccountId& account_id) override;
   void OnSessionStateChanged(session_manager::SessionState state) override;
 
+  // message_center::MessageCenterObserver
+  void OnNotificationRemoved(const std::string& notification_id,
+                             bool by_user) override;
+
+  void OnNotificationClicked(
+      const std::string& notification_id,
+      const absl::optional<int>& button_index,
+      const absl::optional<std::u16string>& reply) override;
+
  private:
   friend class MultiDeviceNotificationPresenterTest;
 
   // MultiDevice setup notification ID.
-  static const char kNotificationId[];
-
-  // These methods are delegated to a nested class to make them easier to stub
-  // in unit tests. This way they can all be stubbed simultaneously by building
-  // a test delegate class deriving from OpenUiDelegate.
-  class OpenUiDelegate {
-   public:
-    virtual ~OpenUiDelegate();
-    virtual void OpenMultiDeviceSetupUi();
-    virtual void OpenConnectedDevicesSettings();
-  };
+  static const char kWifiSyncNotificationId[];
 
   // Represents each possible MultiDevice setup notification that the setup flow
   // can show with a "none" option for the general state with no notification
@@ -95,11 +112,14 @@ class ASH_EXPORT MultiDeviceNotificationPresenter
 
   // Reflects MultiDeviceSetupNotification enum in enums.xml. Do not
   // rearrange.
-  enum NotificationType {
-    kNotificationTypeNewUserPotentialHostExists = 0,
-    kNotificationTypeExistingUserHostSwitched = 1,
-    kNotificationTypeExistingUserNewChromebookAdded = 2,
-    kNotificationTypeMax
+  enum class NotificationType {
+    kNewUserPotentialHostExists = 0,
+    kExistingUserHostSwitched = 1,
+    kExistingUserNewChromebookAdded = 2,
+    // This is a legacy error case that is not expected to occur.
+    kErrorUnknown = 3,
+    kWifiSyncAnnouncement = 4,
+    kMaxValue = kWifiSyncAnnouncement
   };
 
   static NotificationType GetMetricValueForNotification(
@@ -109,32 +129,34 @@ class ASH_EXPORT MultiDeviceNotificationPresenter
       Status notification_status);
 
   void ObserveMultiDeviceSetupIfPossible();
-  void OnNotificationClicked();
-  void ShowNotification(const Status notification_status,
-                        const base::string16& title,
-                        const base::string16& message);
-  std::unique_ptr<message_center::Notification> CreateNotification(
-      const base::string16& title,
-      const base::string16& message);
+  void ShowSetupNotification(const Status notification_status,
+                             const std::u16string& title,
+                             const std::u16string& message);
+  void ShowNotification(const std::string& id,
+                        const std::u16string& title,
+                        const std::u16string& message,
+                        message_center::RichNotificationData optional_fields);
 
   void FlushForTesting();
 
-  message_center::MessageCenter* message_center_;
-  service_manager::Connector* connector_;
+  // Indicates if Phone Hub icon is clicked when the setup notification is
+  // visible. If the value is true, we do not log event to
+  // MultiDevice.Setup.NotificationInteracted histogram.
+  bool is_setup_notification_interacted_ = false;
+
+  raw_ptr<message_center::MessageCenter, ExperimentalAsh> message_center_;
 
   // Notification currently showing or
   // Status::kNoNotificationVisible if there isn't one.
   Status notification_status_ = Status::kNoNotificationVisible;
 
-  chromeos::multidevice_setup::mojom::MultiDeviceSetupPtr
-      multidevice_setup_ptr_;
-  mojo::Binding<chromeos::multidevice_setup::mojom::AccountStatusChangeDelegate>
-      binding_;
-
-  std::unique_ptr<OpenUiDelegate> open_ui_delegate_;
-  base::WeakPtrFactory<MultiDeviceNotificationPresenter> weak_ptr_factory_;
+  mojo::Remote<multidevice_setup::mojom::MultiDeviceSetup>
+      multidevice_setup_remote_;
+  mojo::Receiver<multidevice_setup::mojom::AccountStatusChangeDelegate>
+      receiver_{this};
 
-  DISALLOW_COPY_AND_ASSIGN(MultiDeviceNotificationPresenter);
+  base::WeakPtrFactory<MultiDeviceNotificationPresenter> weak_ptr_factory_{
+      this};
 };
 
 }  // namespace ash