Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3576)

Unified Diff: chrome/browser/notifications/stub_notification_display_service.cc

Issue 2703213004: Migrate extension notifications to the new NotificationDisplayService (Closed)
Patch Set: Migrate extension notifications to the new NotificationDisplayService Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/stub_notification_display_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/stub_notification_display_service.cc
diff --git a/chrome/browser/notifications/stub_notification_display_service.cc b/chrome/browser/notifications/stub_notification_display_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..981d47206592fbfc2a84a7e91485343417f2da35
--- /dev/null
+++ b/chrome/browser/notifications/stub_notification_display_service.cc
@@ -0,0 +1,89 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/stub_notification_display_service.h"
+
+#include <algorithm>
+
+#include "base/memory/ptr_util.h"
+
+// static
+std::unique_ptr<KeyedService> StubNotificationDisplayService::FactoryForTests(
+ content::BrowserContext* /* browser_context */) {
+ return base::MakeUnique<StubNotificationDisplayService>();
+}
+
+StubNotificationDisplayService::StubNotificationDisplayService() = default;
+
+StubNotificationDisplayService::~StubNotificationDisplayService() = default;
+
+void StubNotificationDisplayService::RemoveNotification(
+ NotificationCommon::Type notification_type,
+ const std::string& notification_id,
+ bool by_user) {
+ auto iter = std::find_if(
+ notifications_.begin(), notifications_.end(),
+ [notification_type, notification_id](const NotificationData& data) {
+ return data.first == notification_type &&
+ data.second.delegate_id() == notification_id;
+ });
+
+ if (iter == notifications_.end())
+ return;
+
+ // TODO(peter): Invoke the handlers when that has been generalized.
+ iter->second.delegate()->Close(by_user);
+
+ notifications_.erase(iter);
+}
+
+void StubNotificationDisplayService::RemoveAllNotifications(
+ NotificationCommon::Type notification_type,
+ bool by_user) {
+ for (auto iter = notifications_.begin(); iter != notifications_.end();) {
+ if (iter->first == notification_type) {
+ // TODO(peter): Invoke the handlers when that has been generalized.
+ iter->second.delegate()->Close(by_user);
+
+ iter = notifications_.erase(iter);
+ } else {
+ iter++;
+ }
+ }
+}
+
+void StubNotificationDisplayService::Display(
+ NotificationCommon::Type notification_type,
+ const std::string& notification_id,
+ const Notification& notification) {
+ // This mimics notification replacement behaviour; the Close() method on a
+ // notification's delegate is not meant to be invoked in this situation.
+ Close(notification_type, notification_id);
+
+ notifications_.emplace_back(notification_type, notification);
+}
+
+void StubNotificationDisplayService::Close(
+ NotificationCommon::Type notification_type,
+ const std::string& notification_id) {
+ notifications_.erase(
+ std::remove_if(
+ notifications_.begin(), notifications_.end(),
+ [notification_type, notification_id](const NotificationData& data) {
+ return data.first == notification_type &&
+ data.second.delegate_id() == notification_id;
+ }),
+ notifications_.end());
+}
+
+void StubNotificationDisplayService::GetDisplayed(
+ const DisplayedNotificationsCallback& callback) const {
+ std::unique_ptr<std::set<std::string>> notifications =
+ base::MakeUnique<std::set<std::string>>();
+
+ for (const auto& notification_data : notifications_)
+ notifications->insert(notification_data.second.delegate_id());
+
+ callback.Run(std::move(notifications), true /* supports_synchronization */);
+}
« no previous file with comments | « chrome/browser/notifications/stub_notification_display_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698