| OLD | NEW |
| 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" | |
| 17 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 20 | 19 |
| 21 BalloonNotificationUIManager::BalloonNotificationUIManager( | 20 BalloonNotificationUIManager::BalloonNotificationUIManager( |
| 22 PrefService* local_state) | 21 PrefService* local_state) |
| 23 : NotificationUIManagerImpl(), | 22 : NotificationUIManagerImpl(), |
| 24 NotificationPrefsManager(local_state), | 23 NotificationPrefsManager(local_state), |
| 25 balloon_collection_(NULL) { | 24 balloon_collection_(NULL) { |
| 26 position_pref_.Init( | 25 position_pref_.Init( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 } | 52 } |
| 54 | 53 |
| 55 bool BalloonNotificationUIManager::CancelById(const std::string& id) { | 54 bool BalloonNotificationUIManager::CancelById(const std::string& id) { |
| 56 // See if this ID hasn't been shown yet. | 55 // See if this ID hasn't been shown yet. |
| 57 if (NotificationUIManagerImpl::CancelById(id)) | 56 if (NotificationUIManagerImpl::CancelById(id)) |
| 58 return true; | 57 return true; |
| 59 // If it has been shown, remove it from the balloon collections. | 58 // If it has been shown, remove it from the balloon collections. |
| 60 return balloon_collection_->RemoveById(id); | 59 return balloon_collection_->RemoveById(id); |
| 61 } | 60 } |
| 62 | 61 |
| 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 | |
| 83 bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { | 62 bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { |
| 84 // Same pattern as CancelById, but more complicated than the above | 63 // Same pattern as CancelById, but more complicated than the above |
| 85 // because there may be multiple notifications from the same source. | 64 // because there may be multiple notifications from the same source. |
| 86 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); | 65 bool removed = NotificationUIManagerImpl::CancelAllBySourceOrigin(source); |
| 87 return balloon_collection_->RemoveBySourceOrigin(source) || removed; | 66 return balloon_collection_->RemoveBySourceOrigin(source) || removed; |
| 88 } | 67 } |
| 89 | 68 |
| 90 bool BalloonNotificationUIManager::CancelAllByProfile(Profile* profile) { | 69 bool BalloonNotificationUIManager::CancelAllByProfile(Profile* profile) { |
| 91 // Same pattern as CancelAllBySourceOrigin. | 70 // Same pattern as CancelAllBySourceOrigin. |
| 92 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); | 71 bool removed = NotificationUIManagerImpl::CancelAllByProfile(profile); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 BalloonNotificationUIManager::GetInstanceForTesting() { | 147 BalloonNotificationUIManager::GetInstanceForTesting() { |
| 169 if (NotificationUIManager::DelegatesToMessageCenter()) { | 148 if (NotificationUIManager::DelegatesToMessageCenter()) { |
| 170 LOG(ERROR) << "Attempt to run a test that requires " | 149 LOG(ERROR) << "Attempt to run a test that requires " |
| 171 << "BalloonNotificationUIManager while delegating to a " | 150 << "BalloonNotificationUIManager while delegating to a " |
| 172 << "native MessageCenter. Test will fail. Ask dimich@"; | 151 << "native MessageCenter. Test will fail. Ask dimich@"; |
| 173 return NULL; | 152 return NULL; |
| 174 } | 153 } |
| 175 return static_cast<BalloonNotificationUIManager*>( | 154 return static_cast<BalloonNotificationUIManager*>( |
| 176 g_browser_process->notification_ui_manager()); | 155 g_browser_process->notification_ui_manager()); |
| 177 } | 156 } |
| OLD | NEW |