| 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/common/system/chromeos/session/tray_session_length_limit.h" | 5 #include "ash/common/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 |
| 11 #include "ash/common/system/system_notifier.h" | 11 #include "ash/common/system/system_notifier.h" |
| 12 #include "ash/common/system/tray/label_tray_view.h" | 12 #include "ash/common/system/tray/label_tray_view.h" |
| 13 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 15 #include "ash/common/system/tray/system_tray_notifier.h" | 15 #include "ash/common/system/tray/system_tray_notifier.h" |
| 16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 17 #include "ash/resources/grit/ash_resources.h" | 17 #include "ash/resources/grit/ash_resources.h" |
| 18 #include "ash/resources/vector_icons/vector_icons.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "grit/ash_strings.h" | 21 #include "grit/ash_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/l10n/time_format.h" | 23 #include "ui/base/l10n/time_format.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/message_center/message_center.h" | 25 #include "ui/message_center/message_center.h" |
| 25 #include "ui/message_center/notification.h" | 26 #include "ui/message_center/notification.h" |
| 26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 27 | 28 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 const char TraySessionLengthLimit::kNotificationId[] = | 44 const char TraySessionLengthLimit::kNotificationId[] = |
| 44 "chrome://session/timeout"; | 45 "chrome://session/timeout"; |
| 45 | 46 |
| 46 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray) | 47 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray) |
| 47 : SystemTrayItem(system_tray, UMA_SESSION_LENGTH_LIMIT), | 48 : SystemTrayItem(system_tray, UMA_SESSION_LENGTH_LIMIT), |
| 48 limit_state_(LIMIT_NONE), | 49 limit_state_(LIMIT_NONE), |
| 49 last_limit_state_(LIMIT_NONE), | 50 last_limit_state_(LIMIT_NONE), |
| 50 tray_bubble_view_(NULL) { | 51 tray_bubble_view_(nullptr) { |
| 51 WmShell::Get()->system_tray_notifier()->AddSessionLengthLimitObserver(this); | 52 WmShell::Get()->system_tray_notifier()->AddSessionLengthLimitObserver(this); |
| 52 Update(); | 53 Update(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 TraySessionLengthLimit::~TraySessionLengthLimit() { | 56 TraySessionLengthLimit::~TraySessionLengthLimit() { |
| 56 WmShell::Get()->system_tray_notifier()->RemoveSessionLengthLimitObserver( | 57 WmShell::Get()->system_tray_notifier()->RemoveSessionLengthLimitObserver( |
| 57 this); | 58 this); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Add view to tray bubble. | 61 // Add view to tray bubble. |
| 61 views::View* TraySessionLengthLimit::CreateDefaultView(LoginStatus status) { | 62 views::View* TraySessionLengthLimit::CreateDefaultView(LoginStatus status) { |
| 62 CHECK(!tray_bubble_view_); | 63 CHECK(!tray_bubble_view_); |
| 63 UpdateState(); | 64 UpdateState(); |
| 64 if (limit_state_ == LIMIT_NONE) | 65 if (limit_state_ == LIMIT_NONE) |
| 65 return NULL; | 66 return nullptr; |
| 66 tray_bubble_view_ = | 67 tray_bubble_view_ = new LabelTrayView(nullptr, kSystemMenuTimerIcon); |
| 67 new LabelTrayView(NULL /* click_listener */, | |
| 68 IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT); | |
| 69 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); | 68 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); |
| 70 return tray_bubble_view_; | 69 return tray_bubble_view_; |
| 71 } | 70 } |
| 72 | 71 |
| 73 // View has been removed from tray bubble. | 72 // View has been removed from tray bubble. |
| 74 void TraySessionLengthLimit::DestroyDefaultView() { | 73 void TraySessionLengthLimit::DestroyDefaultView() { |
| 75 tray_bubble_view_ = NULL; | 74 tray_bubble_view_ = nullptr; |
| 76 } | 75 } |
| 77 | 76 |
| 78 void TraySessionLengthLimit::OnSessionStartTimeChanged() { | 77 void TraySessionLengthLimit::OnSessionStartTimeChanged() { |
| 79 Update(); | 78 Update(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 void TraySessionLengthLimit::OnSessionLengthLimitChanged() { | 81 void TraySessionLengthLimit::OnSessionLengthLimitChanged() { |
| 83 Update(); | 82 Update(); |
| 84 } | 83 } |
| 85 | 84 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 new message_center::Notification( | 149 new message_center::Notification( |
| 151 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, | 150 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, |
| 152 base::string16() /* title */, | 151 base::string16() /* title */, |
| 153 ComposeNotificationMessage() /* message */, | 152 ComposeNotificationMessage() /* message */, |
| 154 bundle.GetImageNamed( | 153 bundle.GetImageNamed( |
| 155 IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT), | 154 IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT), |
| 156 base::string16() /* display_source */, GURL(), | 155 base::string16() /* display_source */, GURL(), |
| 157 message_center::NotifierId( | 156 message_center::NotifierId( |
| 158 message_center::NotifierId::SYSTEM_COMPONENT, | 157 message_center::NotifierId::SYSTEM_COMPONENT, |
| 159 system_notifier::kNotifierSessionLengthTimeout), | 158 system_notifier::kNotifierSessionLengthTimeout), |
| 160 data, NULL /* delegate */)); | 159 data, nullptr /* delegate */)); |
| 161 notification->SetSystemPriority(); | 160 notification->SetSystemPriority(); |
| 162 if (message_center->FindVisibleNotificationById(kNotificationId)) | 161 if (message_center->FindVisibleNotificationById(kNotificationId)) |
| 163 message_center->UpdateNotification(kNotificationId, | 162 message_center->UpdateNotification(kNotificationId, |
| 164 std::move(notification)); | 163 std::move(notification)); |
| 165 else | 164 else |
| 166 message_center->AddNotification(std::move(notification)); | 165 message_center->AddNotification(std::move(notification)); |
| 167 last_limit_state_ = limit_state_; | 166 last_limit_state_ = limit_state_; |
| 168 } | 167 } |
| 169 | 168 |
| 170 void TraySessionLengthLimit::UpdateTrayBubbleView() const { | 169 void TraySessionLengthLimit::UpdateTrayBubbleView() const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 187 | 186 |
| 188 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { | 187 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { |
| 189 return l10n_util::GetStringFUTF16( | 188 return l10n_util::GetStringFUTF16( |
| 190 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, | 189 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, |
| 191 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | 190 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, |
| 192 ui::TimeFormat::LENGTH_LONG, 10, | 191 ui::TimeFormat::LENGTH_LONG, 10, |
| 193 remaining_session_time_)); | 192 remaining_session_time_)); |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace ash | 195 } // namespace ash |
| OLD | NEW |