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

Unified Diff: chrome/browser/chromeos/notifications/system_notification.cc

Issue 10382118: Don't show system notifications while the screen is locked. (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/notifications/system_notification.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « chrome/browser/chromeos/notifications/system_notification.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698