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

Unified Diff: content/test/mock_platform_notification_service.cc

Issue 2906883003: Deprecate per notification type delegates. (Closed)
Patch Set: review Created 3 years, 6 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 | « content/test/mock_platform_notification_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/mock_platform_notification_service.cc
diff --git a/content/test/mock_platform_notification_service.cc b/content/test/mock_platform_notification_service.cc
index 47990a26fa89ce4a54846224f3b6c6161b350c74..58db6968fe6370e92f3b5b40d25727755656d135 100644
--- a/content/test/mock_platform_notification_service.cc
+++ b/content/test/mock_platform_notification_service.cc
@@ -8,7 +8,6 @@
#include "base/strings/nullable_string16.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/browser/notification_event_dispatcher.h"
#include "content/public/browser/permission_type.h"
#include "content/public/common/persistent_notification_status.h"
@@ -34,7 +33,6 @@ void MockPlatformNotificationService::DisplayNotification(
const GURL& origin,
const PlatformNotificationData& notification_data,
const NotificationResources& notification_resources,
- std::unique_ptr<DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(cancel_callback);
@@ -43,10 +41,10 @@ void MockPlatformNotificationService::DisplayNotification(
weak_factory_.GetWeakPtr(), notification_id);
ReplaceNotificationIfNeeded(notification_id);
+ non_persistent_notifications_.insert(notification_id);
- non_persistent_notifications_[notification_id] = std::move(delegate);
- non_persistent_notifications_[notification_id]->NotificationDisplayed();
-
+ NotificationEventDispatcher::GetInstance()->DispatchNonPersistentShowEvent(
+ notification_id);
notification_id_map_[base::UTF16ToUTF8(notification_data.title)] =
notification_id;
}
@@ -90,7 +88,7 @@ void MockPlatformNotificationService::GetDisplayedNotifications(
displayed_notifications->insert(kv.first);
BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
+ BrowserThread::UI, FROM_HERE,
base::Bind(callback, base::Passed(&displayed_notifications),
true /* supports_synchronization */));
}
@@ -100,7 +98,6 @@ void MockPlatformNotificationService::SimulateClick(
int action_index,
const base::NullableString16& reply) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
const auto notification_id_iter = notification_id_map_.find(title);
if (notification_id_iter == notification_id_map_.end())
return;
@@ -115,15 +112,14 @@ void MockPlatformNotificationService::SimulateClick(
DCHECK(non_persistent_iter == non_persistent_notifications_.end());
const PersistentNotification& notification = persistent_iter->second;
- content::NotificationEventDispatcher::GetInstance()
- ->DispatchNotificationClickEvent(
- notification.browser_context, notification_id, notification.origin,
- action_index, reply, base::Bind(&OnEventDispatchComplete));
+ NotificationEventDispatcher::GetInstance()->DispatchNotificationClickEvent(
+ notification.browser_context, notification_id, notification.origin,
+ action_index, reply, base::Bind(&OnEventDispatchComplete));
} else if (non_persistent_iter != non_persistent_notifications_.end()) {
DCHECK_EQ(action_index, -1) << "Action buttons are only supported for "
"persistent notifications";
-
- non_persistent_iter->second->NotificationClick();
+ NotificationEventDispatcher::GetInstance()->DispatchNonPersistentClickEvent(
+ notification_id);
}
}
@@ -142,10 +138,9 @@ void MockPlatformNotificationService::SimulateClose(const std::string& title,
return;
const PersistentNotification& notification = persistent_iter->second;
- content::NotificationEventDispatcher::GetInstance()
- ->DispatchNotificationCloseEvent(
- notification.browser_context, notification_id, notification.origin,
- by_user, base::Bind(&OnEventDispatchComplete));
+ NotificationEventDispatcher::GetInstance()->DispatchNotificationCloseEvent(
+ notification.browser_context, notification_id, notification.origin,
+ by_user, base::Bind(&OnEventDispatchComplete));
}
blink::mojom::PermissionStatus
@@ -169,28 +164,21 @@ MockPlatformNotificationService::CheckPermissionOnIOThread(
void MockPlatformNotificationService::Close(
const std::string& notification_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- auto iterator = non_persistent_notifications_.find(notification_id);
- if (iterator == non_persistent_notifications_.end())
- return;
-
- iterator->second->NotificationClosed();
-}
-
-void MockPlatformNotificationService::ReplaceNotificationIfNeeded(
- const std::string& notification_id) {
- const auto persistent_iter = persistent_notifications_.find(notification_id);
const auto non_persistent_iter =
non_persistent_notifications_.find(notification_id);
-
- if (persistent_iter != persistent_notifications_.end()) {
- DCHECK(non_persistent_iter == non_persistent_notifications_.end());
- persistent_notifications_.erase(persistent_iter);
- } else if (non_persistent_iter != non_persistent_notifications_.end()) {
- non_persistent_iter->second->NotificationClosed();
+ if (non_persistent_iter == non_persistent_notifications_.end()) {
+ NotificationEventDispatcher::GetInstance()->DispatchNonPersistentCloseEvent(
+ notification_id);
non_persistent_notifications_.erase(non_persistent_iter);
}
}
+void MockPlatformNotificationService::ReplaceNotificationIfNeeded(
+ const std::string& notification_id) {
+ persistent_notifications_.erase(notification_id);
+ non_persistent_notifications_.erase(notification_id);
+}
+
blink::mojom::PermissionStatus MockPlatformNotificationService::CheckPermission(
const GURL& origin) {
return blink::mojom::PermissionStatus::GRANTED;
« no previous file with comments | « content/test/mock_platform_notification_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698