Commit 57750511 authored by wutao's avatar wutao Committed by Commit Bot

Assistant: Keep all notifications

This patch keeps all the assistant notifications in message center.

Bug: b/79493568
Test: manual.
Change-Id: If877634199fb1a0a7a269fe273d0cf6f3283cc15
Reviewed-on: https://chromium-review.googlesource.com/1137487Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575498}
parent 22e0cc79
...@@ -76,12 +76,22 @@ class AssistantNotificationDelegate ...@@ -76,12 +76,22 @@ class AssistantNotificationDelegate
DISALLOW_COPY_AND_ASSIGN(AssistantNotificationDelegate); DISALLOW_COPY_AND_ASSIGN(AssistantNotificationDelegate);
}; };
std::string GetNotificationId(const std::string& grouping_key) {
return kNotificationId + grouping_key;
}
message_center::NotifierId GetNotifierId() {
return message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT, kNotifierAssistant);
}
} // namespace } // namespace
AssistantNotificationController::AssistantNotificationController( AssistantNotificationController::AssistantNotificationController(
AssistantController* assistant_controller) AssistantController* assistant_controller)
: assistant_controller_(assistant_controller), : assistant_controller_(assistant_controller),
assistant_notification_subscriber_binding_(this), assistant_notification_subscriber_binding_(this),
notifier_id_(GetNotifierId()),
weak_factory_(this) {} weak_factory_(this) {}
AssistantNotificationController::~AssistantNotificationController() = default; AssistantNotificationController::~AssistantNotificationController() = default;
...@@ -113,9 +123,8 @@ void AssistantNotificationController::OnShowNotification( ...@@ -113,9 +123,8 @@ void AssistantNotificationController::OnShowNotification(
// Create the specified |notification| that should be rendered in the // Create the specified |notification| that should be rendered in the
// |message_center| for the interaction. // |message_center| for the interaction.
notification_ = std::move(notification); const base::string16 title = base::UTF8ToUTF16(notification->title);
const base::string16 title = base::UTF8ToUTF16(notification_->title); const base::string16 message = base::UTF8ToUTF16(notification->message);
const base::string16 message = base::UTF8ToUTF16(notification_->message);
const base::string16 display_source = const base::string16 display_source =
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_NOTIFICATION_DISPLAY_SOURCE); l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_NOTIFICATION_DISPLAY_SOURCE);
...@@ -125,14 +134,12 @@ void AssistantNotificationController::OnShowNotification( ...@@ -125,14 +134,12 @@ void AssistantNotificationController::OnShowNotification(
std::unique_ptr<message_center::Notification> system_notification = std::unique_ptr<message_center::Notification> system_notification =
message_center::Notification::CreateSystemNotification( message_center::Notification::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, title, message_center::NOTIFICATION_TYPE_SIMPLE,
message, gfx::Image(), display_source, GURL(), GetNotificationId(notification->grouping_key), title, message,
message_center::NotifierId( gfx::Image(), display_source, GURL(), notifier_id_, optional_field,
message_center::NotifierId::SYSTEM_COMPONENT, kNotifierAssistant),
optional_field,
new AssistantNotificationDelegate(weak_factory_.GetWeakPtr(), new AssistantNotificationDelegate(weak_factory_.GetWeakPtr(),
assistant_controller_->GetWeakPtr(), assistant_controller_->GetWeakPtr(),
notification_.Clone()), notification.Clone()),
kAssistantIcon, kAssistantIcon,
message_center::SystemNotificationWarningLevel::NORMAL); message_center::SystemNotificationWarningLevel::NORMAL);
system_notification->set_priority(message_center::DEFAULT_PRIORITY); system_notification->set_priority(message_center::DEFAULT_PRIORITY);
...@@ -141,17 +148,17 @@ void AssistantNotificationController::OnShowNotification( ...@@ -141,17 +148,17 @@ void AssistantNotificationController::OnShowNotification(
void AssistantNotificationController::OnRemoveNotification( void AssistantNotificationController::OnRemoveNotification(
const std::string& grouping_key) { const std::string& grouping_key) {
if (!grouping_key.empty() &&
(!notification_ || notification_->grouping_key != grouping_key)) {
return;
}
// message_center has only one Assistant notification, so there is no
// difference between removing all and removing one Assistant notification.
notification_.reset();
message_center::MessageCenter* message_center = message_center::MessageCenter* message_center =
message_center::MessageCenter::Get(); message_center::MessageCenter::Get();
message_center->RemoveNotification(kNotificationId, /*by_user=*/false); if (grouping_key.empty()) {
// Remove all assistant notifications by NotifierId.
message_center->RemoveNotificationsForNotifierId(notifier_id_);
} else {
// Remove the notification with |grouping_key|. It is no-op if no
// corresponding notification is found in |message_center|.
message_center->RemoveNotification(GetNotificationId(grouping_key),
/*by_user=*/false);
}
} }
} // namespace ash } // namespace ash
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "ui/message_center/public/cpp/notifier_id.h"
namespace ash { namespace ash {
...@@ -48,8 +49,7 @@ class ASH_EXPORT AssistantNotificationController ...@@ -48,8 +49,7 @@ class ASH_EXPORT AssistantNotificationController
// Owned by AssistantController. // Owned by AssistantController.
chromeos::assistant::mojom::Assistant* assistant_ = nullptr; chromeos::assistant::mojom::Assistant* assistant_ = nullptr;
// Save the latest notification for future retrieval or dismiss operations. const message_center::NotifierId notifier_id_;
AssistantNotificationPtr notification_;
base::WeakPtrFactory<AssistantNotificationController> weak_factory_; base::WeakPtrFactory<AssistantNotificationController> weak_factory_;
......
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