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

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

Issue 2921263002: Remove many delegates, let's see what breaks
Patch Set: fix test 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"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 12
12 // static 13 // static
13 std::unique_ptr<KeyedService> StubNotificationDisplayService::FactoryForTests( 14 std::unique_ptr<KeyedService> StubNotificationDisplayService::FactoryForTests(
14 content::BrowserContext* context) { 15 content::BrowserContext* context) {
15 return base::MakeUnique<StubNotificationDisplayService>( 16 return base::MakeUnique<StubNotificationDisplayService>(
16 Profile::FromBrowserContext(context)); 17 Profile::FromBrowserContext(context));
17 } 18 }
18 19
19 StubNotificationDisplayService::StubNotificationDisplayService(Profile* profile) 20 StubNotificationDisplayService::StubNotificationDisplayService(Profile* profile)
20 : NotificationDisplayService(profile) {} 21 : NotificationDisplayService(profile), profile_(profile) {}
21 22
22 StubNotificationDisplayService::~StubNotificationDisplayService() = default; 23 StubNotificationDisplayService::~StubNotificationDisplayService() = default;
23 24
24 void StubNotificationDisplayService::RemoveNotification( 25 void StubNotificationDisplayService::RemoveNotification(
25 NotificationCommon::Type notification_type, 26 NotificationCommon::Type notification_type,
26 const std::string& notification_id, 27 const std::string& notification_id,
27 bool by_user) { 28 bool by_user) {
28 auto iter = std::find_if( 29 auto iter = std::find_if(
29 notifications_.begin(), notifications_.end(), 30 notifications_.begin(), notifications_.end(),
30 [notification_type, notification_id](const NotificationData& data) { 31 [notification_type, notification_id](const NotificationData& data) {
31 return data.first == notification_type && 32 return data.first == notification_type &&
32 data.second.delegate_id() == notification_id; 33 data.second.delegate_id() == notification_id;
33 }); 34 });
34 35
35 if (iter == notifications_.end()) 36 if (iter == notifications_.end())
36 return; 37 return;
37 38
38 // TODO(peter): Invoke the handlers when that has been generalized. 39 NotificationHandler* handler = GetNotificationHandler(notification_type);
39 iter->second.delegate()->Close(by_user); 40 DCHECK(handler);
40 41 handler->OnClose(profile_, iter->second.origin_url().spec(), notification_id,
42 by_user);
41 notifications_.erase(iter); 43 notifications_.erase(iter);
42 } 44 }
43 45
44 void StubNotificationDisplayService::RemoveAllNotifications( 46 void StubNotificationDisplayService::RemoveAllNotifications(
45 NotificationCommon::Type notification_type, 47 NotificationCommon::Type notification_type,
46 bool by_user) { 48 bool by_user) {
49 NotificationHandler* handler = GetNotificationHandler(notification_type);
50 DCHECK(handler);
47 for (auto iter = notifications_.begin(); iter != notifications_.end();) { 51 for (auto iter = notifications_.begin(); iter != notifications_.end();) {
48 if (iter->first == notification_type) { 52 if (iter->first == notification_type) {
49 // TODO(peter): Invoke the handlers when that has been generalized. 53 handler->OnClose(profile_, iter->second.origin_url().spec(),
50 iter->second.delegate()->Close(by_user); 54 iter->second.id(), by_user);
51
52 iter = notifications_.erase(iter); 55 iter = notifications_.erase(iter);
53 } else { 56 } else {
54 iter++; 57 iter++;
55 } 58 }
56 } 59 }
57 } 60 }
58 61
59 void StubNotificationDisplayService::Display( 62 void StubNotificationDisplayService::Display(
60 NotificationCommon::Type notification_type, 63 NotificationCommon::Type notification_type,
61 const std::string& notification_id, 64 const std::string& notification_id,
(...skipping 21 matching lines...) Expand all
83 void StubNotificationDisplayService::GetDisplayed( 86 void StubNotificationDisplayService::GetDisplayed(
84 const DisplayedNotificationsCallback& callback) { 87 const DisplayedNotificationsCallback& callback) {
85 std::unique_ptr<std::set<std::string>> notifications = 88 std::unique_ptr<std::set<std::string>> notifications =
86 base::MakeUnique<std::set<std::string>>(); 89 base::MakeUnique<std::set<std::string>>();
87 90
88 for (const auto& notification_data : notifications_) 91 for (const auto& notification_data : notifications_)
89 notifications->insert(notification_data.second.delegate_id()); 92 notifications->insert(notification_data.second.delegate_id());
90 93
91 callback.Run(std::move(notifications), true /* supports_synchronization */); 94 callback.Run(std::move(notifications), true /* supports_synchronization */);
92 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698