| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/session/tray_session_length_limit.h" | 5 #include "ash/system/chromeos/session/tray_session_length_limit.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 WmShell::Get()->system_tray_notifier()->RemoveSessionLengthLimitObserver( | 56 WmShell::Get()->system_tray_notifier()->RemoveSessionLengthLimitObserver( |
| 57 this); | 57 this); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Add view to tray bubble. | 60 // Add view to tray bubble. |
| 61 views::View* TraySessionLengthLimit::CreateDefaultView(LoginStatus status) { | 61 views::View* TraySessionLengthLimit::CreateDefaultView(LoginStatus status) { |
| 62 CHECK(!tray_bubble_view_); | 62 CHECK(!tray_bubble_view_); |
| 63 UpdateState(); | 63 UpdateState(); |
| 64 if (limit_state_ == LIMIT_NONE) | 64 if (limit_state_ == LIMIT_NONE) |
| 65 return NULL; | 65 return NULL; |
| 66 tray_bubble_view_ = new LabelTrayView( | 66 tray_bubble_view_ = |
| 67 NULL /* click_listener */, | 67 new LabelTrayView(NULL /* click_listener */, |
| 68 IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT); | 68 IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT); |
| 69 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); | 69 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); |
| 70 return tray_bubble_view_; | 70 return tray_bubble_view_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // View has been removed from tray bubble. | 73 // View has been removed from tray bubble. |
| 74 void TraySessionLengthLimit::DestroyDefaultView() { | 74 void TraySessionLengthLimit::DestroyDefaultView() { |
| 75 tray_bubble_view_ = NULL; | 75 tray_bubble_view_ = NULL; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void TraySessionLengthLimit::OnSessionStartTimeChanged() { | 78 void TraySessionLengthLimit::OnSessionStartTimeChanged() { |
| 79 Update(); | 79 Update(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void TraySessionLengthLimit::OnSessionLengthLimitChanged() { | 82 void TraySessionLengthLimit::OnSessionLengthLimitChanged() { |
| 83 Update(); | 83 Update(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void TraySessionLengthLimit::Update() { | 86 void TraySessionLengthLimit::Update() { |
| 87 UpdateState(); | 87 UpdateState(); |
| 88 UpdateNotification(); | 88 UpdateNotification(); |
| 89 UpdateTrayBubbleView(); | 89 UpdateTrayBubbleView(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void TraySessionLengthLimit::UpdateState() { | 92 void TraySessionLengthLimit::UpdateState() { |
| 93 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 93 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 94 if (delegate->GetSessionStartTime(&session_start_time_) && | 94 if (delegate->GetSessionStartTime(&session_start_time_) && |
| 95 delegate->GetSessionLengthLimit(&time_limit_)) { | 95 delegate->GetSessionLengthLimit(&time_limit_)) { |
| 96 const base::TimeDelta expiring_soon_threshold( | 96 const base::TimeDelta expiring_soon_threshold( |
| 97 base::TimeDelta::FromMinutes(kExpiringSoonThresholdInMinutes)); | 97 base::TimeDelta::FromMinutes(kExpiringSoonThresholdInMinutes)); |
| 98 remaining_session_time_ = std::max( | 98 remaining_session_time_ = |
| 99 time_limit_ - (base::TimeTicks::Now() - session_start_time_), | 99 std::max(time_limit_ - (base::TimeTicks::Now() - session_start_time_), |
| 100 base::TimeDelta()); | 100 base::TimeDelta()); |
| 101 limit_state_ = remaining_session_time_ <= expiring_soon_threshold ? | 101 limit_state_ = remaining_session_time_ <= expiring_soon_threshold |
| 102 LIMIT_EXPIRING_SOON : LIMIT_SET; | 102 ? LIMIT_EXPIRING_SOON |
| 103 : LIMIT_SET; |
| 103 if (!timer_) | 104 if (!timer_) |
| 104 timer_.reset(new base::RepeatingTimer); | 105 timer_.reset(new base::RepeatingTimer); |
| 105 if (!timer_->IsRunning()) { | 106 if (!timer_->IsRunning()) { |
| 106 timer_->Start(FROM_HERE, | 107 timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds( |
| 107 base::TimeDelta::FromMilliseconds( | 108 kTimerIntervalInMilliseconds), |
| 108 kTimerIntervalInMilliseconds), | 109 this, &TraySessionLengthLimit::Update); |
| 109 this, | |
| 110 &TraySessionLengthLimit::Update); | |
| 111 } | 110 } |
| 112 } else { | 111 } else { |
| 113 remaining_session_time_ = base::TimeDelta(); | 112 remaining_session_time_ = base::TimeDelta(); |
| 114 limit_state_ = LIMIT_NONE; | 113 limit_state_ = LIMIT_NONE; |
| 115 timer_.reset(); | 114 timer_.reset(); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 | 117 |
| 119 void TraySessionLengthLimit::UpdateNotification() { | 118 void TraySessionLengthLimit::UpdateNotification() { |
| 120 message_center::MessageCenter* message_center = | 119 message_center::MessageCenter* message_center = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 tray_bubble_view_->SetMessage(base::string16()); | 174 tray_bubble_view_->SetMessage(base::string16()); |
| 176 else | 175 else |
| 177 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); | 176 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); |
| 178 tray_bubble_view_->Layout(); | 177 tray_bubble_view_->Layout(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 base::string16 TraySessionLengthLimit::ComposeNotificationMessage() const { | 180 base::string16 TraySessionLengthLimit::ComposeNotificationMessage() const { |
| 182 return l10n_util::GetStringFUTF16( | 181 return l10n_util::GetStringFUTF16( |
| 183 IDS_ASH_STATUS_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT, | 182 IDS_ASH_STATUS_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT, |
| 184 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | 183 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, |
| 185 ui::TimeFormat::LENGTH_LONG, | 184 ui::TimeFormat::LENGTH_LONG, 10, |
| 186 10, | |
| 187 remaining_session_time_)); | 185 remaining_session_time_)); |
| 188 } | 186 } |
| 189 | 187 |
| 190 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { | 188 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { |
| 191 return l10n_util::GetStringFUTF16( | 189 return l10n_util::GetStringFUTF16( |
| 192 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, | 190 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, |
| 193 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | 191 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, |
| 194 ui::TimeFormat::LENGTH_LONG, | 192 ui::TimeFormat::LENGTH_LONG, 10, |
| 195 10, | |
| 196 remaining_session_time_)); | 193 remaining_session_time_)); |
| 197 } | 194 } |
| 198 | 195 |
| 199 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |