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

Side by Side Diff: ash/system/session_length_limit/tray_session_length_limit.cc

Issue 108213009: Adds TraySessionLengthLimitTest to ash_unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ash/system/session_length_limit/tray_session_length_limit.h" 5 #include "ash/system/session_length_limit/tray_session_length_limit.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/shelf/shelf_types.h" 9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // If the remaining session time falls below this threshold, the user should be 44 // If the remaining session time falls below this threshold, the user should be
45 // informed that the session is about to expire. 45 // informed that the session is about to expire.
46 const int kExpiringSoonThresholdInSeconds = 5 * 60; // 5 minutes. 46 const int kExpiringSoonThresholdInSeconds = 5 * 60; // 5 minutes.
47 47
48 // Color in which the remaining session time is normally shown. 48 // Color in which the remaining session time is normally shown.
49 const SkColor kRemainingTimeColor = SK_ColorWHITE; 49 const SkColor kRemainingTimeColor = SK_ColorWHITE;
50 // Color in which the remaining session time is shown when it is expiring soon. 50 // Color in which the remaining session time is shown when it is expiring soon.
51 const SkColor kRemainingTimeExpiringSoonColor = SK_ColorRED; 51 const SkColor kRemainingTimeExpiringSoonColor = SK_ColorRED;
52 52
53 const char kSessionLengthTimeoutNotificationId[] = "chrome://session/timeout";
54
55 views::Label* CreateAndSetupLabel() { 53 views::Label* CreateAndSetupLabel() {
56 views::Label* label = new views::Label; 54 views::Label* label = new views::Label;
57 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 55 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
58 SetupLabelForTray(label); 56 SetupLabelForTray(label);
59 gfx::Font font = label->font(); 57 gfx::Font font = label->font();
60 label->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); 58 label->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD));
61 return label; 59 return label;
62 } 60 }
63 61
64 base::string16 IntToTwoDigitString(int value) { 62 base::string16 IntToTwoDigitString(int value) {
65 DCHECK_GE(value, 0); 63 DCHECK_GE(value, 0);
66 DCHECK_LE(value, 99); 64 DCHECK_LE(value, 99);
67 if (value < 10) 65 if (value < 10)
68 return ASCIIToUTF16("0") + base::IntToString16(value); 66 return ASCIIToUTF16("0") + base::IntToString16(value);
69 return base::IntToString16(value); 67 return base::IntToString16(value);
70 } 68 }
71 69
72 base::string16 FormatRemainingSessionTimeNotification( 70 base::string16 FormatRemainingSessionTimeNotification(
73 const base::TimeDelta& remaining_session_time) { 71 const base::TimeDelta& remaining_session_time) {
74 return l10n_util::GetStringFUTF16( 72 return l10n_util::GetStringFUTF16(
75 IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME_NOTIFICATION, 73 IDS_ASH_STATUS_TRAY_REMAINING_SESSION_TIME_NOTIFICATION,
76 ui::TimeFormat::TimeDurationLong(remaining_session_time)); 74 ui::TimeFormat::TimeDurationLong(remaining_session_time));
77 } 75 }
78 76
79 // Creates, or updates the notification for session length timeout with 77 // Creates, or updates the notification for session length timeout with
80 // |remaining_time|. |state_changed| is true when its internal state has been 78 // |remaining_time|. |state_changed| is true when its internal state has been
81 // changed from another. 79 // changed from another.
82 void CreateOrUpdateNotification(const base::TimeDelta& remaining_time, 80 void CreateOrUpdateNotification(const std::string& notification_id,
81 const base::TimeDelta& remaining_time,
83 bool state_changed) { 82 bool state_changed) {
84 message_center::MessageCenter* message_center = 83 message_center::MessageCenter* message_center =
85 message_center::MessageCenter::Get(); 84 message_center::MessageCenter::Get();
86 85
87 // Do not create a new notification if no state has changed. It may happen 86 // Do not create a new notification if no state has changed. It may happen
88 // when the notification is already closed by the user, see crbug.com/285941. 87 // when the notification is already closed by the user, see crbug.com/285941.
89 if (!state_changed && 88 if (!state_changed && !message_center->HasNotification(notification_id))
90 !message_center->HasNotification(kSessionLengthTimeoutNotificationId)) {
91 return; 89 return;
92 }
93 90
94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
95 message_center::RichNotificationData data; 92 message_center::RichNotificationData data;
96 // Makes the spoken feedback only when the state has been changed. 93 // Makes the spoken feedback only when the state has been changed.
97 data.should_make_spoken_feedback_for_popup_updates = state_changed; 94 data.should_make_spoken_feedback_for_popup_updates = state_changed;
98 scoped_ptr<Notification> notification(new Notification( 95 scoped_ptr<Notification> notification(new Notification(
99 message_center::NOTIFICATION_TYPE_SIMPLE, 96 message_center::NOTIFICATION_TYPE_SIMPLE,
100 kSessionLengthTimeoutNotificationId, 97 notification_id,
101 FormatRemainingSessionTimeNotification(remaining_time), 98 FormatRemainingSessionTimeNotification(remaining_time),
102 base::string16() /* message */, 99 base::string16() /* message */,
103 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER), 100 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER),
104 base::string16() /* display_source */, 101 base::string16() /* display_source */,
105 message_center::NotifierId( 102 message_center::NotifierId(
106 message_center::NotifierId::SYSTEM_COMPONENT, 103 message_center::NotifierId::SYSTEM_COMPONENT,
107 system_notifier::kNotifierSessionLengthTimeout), 104 system_notifier::kNotifierSessionLengthTimeout),
108 data, 105 data,
109 NULL /* delegate */)); 106 NULL /* delegate */));
110 notification->SetSystemPriority(); 107 notification->SetSystemPriority();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 set_border(views::Border::CreateEmptyBorder( 268 set_border(views::Border::CreateEmptyBorder(
272 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 269 0, kTrayLabelItemHorizontalPaddingBottomAlignment,
273 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); 270 0, kTrayLabelItemHorizontalPaddingBottomAlignment));
274 } else { 271 } else {
275 set_border(NULL); 272 set_border(NULL);
276 } 273 }
277 } 274 }
278 275
279 } // namespace tray 276 } // namespace tray
280 277
278 // static
279 const char TraySessionLengthLimit::kNotificationId[] =
280 "chrome://session/timeout";
281
281 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray) 282 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray)
282 : SystemTrayItem(system_tray), 283 : SystemTrayItem(system_tray),
283 tray_view_(NULL), 284 tray_view_(NULL),
284 limit_state_(LIMIT_NONE) { 285 limit_state_(LIMIT_NONE) {
285 Shell::GetInstance()->system_tray_notifier()-> 286 Shell::GetInstance()->system_tray_notifier()->
286 AddSessionLengthLimitObserver(this); 287 AddSessionLengthLimitObserver(this);
287 Update(); 288 Update();
288 } 289 }
289 290
290 TraySessionLengthLimit::~TraySessionLengthLimit() { 291 TraySessionLengthLimit::~TraySessionLengthLimit() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 timer_->Start(FROM_HERE, 348 timer_->Start(FROM_HERE,
348 base::TimeDelta::FromSeconds(1), 349 base::TimeDelta::FromSeconds(1),
349 this, 350 this,
350 &TraySessionLengthLimit::Update); 351 &TraySessionLengthLimit::Update);
351 } 352 }
352 } 353 }
353 354
354 switch (limit_state_) { 355 switch (limit_state_) {
355 case LIMIT_NONE: 356 case LIMIT_NONE:
356 message_center::MessageCenter::Get()->RemoveNotification( 357 message_center::MessageCenter::Get()->RemoveNotification(
357 kSessionLengthTimeoutNotificationId, false /* by_user */); 358 kNotificationId, false /* by_user */);
358 break; 359 break;
359 case LIMIT_SET: 360 case LIMIT_SET:
360 CreateOrUpdateNotification( 361 CreateOrUpdateNotification(
362 kNotificationId,
361 remaining_session_time_, 363 remaining_session_time_,
362 previous_limit_state == LIMIT_NONE); 364 previous_limit_state == LIMIT_NONE);
363 break; 365 break;
364 case LIMIT_EXPIRING_SOON: 366 case LIMIT_EXPIRING_SOON:
365 CreateOrUpdateNotification( 367 CreateOrUpdateNotification(
368 kNotificationId,
366 remaining_session_time_, 369 remaining_session_time_,
367 previous_limit_state == LIMIT_NONE || 370 previous_limit_state == LIMIT_NONE ||
368 previous_limit_state == LIMIT_SET); 371 previous_limit_state == LIMIT_SET);
369 break; 372 break;
370 } 373 }
371 374
372 // Update the tray view last so that it can check whether the notification 375 // Update the tray view last so that it can check whether the notification
373 // view is currently visible or not. 376 // view is currently visible or not.
374 if (tray_view_) 377 if (tray_view_)
375 tray_view_->Update(); 378 tray_view_->Update();
376 } 379 }
377 380
381 bool TraySessionLengthLimit::IsTrayViewVisibleForTest() {
382 return tray_view_ && tray_view_->visible();
383 }
384
378 } // namespace internal 385 } // namespace internal
379 } // namespace ash 386 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698