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

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

Issue 14767029: Add API function chrome.notifications.getAll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/balloon_notification_ui_manager.h" 5 #include "chrome/browser/notifications/balloon_notification_ui_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/fullscreen.h" 12 #include "chrome/browser/fullscreen.h"
13 #include "chrome/browser/idle.h" 13 #include "chrome/browser/idle.h"
14 #include "chrome/browser/notifications/balloon_collection.h" 14 #include "chrome/browser/notifications/balloon_collection.h"
15 #include "chrome/browser/notifications/notification.h" 15 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 20
20 BalloonNotificationUIManager::BalloonNotificationUIManager( 21 BalloonNotificationUIManager::BalloonNotificationUIManager(
21 PrefService* local_state) 22 PrefService* local_state)
22 : NotificationUIManagerImpl(), 23 : NotificationUIManagerImpl(),
23 NotificationPrefsManager(local_state), 24 NotificationPrefsManager(local_state),
24 balloon_collection_(NULL) { 25 balloon_collection_(NULL) {
25 position_pref_.Init( 26 position_pref_.Init(
(...skipping 26 matching lines...) Expand all
52 } 53 }
53 54
54 bool BalloonNotificationUIManager::CancelById(const std::string& id) { 55 bool BalloonNotificationUIManager::CancelById(const std::string& id) {
55 // See if this ID hasn't been shown yet. 56 // See if this ID hasn't been shown yet.
56 if (NotificationUIManagerImpl::CancelById(id)) 57 if (NotificationUIManagerImpl::CancelById(id))
57 return true; 58 return true;
58 // If it has been shown, remove it from the balloon collections. 59 // If it has been shown, remove it from the balloon collections.
59 return balloon_collection_->RemoveById(id); 60 return balloon_collection_->RemoveById(id);
60 } 61 }
61 62
63 std::set<std::string>
64 BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
65 Profile* profile,
66 const GURL& source) {
67 std::set<std::string> notification_ids =
68 NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile,
69 source);
70
71 const BalloonCollection::Balloons& balloons =
72 balloon_collection_->GetActiveBalloons();
73 for (BalloonCollection::Balloons::const_iterator iter = balloons.begin();
74 iter != balloons.end(); ++iter) {
75 if (profile->IsSameProfile((*iter)->profile()) &&
76 source == (*iter)->notification().origin_url()) {
77 notification_ids.insert((*iter)->notification().notification_id());
78 }
79 }
80 return notification_ids;
81 }
82
62 bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { 83 bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) {
63 // Same pattern as CancelById, but more complicated than the above 84 // Same pattern as CancelById, but more complicated than the above
64 // because there may be multiple notifications from the same source. 85 // because there may be multiple notifications from the same source.
65 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); 86 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source);
66 return balloon_collection_->RemoveBySourceOrigin(source) || removed; 87 return balloon_collection_->RemoveBySourceOrigin(source) || removed;
67 } 88 }
68 89
69 bool BalloonNotificationUIManager::CancelAllByProfile(Profile* profile) { 90 bool BalloonNotificationUIManager::CancelAllByProfile(Profile* profile) {
70 // Same pattern as CancelAllBySourceOrigin. 91 // Same pattern as CancelAllBySourceOrigin.
71 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); 92 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 BalloonNotificationUIManager::GetInstanceForTesting() { 168 BalloonNotificationUIManager::GetInstanceForTesting() {
148 if (NotificationUIManager::DelegatesToMessageCenter()) { 169 if (NotificationUIManager::DelegatesToMessageCenter()) {
149 LOG(ERROR) << "Attempt to run a test that requires " 170 LOG(ERROR) << "Attempt to run a test that requires "
150 << "BalloonNotificationUIManager while delegating to a " 171 << "BalloonNotificationUIManager while delegating to a "
151 << "native MessageCenter. Test will fail. Ask dimich@"; 172 << "native MessageCenter. Test will fail. Ask dimich@";
152 return NULL; 173 return NULL;
153 } 174 }
154 return static_cast<BalloonNotificationUIManager*>( 175 return static_cast<BalloonNotificationUIManager*>(
155 g_browser_process->notification_ui_manager()); 176 g_browser_process->notification_ui_manager());
156 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698