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

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

Issue 2749453002: Make GetDisplayedNotifications asynchronous. (Closed)
Patch Set: review Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_platform_bridge.h" 5 #include "chrome/browser/notifications/stub_notification_platform_bridge.h"
6 6
7 #include "base/memory/ptr_util.h"
8 #include "content/public/browser/browser_thread.h"
9
7 StubNotificationPlatformBridge::StubNotificationPlatformBridge() 10 StubNotificationPlatformBridge::StubNotificationPlatformBridge()
8 : NotificationPlatformBridge() {} 11 : NotificationPlatformBridge() {}
9 12
10 StubNotificationPlatformBridge::~StubNotificationPlatformBridge() {} 13 StubNotificationPlatformBridge::~StubNotificationPlatformBridge() {}
11 14
12 Notification StubNotificationPlatformBridge::GetNotificationAt( 15 Notification StubNotificationPlatformBridge::GetNotificationAt(
13 std::string profile_id, 16 std::string profile_id,
14 size_t index) { 17 size_t index) {
15 DCHECK(notifications_.find(profile_id) != notifications_.end()); 18 DCHECK(notifications_.find(profile_id) != notifications_.end());
16 DCHECK_GT(notifications_[profile_id].size(), index); 19 DCHECK_GT(notifications_[profile_id].size(), index);
17 20
18 return notifications_[profile_id][index]; 21 return notifications_[profile_id][index];
19 } 22 }
20 23
24 size_t StubNotificationPlatformBridge::GetNotificationCount() {
25 int count = 0;
26 for (const auto& pair : notifications_) {
27 count += pair.second.size();
28 }
29 return count;
30 }
31
21 void StubNotificationPlatformBridge::Display( 32 void StubNotificationPlatformBridge::Display(
22 NotificationCommon::Type notification_type, 33 NotificationCommon::Type notification_type,
23 const std::string& notification_id, 34 const std::string& notification_id,
24 const std::string& profile_id, 35 const std::string& profile_id,
25 bool incognito, 36 bool incognito,
26 const Notification& notification) { 37 const Notification& notification) {
27 notifications_[profile_id].push_back(notification); 38 notifications_[profile_id].push_back(notification);
28 } 39 }
29 40
30 void StubNotificationPlatformBridge::Close(const std::string& profile_id, 41 void StubNotificationPlatformBridge::Close(const std::string& profile_id,
31 const std::string& notification_id) { 42 const std::string& notification_id) {
32 if (notifications_.find(profile_id) == notifications_.end()) 43 if (notifications_.find(profile_id) == notifications_.end())
33 return; 44 return;
34 std::vector<Notification> profile_notifications = notifications_[profile_id]; 45 std::vector<Notification> profile_notifications = notifications_[profile_id];
35 for (auto iter = profile_notifications.begin(); 46 for (auto iter = profile_notifications.begin();
36 iter != profile_notifications.end(); ++iter) { 47 iter != profile_notifications.end(); ++iter) {
37 if (iter->id() == notification_id) { 48 if (iter->id() == notification_id) {
38 profile_notifications.erase(iter); 49 profile_notifications.erase(iter);
39 if (profile_notifications.empty()) 50 if (profile_notifications.empty())
40 notifications_.erase(profile_id); 51 notifications_.erase(profile_id);
41 break; 52 break;
42 } 53 }
43 } 54 }
44 } 55 }
45 56
46 bool StubNotificationPlatformBridge::GetDisplayed( 57 void StubNotificationPlatformBridge::GetDisplayed(
47 const std::string& profile_id, 58 const std::string& profile_id,
48 bool incognito, 59 bool incognito,
49 std::set<std::string>* notifications) const { 60 const DisplayedNotificationsCallback& callback) const {
50 if (notifications_.find(profile_id) == notifications_.end()) 61 auto displayed_notifications = base::MakeUnique<std::set<std::string>>();
51 return true;
52 62
53 const std::vector<Notification>& profile_notifications = 63 if (notifications_.find(profile_id) != notifications_.end()) {
54 notifications_.at(profile_id); 64 const std::vector<Notification>& profile_notifications =
55 for (auto notification : profile_notifications) 65 notifications_.at(profile_id);
56 notifications->insert(notification.id()); 66 for (auto notification : profile_notifications)
57 return true; 67 displayed_notifications->insert(notification.id());
68 }
69
70 content::BrowserThread::PostTask(
71 content::BrowserThread::UI, FROM_HERE,
72 base::Bind(callback, base::Passed(&displayed_notifications),
73 true /* supports_synchronization */));
58 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698