Index: chrome/browser/chromeos/notifications/system_notification.cc |
diff --git a/chrome/browser/chromeos/notifications/system_notification.cc b/chrome/browser/chromeos/notifications/system_notification.cc |
index f248707b1ed4b6b1aa6927055fedde813833b7e1..f57cd962db6f956d1a28bb631e7cad65a3e2b044 100644 |
--- a/chrome/browser/chromeos/notifications/system_notification.cc |
+++ b/chrome/browser/chromeos/notifications/system_notification.cc |
@@ -11,10 +11,14 @@ |
#include "chrome/browser/notifications/notification.h" |
#include "chrome/browser/notifications/notification_ui_manager.h" |
#include "chrome/browser/ui/webui/web_ui_util.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
namespace chromeos { |
void SystemNotification::Init(int icon_resource_id) { |
+ screen_locked_ = |
+ DBusThreadManager::Get()->GetPowerManagerClient()->GetIsScreenLocked(); |
Daniel Erat
2012/05/11 14:12:38
i don't see this method at git.chromium.org/gitweb
stevenjb
2012/05/11 16:35:29
Doh! Forgot to add those files...
|
+ DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
collection_ = static_cast<BalloonCollectionImplType*>( |
g_browser_process->notification_ui_manager()->balloon_collection()); |
std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); |
@@ -32,7 +36,9 @@ SystemNotification::SystemNotification(Profile* profile, |
delegate_(delegate), |
title_(title), |
visible_(false), |
- urgent_(false) { |
+ sticky_(false), |
+ urgent_(false), |
+ screen_locked_(false) { |
Init(icon_resource_id); |
} |
@@ -45,11 +51,31 @@ SystemNotification::SystemNotification(Profile* profile, |
delegate_(new Delegate(id)), |
title_(title), |
visible_(false), |
- urgent_(false) { |
+ sticky_(false), |
+ urgent_(false), |
+ screen_locked_(false) { |
Init(icon_resource_id); |
} |
SystemNotification::~SystemNotification() { |
+ DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
+} |
+ |
+void SystemNotification::LockScreen() { |
+ screen_locked_ = true; |
+ bool was_visible = visible_; |
+ Hide(); |
+ visible_ = was_visible; // Show on unlock. |
+} |
+ |
+void SystemNotification::UnlockScreen() { |
+ screen_locked_ = false; |
+ if (visible_) { |
+ visible_ = false; // Not actually visible yet |
+ Notification notify = SystemNotificationFactory::Create( |
+ icon_, title_, message_, link_, delegate_.get()); |
+ ShowNotification(notify); |
+ } |
} |
void SystemNotification::Show(const string16& message, |
@@ -63,8 +89,16 @@ void SystemNotification::Show(const string16& message, |
const BalloonViewHost::MessageCallback& callback, |
bool urgent, |
bool sticky) { |
- Notification notify = SystemNotificationFactory::Create(icon_, |
- title_, message, link, delegate_.get()); |
+ message_ = message; |
+ link_ = link; |
+ callback_ = callback; |
+ sticky_ = sticky; |
+ if (screen_locked_) { |
+ visible_ = true; // Show on unlock |
+ return; |
+ } |
+ Notification notify = SystemNotificationFactory::Create( |
+ icon_, title_, message_, link_, delegate_.get()); |
if (visible_) { |
// Force showing a user hidden notification on an urgent transition. |
if (urgent && !urgent_) { |
@@ -74,12 +108,16 @@ void SystemNotification::Show(const string16& message, |
collection_->UpdateNotification(notify); |
} |
} |
+ urgent_ = urgent; |
+ ShowNotification(notify); |
+} |
+ |
+void SystemNotification::ShowNotification(const Notification& notify) { |
if (!visible_) { |
- collection_->AddSystemNotification(notify, profile_, sticky); |
- collection_->AddWebUIMessageCallback(notify, "link", callback); |
+ collection_->AddSystemNotification(notify, profile_, sticky_); |
+ collection_->AddWebUIMessageCallback(notify, "link", callback_); |
} |
visible_ = true; |
- urgent_ = urgent; |
} |
void SystemNotification::Hide() { |