summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 08:46:53 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 08:46:53 +0000
commitbba8921b1bbfb8da79bd8484df6c5b952363c367 (patch)
treef2592144dfbc564b16892967e293c6668b480fa6 /ash
parent14c9e2e5f59acf63581642073f9dcf51fd4ef635 (diff)
downloadchromium_src-bba8921b1bbfb8da79bd8484df6c5b952363c367.zip
chromium_src-bba8921b1bbfb8da79bd8484df6c5b952363c367.tar.gz
chromium_src-bba8921b1bbfb8da79bd8484df6c5b952363c367.tar.bz2
Ports session_length_timeout notification to message center.
BUG=259138 R=stevenjb@chromium.org, bartfab@chromium.org TEST=manually Review URL: https://chromiumcodereview.appspot.com/23496010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/system/session_length_limit/tray_session_length_limit.cc107
-rw-r--r--ash/system/session_length_limit/tray_session_length_limit.h6
-rw-r--r--ash/system/system_notifier.h1
3 files changed, 37 insertions, 77 deletions
diff --git a/ash/system/session_length_limit/tray_session_length_limit.cc b/ash/system/session_length_limit/tray_session_length_limit.cc
index c807446..af32635 100644
--- a/ash/system/session_length_limit/tray_session_length_limit.cc
+++ b/ash/system/session_length_limit/tray_session_length_limit.cc
@@ -8,11 +8,11 @@
#include "ash/shelf/shelf_types.h"
#include "ash/shell.h"
+#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_notification_view.h"
#include "ash/system/tray/tray_utils.h"
#include "base/location.h"
#include "base/logging.h"
@@ -24,14 +24,18 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/text_constants.h"
+#include "ui/message_center/message_center.h"
+#include "ui/message_center/notification.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h"
+using message_center::Notification;
+
namespace ash {
namespace internal {
@@ -46,6 +50,8 @@ const SkColor kRemainingTimeColor = SK_ColorWHITE;
// Color in which the remaining session time is shown when it is expiring soon.
const SkColor kRemainingTimeExpiringSoonColor = SK_ColorRED;
+const char kSessionLengthTimeoutNotificationId[] = "chrome://session/timeout";
+
views::Label* CreateAndSetupLabel() {
views::Label* label = new views::Label;
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
@@ -70,26 +76,29 @@ base::string16 FormatRemainingSessionTimeNotification(
ui::TimeFormat::TimeDurationLong(remaining_session_time));
}
+void CreateOrUpdateNotification(const base::TimeDelta& remaining_time,
+ bool enable_spoken_feedback) {
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ message_center::RichNotificationData data;
+ data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback;
+ scoped_ptr<Notification> notification(new Notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE,
+ kSessionLengthTimeoutNotificationId,
+ FormatRemainingSessionTimeNotification(remaining_time),
+ base::string16() /* message */,
+ bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER),
+ base::string16() /* display_source */,
+ message_center::NotifierId(NOTIFIER_SESSION_LENGTH_TIMEOUT),
+ data,
+ NULL /* delegate */));
+ notification->SetSystemPriority();
+ message_center::MessageCenter::Get()->AddNotification(notification.Pass());
+}
+
} // namespace
namespace tray {
-class RemainingSessionTimeNotificationView : public TrayNotificationView {
- public:
- explicit RemainingSessionTimeNotificationView(TraySessionLengthLimit* owner);
- virtual ~RemainingSessionTimeNotificationView();
-
- // TrayNotificationView:
- virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
-
- void Update();
-
- private:
- views::Label* label_;
-
- DISALLOW_COPY_AND_ASSIGN(RemainingSessionTimeNotificationView);
-};
-
class RemainingSessionTimeTrayView : public views::View {
public:
RemainingSessionTimeTrayView(const TraySessionLengthLimit* owner,
@@ -115,31 +124,6 @@ class RemainingSessionTimeTrayView : public views::View {
DISALLOW_COPY_AND_ASSIGN(RemainingSessionTimeTrayView);
};
-RemainingSessionTimeNotificationView::RemainingSessionTimeNotificationView(
- TraySessionLengthLimit* owner)
- : TrayNotificationView(owner,
- IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER) {
- label_ = new views::Label;
- label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- label_->SetMultiLine(true);
- Update();
- InitView(label_);
-}
-
-RemainingSessionTimeNotificationView::~RemainingSessionTimeNotificationView() {
-}
-
-void RemainingSessionTimeNotificationView::ChildPreferredSizeChanged(
- views::View* child) {
- PreferredSizeChanged();
-}
-
-void RemainingSessionTimeNotificationView::Update() {
- label_->SetText(FormatRemainingSessionTimeNotification(
- reinterpret_cast<TraySessionLengthLimit*>(owner())->
- GetRemainingSessionTime()));
-}
-
RemainingSessionTimeTrayView::RemainingSessionTimeTrayView(
const TraySessionLengthLimit* owner,
ShelfAlignment shelf_alignment)
@@ -281,7 +265,6 @@ void RemainingSessionTimeTrayView::SetBorder(ShelfAlignment shelf_alignment) {
TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray)
: SystemTrayItem(system_tray),
tray_view_(NULL),
- notification_view_(NULL),
limit_state_(LIMIT_NONE) {
Shell::GetInstance()->system_tray_notifier()->
AddSessionLengthLimitObserver(this);
@@ -300,21 +283,10 @@ views::View* TraySessionLengthLimit::CreateTrayView(user::LoginStatus status) {
return tray_view_;
}
-views::View* TraySessionLengthLimit::CreateNotificationView(
- user::LoginStatus status) {
- CHECK(notification_view_ == NULL);
- notification_view_ = new tray::RemainingSessionTimeNotificationView(this);
- return notification_view_;
-}
-
void TraySessionLengthLimit::DestroyTrayView() {
tray_view_ = NULL;
}
-void TraySessionLengthLimit::DestroyNotificationView() {
- notification_view_ = NULL;
-}
-
void TraySessionLengthLimit::UpdateAfterShelfAlignmentChange(
ShelfAlignment alignment) {
if (tray_view_)
@@ -338,12 +310,6 @@ base::TimeDelta TraySessionLengthLimit::GetRemainingSessionTime() const {
return remaining_session_time_;
}
-void TraySessionLengthLimit::ShowAndSpeakNotification() {
- ShowNotificationView();
- Shell::GetInstance()->system_tray_delegate()->MaybeSpeak(UTF16ToUTF8(
- FormatRemainingSessionTimeNotification(remaining_session_time_)));
-}
-
void TraySessionLengthLimit::Update() {
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
const LimitState previous_limit_state = limit_state_;
@@ -369,22 +335,21 @@ void TraySessionLengthLimit::Update() {
}
}
- if (notification_view_)
- notification_view_->Update();
-
switch (limit_state_) {
case LIMIT_NONE:
- HideNotificationView();
+ message_center::MessageCenter::Get()->RemoveNotification(
+ kSessionLengthTimeoutNotificationId, false /* by_user */);
break;
case LIMIT_SET:
- if (previous_limit_state == LIMIT_NONE)
- ShowAndSpeakNotification();
+ CreateOrUpdateNotification(
+ remaining_session_time_,
+ previous_limit_state == LIMIT_NONE);
break;
case LIMIT_EXPIRING_SOON:
- if (previous_limit_state == LIMIT_NONE ||
- previous_limit_state == LIMIT_SET) {
- ShowAndSpeakNotification();
- }
+ CreateOrUpdateNotification(
+ remaining_session_time_,
+ previous_limit_state == LIMIT_NONE ||
+ previous_limit_state == LIMIT_SET);
break;
}
diff --git a/ash/system/session_length_limit/tray_session_length_limit.h b/ash/system/session_length_limit/tray_session_length_limit.h
index 1df4bb0..94ce137 100644
--- a/ash/system/session_length_limit/tray_session_length_limit.h
+++ b/ash/system/session_length_limit/tray_session_length_limit.h
@@ -17,7 +17,6 @@ namespace ash {
namespace internal {
namespace tray {
-class RemainingSessionTimeNotificationView;
class RemainingSessionTimeTrayView;
}
@@ -36,10 +35,7 @@ class TraySessionLengthLimit : public SystemTrayItem,
// SystemTrayItem:
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
- virtual views::View* CreateNotificationView(
- user::LoginStatus status) OVERRIDE;
virtual void DestroyTrayView() OVERRIDE;
- virtual void DestroyNotificationView() OVERRIDE;
virtual void UpdateAfterShelfAlignmentChange(
ShelfAlignment alignment) OVERRIDE;
@@ -51,11 +47,9 @@ class TraySessionLengthLimit : public SystemTrayItem,
base::TimeDelta GetRemainingSessionTime() const;
private:
- void ShowAndSpeakNotification();
void Update();
tray::RemainingSessionTimeTrayView* tray_view_;
- tray::RemainingSessionTimeNotificationView* notification_view_;
LimitState limit_state_;
base::TimeTicks session_start_time_;
diff --git a/ash/system/system_notifier.h b/ash/system/system_notifier.h
index 119ed5b..1680a1b 100644
--- a/ash/system/system_notifier.h
+++ b/ash/system/system_notifier.h
@@ -26,6 +26,7 @@ enum AshSystemComponentNotifierType {
NOTIFIER_SCREENSHOT,
NOTIFIER_SCREEN_CAPTURE,
NOTIFIER_SCREEN_SHARE,
+ NOTIFIER_SESSION_LENGTH_TIMEOUT,
NOTIFIER_POWER,
};