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

Side by Side Diff: chrome/browser/notifications/stub_notification_display_service.cc

Issue 2941743002: Revert of Deprecate native and extension notification delegates. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/stub_notification_display_service.h" 5 #include "chrome/browser/notifications/stub_notification_display_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/notifications/notification_handler.h"
11 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
12 11
13 // static 12 // static
14 std::unique_ptr<KeyedService> StubNotificationDisplayService::FactoryForTests( 13 std::unique_ptr<KeyedService> StubNotificationDisplayService::FactoryForTests(
15 content::BrowserContext* context) { 14 content::BrowserContext* context) {
16 return base::MakeUnique<StubNotificationDisplayService>( 15 return base::MakeUnique<StubNotificationDisplayService>(
17 Profile::FromBrowserContext(context)); 16 Profile::FromBrowserContext(context));
18 } 17 }
19 18
20 StubNotificationDisplayService::StubNotificationDisplayService(Profile* profile) 19 StubNotificationDisplayService::StubNotificationDisplayService(Profile* profile)
21 : NotificationDisplayService(profile), profile_(profile) {} 20 : NotificationDisplayService(profile) {}
22 21
23 StubNotificationDisplayService::~StubNotificationDisplayService() = default; 22 StubNotificationDisplayService::~StubNotificationDisplayService() = default;
24 23
25 void StubNotificationDisplayService::RemoveNotification( 24 void StubNotificationDisplayService::RemoveNotification(
26 NotificationCommon::Type notification_type, 25 NotificationCommon::Type notification_type,
27 const std::string& notification_id, 26 const std::string& notification_id,
28 bool by_user) { 27 bool by_user) {
29 auto iter = std::find_if( 28 auto iter = std::find_if(
30 notifications_.begin(), notifications_.end(), 29 notifications_.begin(), notifications_.end(),
31 [notification_type, notification_id](const NotificationData& data) { 30 [notification_type, notification_id](const NotificationData& data) {
32 return data.first == notification_type && 31 return data.first == notification_type &&
33 data.second.delegate_id() == notification_id; 32 data.second.delegate_id() == notification_id;
34 }); 33 });
35 34
36 if (iter == notifications_.end()) 35 if (iter == notifications_.end())
37 return; 36 return;
38 37
39 NotificationHandler* handler = GetNotificationHandler(notification_type); 38 // TODO(peter): Invoke the handlers when that has been generalized.
40 DCHECK(handler); 39 iter->second.delegate()->Close(by_user);
41 handler->OnClose(profile_, iter->second.origin_url().spec(), notification_id, 40
42 by_user);
43 notifications_.erase(iter); 41 notifications_.erase(iter);
44 } 42 }
45 43
46 void StubNotificationDisplayService::RemoveAllNotifications( 44 void StubNotificationDisplayService::RemoveAllNotifications(
47 NotificationCommon::Type notification_type, 45 NotificationCommon::Type notification_type,
48 bool by_user) { 46 bool by_user) {
49 NotificationHandler* handler = GetNotificationHandler(notification_type);
50 DCHECK(handler);
51 for (auto iter = notifications_.begin(); iter != notifications_.end();) { 47 for (auto iter = notifications_.begin(); iter != notifications_.end();) {
52 if (iter->first == notification_type) { 48 if (iter->first == notification_type) {
53 handler->OnClose(profile_, iter->second.origin_url().spec(), 49 // TODO(peter): Invoke the handlers when that has been generalized.
54 iter->second.id(), by_user); 50 iter->second.delegate()->Close(by_user);
51
55 iter = notifications_.erase(iter); 52 iter = notifications_.erase(iter);
56 } else { 53 } else {
57 iter++; 54 iter++;
58 } 55 }
59 } 56 }
60 } 57 }
61 58
62 void StubNotificationDisplayService::Display( 59 void StubNotificationDisplayService::Display(
63 NotificationCommon::Type notification_type, 60 NotificationCommon::Type notification_type,
64 const std::string& notification_id, 61 const std::string& notification_id,
(...skipping 21 matching lines...) Expand all
86 void StubNotificationDisplayService::GetDisplayed( 83 void StubNotificationDisplayService::GetDisplayed(
87 const DisplayedNotificationsCallback& callback) { 84 const DisplayedNotificationsCallback& callback) {
88 std::unique_ptr<std::set<std::string>> notifications = 85 std::unique_ptr<std::set<std::string>> notifications =
89 base::MakeUnique<std::set<std::string>>(); 86 base::MakeUnique<std::set<std::string>>();
90 87
91 for (const auto& notification_data : notifications_) 88 for (const auto& notification_data : notifications_)
92 notifications->insert(notification_data.second.delegate_id()); 89 notifications->insert(notification_data.second.delegate_id());
93 90
94 callback.Run(std::move(notifications), true /* supports_synchronization */); 91 callback.Run(std::move(notifications), true /* supports_synchronization */);
95 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698