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

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

Issue 2923083002: chromeos: Convert system tray session length limit to mojo (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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/session/tray_session_length_limit.h" 5 #include "ash/system/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/resources/vector_icons/vector_icons.h" 11 #include "ash/resources/vector_icons/vector_icons.h"
12 #include "ash/session/session_controller.h"
12 #include "ash/shell.h" 13 #include "ash/shell.h"
13 #include "ash/strings/grit/ash_strings.h" 14 #include "ash/strings/grit/ash_strings.h"
14 #include "ash/system/system_notifier.h" 15 #include "ash/system/system_notifier.h"
15 #include "ash/system/tray/label_tray_view.h" 16 #include "ash/system/tray/label_tray_view.h"
16 #include "ash/system/tray/system_tray.h" 17 #include "ash/system/tray/system_tray.h"
17 #include "ash/system/tray/system_tray_delegate.h"
18 #include "ash/system/tray/system_tray_notifier.h" 18 #include "ash/system/tray/system_tray_notifier.h"
19 #include "ash/system/tray/tray_constants.h" 19 #include "ash/system/tray/tray_constants.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/l10n/time_format.h" 23 #include "ui/base/l10n/time_format.h"
24 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
25 #include "ui/message_center/message_center.h" 25 #include "ui/message_center/message_center.h"
26 #include "ui/message_center/notification.h" 26 #include "ui/message_center/notification.h"
27 #include "ui/views/view.h" 27 #include "ui/views/view.h"
(...skipping 14 matching lines...) Expand all
42 42
43 // static 43 // static
44 const char TraySessionLengthLimit::kNotificationId[] = 44 const char TraySessionLengthLimit::kNotificationId[] =
45 "chrome://session/timeout"; 45 "chrome://session/timeout";
46 46
47 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray) 47 TraySessionLengthLimit::TraySessionLengthLimit(SystemTray* system_tray)
48 : SystemTrayItem(system_tray, UMA_SESSION_LENGTH_LIMIT), 48 : SystemTrayItem(system_tray, UMA_SESSION_LENGTH_LIMIT),
49 limit_state_(LIMIT_NONE), 49 limit_state_(LIMIT_NONE),
50 last_limit_state_(LIMIT_NONE), 50 last_limit_state_(LIMIT_NONE),
51 tray_bubble_view_(nullptr) { 51 tray_bubble_view_(nullptr) {
52 Shell::Get()->system_tray_notifier()->AddSessionLengthLimitObserver(this); 52 Shell::Get()->session_controller()->AddObserver(this);
53 Update(); 53 Update();
54 } 54 }
55 55
56 TraySessionLengthLimit::~TraySessionLengthLimit() { 56 TraySessionLengthLimit::~TraySessionLengthLimit() {
57 Shell::Get()->system_tray_notifier()->RemoveSessionLengthLimitObserver(this); 57 Shell::Get()->session_controller()->RemoveObserver(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 nullptr; 65 return nullptr;
66 tray_bubble_view_ = new LabelTrayView(nullptr, kSystemMenuTimerIcon); 66 tray_bubble_view_ = new LabelTrayView(nullptr, kSystemMenuTimerIcon);
67 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); 67 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage());
68 return tray_bubble_view_; 68 return tray_bubble_view_;
69 } 69 }
70 70
71 // View has been removed from tray bubble. 71 // View has been removed from tray bubble.
72 void TraySessionLengthLimit::OnDefaultViewDestroyed() { 72 void TraySessionLengthLimit::OnDefaultViewDestroyed() {
73 tray_bubble_view_ = nullptr; 73 tray_bubble_view_ = nullptr;
74 } 74 }
75 75
76 void TraySessionLengthLimit::OnSessionStartTimeChanged() {
77 Update();
78 }
79
80 void TraySessionLengthLimit::OnSessionLengthLimitChanged() { 76 void TraySessionLengthLimit::OnSessionLengthLimitChanged() {
81 Update(); 77 Update();
82 } 78 }
83 79
84 void TraySessionLengthLimit::Update() { 80 void TraySessionLengthLimit::Update() {
85 UpdateState(); 81 UpdateState();
86 UpdateNotification(); 82 UpdateNotification();
87 UpdateTrayBubbleView(); 83 UpdateTrayBubbleView();
88 } 84 }
89 85
90 void TraySessionLengthLimit::UpdateState() { 86 void TraySessionLengthLimit::UpdateState() {
91 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate(); 87 SessionController* session = Shell::Get()->session_controller();
92 if (delegate->GetSessionStartTime(&session_start_time_) && 88 base::TimeDelta time_limit = session->session_length_limit();
93 delegate->GetSessionLengthLimit(&time_limit_)) { 89 base::TimeTicks session_start_time = session->session_start_time();
James Cook 2017/06/05 23:23:48 As far as I can tell there was never a need for th
msw 2017/06/06 19:01:04 Acknowledged.
90 if (!time_limit.is_zero() && !session_start_time.is_null()) {
94 const base::TimeDelta expiring_soon_threshold( 91 const base::TimeDelta expiring_soon_threshold(
95 base::TimeDelta::FromMinutes(kExpiringSoonThresholdInMinutes)); 92 base::TimeDelta::FromMinutes(kExpiringSoonThresholdInMinutes));
96 remaining_session_time_ = 93 remaining_session_time_ =
97 std::max(time_limit_ - (base::TimeTicks::Now() - session_start_time_), 94 std::max(time_limit - (base::TimeTicks::Now() - session_start_time),
98 base::TimeDelta()); 95 base::TimeDelta());
99 limit_state_ = remaining_session_time_ <= expiring_soon_threshold 96 limit_state_ = remaining_session_time_ <= expiring_soon_threshold
100 ? LIMIT_EXPIRING_SOON 97 ? LIMIT_EXPIRING_SOON
101 : LIMIT_SET; 98 : LIMIT_SET;
102 if (!timer_) 99 if (!timer_)
103 timer_.reset(new base::RepeatingTimer); 100 timer_.reset(new base::RepeatingTimer);
104 if (!timer_->IsRunning()) { 101 if (!timer_->IsRunning()) {
105 timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds( 102 timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
106 kTimerIntervalInMilliseconds), 103 kTimerIntervalInMilliseconds),
107 this, &TraySessionLengthLimit::Update); 104 this, &TraySessionLengthLimit::Update);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 base::string16() /* title */, 146 base::string16() /* title */,
150 ComposeNotificationMessage() /* message */, 147 ComposeNotificationMessage() /* message */,
151 gfx::Image( 148 gfx::Image(
152 gfx::CreateVectorIcon(kSystemMenuTimerIcon, kMenuIconColor)), 149 gfx::CreateVectorIcon(kSystemMenuTimerIcon, kMenuIconColor)),
153 base::string16() /* display_source */, GURL(), 150 base::string16() /* display_source */, GURL(),
154 message_center::NotifierId( 151 message_center::NotifierId(
155 message_center::NotifierId::SYSTEM_COMPONENT, 152 message_center::NotifierId::SYSTEM_COMPONENT,
156 system_notifier::kNotifierSessionLengthTimeout), 153 system_notifier::kNotifierSessionLengthTimeout),
157 data, nullptr /* delegate */)); 154 data, nullptr /* delegate */));
158 notification->SetSystemPriority(); 155 notification->SetSystemPriority();
159 if (message_center->FindVisibleNotificationById(kNotificationId)) 156 if (message_center->FindVisibleNotificationById(kNotificationId)) {
160 message_center->UpdateNotification(kNotificationId, 157 message_center->UpdateNotification(kNotificationId,
161 std::move(notification)); 158 std::move(notification));
162 else 159 } else {
163 message_center->AddNotification(std::move(notification)); 160 message_center->AddNotification(std::move(notification));
161 }
164 last_limit_state_ = limit_state_; 162 last_limit_state_ = limit_state_;
165 } 163 }
166 164
167 void TraySessionLengthLimit::UpdateTrayBubbleView() const { 165 void TraySessionLengthLimit::UpdateTrayBubbleView() const {
168 if (!tray_bubble_view_) 166 if (!tray_bubble_view_)
169 return; 167 return;
170 if (limit_state_ == LIMIT_NONE) 168 if (limit_state_ == LIMIT_NONE)
171 tray_bubble_view_->SetMessage(base::string16()); 169 tray_bubble_view_->SetMessage(base::string16());
172 else 170 else
173 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage()); 171 tray_bubble_view_->SetMessage(ComposeTrayBubbleMessage());
(...skipping 10 matching lines...) Expand all
184 182
185 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { 183 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const {
186 return l10n_util::GetStringFUTF16( 184 return l10n_util::GetStringFUTF16(
187 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, 185 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT,
188 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, 186 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION,
189 ui::TimeFormat::LENGTH_LONG, 10, 187 ui::TimeFormat::LENGTH_LONG, 10,
190 remaining_session_time_)); 188 remaining_session_time_));
191 } 189 }
192 190
193 } // namespace ash 191 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698