| 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/message_center_notification_manager.h" | 5 #include "chrome/browser/notifications/message_center_notification_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 "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/notifications/desktop_notification_service.h" | 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 14 #include "chrome/browser/notifications/message_center_settings_controller.h" | 15 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/browser/ui/host_desktop.h" | 20 #include "chrome/browser/ui/host_desktop.h" |
| 20 #include "chrome/common/extensions/extension_set.h" | 21 #include "chrome/common/extensions/extension_set.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/user_metrics.h" |
| 22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
| 24 #include "ui/message_center/message_center_style.h" | 27 #include "ui/message_center/message_center_style.h" |
| 25 #include "ui/message_center/message_center_tray.h" | 28 #include "ui/message_center/message_center_tray.h" |
| 26 #include "ui/message_center/notifier_settings.h" | 29 #include "ui/message_center/notifier_settings.h" |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all | 32 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all |
| 30 // popups go away and the user has notifications in the message center. | 33 // popups go away and the user has notifications in the message center. |
| 31 const int kFirstRunIdleDelaySeconds = 1; | 34 const int kFirstRunIdleDelaySeconds = 1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 message_center_->SetDelegate(this); | 51 message_center_->SetDelegate(this); |
| 49 message_center_->AddObserver(this); | 52 message_center_->AddObserver(this); |
| 50 message_center_->SetNotifierSettingsProvider(settings_controller_.get()); | 53 message_center_->SetNotifierSettingsProvider(settings_controller_.get()); |
| 51 | 54 |
| 52 #if defined(OS_WIN) || defined(OS_MACOSX) \ | 55 #if defined(OS_WIN) || defined(OS_MACOSX) \ |
| 53 || (defined(USE_AURA) && !defined(USE_ASH)) | 56 || (defined(USE_AURA) && !defined(USE_ASH)) |
| 54 // On Windows, Linux and Mac, the notification manager owns the tray icon and | 57 // On Windows, Linux and Mac, the notification manager owns the tray icon and |
| 55 // views.Other platforms have global ownership and Create will return NULL. | 58 // views.Other platforms have global ownership and Create will return NULL. |
| 56 tray_.reset(message_center::CreateMessageCenterTray()); | 59 tray_.reset(message_center::CreateMessageCenterTray()); |
| 57 #endif | 60 #endif |
| 61 registrar_.Add(this, |
| 62 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 63 content::NotificationService::AllSources()); |
| 58 } | 64 } |
| 59 | 65 |
| 60 MessageCenterNotificationManager::~MessageCenterNotificationManager() { | 66 MessageCenterNotificationManager::~MessageCenterNotificationManager() { |
| 61 message_center_->RemoveObserver(this); | 67 message_center_->RemoveObserver(this); |
| 62 } | 68 } |
| 63 | 69 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 65 // NotificationUIManager | 71 // NotificationUIManager |
| 66 | 72 |
| 67 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) { | 73 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 #if defined(OS_WIN) | 313 #if defined(OS_WIN) |
| 308 CheckFirstRunTimer(); | 314 CheckFirstRunTimer(); |
| 309 #endif | 315 #endif |
| 310 } | 316 } |
| 311 | 317 |
| 312 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest( | 318 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest( |
| 313 message_center::MessageCenterTrayDelegate* delegate) { | 319 message_center::MessageCenterTrayDelegate* delegate) { |
| 314 tray_.reset(delegate); | 320 tray_.reset(delegate); |
| 315 } | 321 } |
| 316 | 322 |
| 323 void MessageCenterNotificationManager::Observe( |
| 324 int type, |
| 325 const content::NotificationSource& source, |
| 326 const content::NotificationDetails& details) { |
| 327 if (type == chrome::NOTIFICATION_FULLSCREEN_CHANGED) { |
| 328 const bool is_fullscreen = *content::Details<bool>(details).ptr(); |
| 329 |
| 330 if (is_fullscreen && tray_.get() && tray_->GetMessageCenterTray()) |
| 331 tray_->GetMessageCenterTray()->HidePopupBubble(); |
| 332 } else { |
| 333 NotificationUIManagerImpl::Observe(type, source, details); |
| 334 } |
| 335 } |
| 336 |
| 317 //////////////////////////////////////////////////////////////////////////////// | 337 //////////////////////////////////////////////////////////////////////////////// |
| 318 // ImageDownloads | 338 // ImageDownloads |
| 319 | 339 |
| 320 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( | 340 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( |
| 321 message_center::MessageCenter* message_center, | 341 message_center::MessageCenter* message_center, |
| 322 ImageDownloadsObserver* observer) | 342 ImageDownloadsObserver* observer) |
| 323 : message_center_(message_center), | 343 : message_center_(message_center), |
| 324 pending_downloads_(0), | 344 pending_downloads_(0), |
| 325 observer_(observer) { | 345 observer_(observer) { |
| 326 } | 346 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 544 |
| 525 MessageCenterNotificationManager::ProfileNotification* | 545 MessageCenterNotificationManager::ProfileNotification* |
| 526 MessageCenterNotificationManager::FindProfileNotification( | 546 MessageCenterNotificationManager::FindProfileNotification( |
| 527 const std::string& id) const { | 547 const std::string& id) const { |
| 528 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 548 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 529 if (iter == profile_notifications_.end()) | 549 if (iter == profile_notifications_.end()) |
| 530 return NULL; | 550 return NULL; |
| 531 | 551 |
| 532 return (*iter).second; | 552 return (*iter).second; |
| 533 } | 553 } |
| OLD | NEW |