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

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

Issue 324583002: The 1st patch to disambiguate message center notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 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/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 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/label_tray_view.h" 10 #include "ash/system/chromeos/label_tray_view.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 } 117 }
118 118
119 void TraySessionLengthLimit::UpdateNotification() { 119 void TraySessionLengthLimit::UpdateNotification() {
120 message_center::MessageCenter* message_center = 120 message_center::MessageCenter* message_center =
121 message_center::MessageCenter::Get(); 121 message_center::MessageCenter::Get();
122 122
123 // If state hasn't changed and the notification has already been acknowledged, 123 // If state hasn't changed and the notification has already been acknowledged,
124 // we won't re-create it. 124 // we won't re-create it.
125 if (limit_state_ == last_limit_state_ && 125 if (limit_state_ == last_limit_state_ &&
126 !message_center->HasNotification(kNotificationId)) { 126 !message_center->FindVisibleNotificationById(kNotificationId)) {
127 return; 127 return;
128 } 128 }
129 129
130 // After state change, any possibly existing notification is removed to make 130 // After state change, any possibly existing notification is removed to make
131 // sure it is re-shown even if it had been acknowledged by the user before 131 // sure it is re-shown even if it had been acknowledged by the user before
132 // (and in the rare case of state change towards LIMIT_NONE to make the 132 // (and in the rare case of state change towards LIMIT_NONE to make the
133 // notification disappear). 133 // notification disappear).
134 if (limit_state_ != last_limit_state_ && 134 if (limit_state_ != last_limit_state_ &&
135 message_center->HasNotification(kNotificationId)) { 135 message_center->FindVisibleNotificationById(kNotificationId)) {
136 message_center::MessageCenter::Get()->RemoveNotification( 136 message_center::MessageCenter::Get()->RemoveNotification(
137 kNotificationId, false /* by_user */); 137 kNotificationId, false /* by_user */);
138 } 138 }
139 139
140 // For LIMIT_NONE, there's nothing more to do. 140 // For LIMIT_NONE, there's nothing more to do.
141 if (limit_state_ == LIMIT_NONE) { 141 if (limit_state_ == LIMIT_NONE) {
142 last_limit_state_ = limit_state_; 142 last_limit_state_ = limit_state_;
143 return; 143 return;
144 } 144 }
145 145
146 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 146 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
147 message_center::RichNotificationData data; 147 message_center::RichNotificationData data;
148 data.should_make_spoken_feedback_for_popup_updates = 148 data.should_make_spoken_feedback_for_popup_updates =
149 (limit_state_ != last_limit_state_); 149 (limit_state_ != last_limit_state_);
150 scoped_ptr<message_center::Notification> notification( 150 scoped_ptr<message_center::Notification> notification(
151 new message_center::Notification( 151 new message_center::Notification(
152 message_center::NOTIFICATION_TYPE_SIMPLE, 152 message_center::NOTIFICATION_TYPE_SIMPLE,
153 kNotificationId, 153 kNotificationId,
154 base::string16() /* title */, 154 base::string16() /* title */,
155 ComposeNotificationMessage() /* message */, 155 ComposeNotificationMessage() /* message */,
156 bundle.GetImageNamed( 156 bundle.GetImageNamed(
157 IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT), 157 IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT),
158 base::string16() /* display_source */, 158 base::string16() /* display_source */,
159 message_center::NotifierId( 159 message_center::NotifierId(
160 message_center::NotifierId::SYSTEM_COMPONENT, 160 message_center::NotifierId::SYSTEM_COMPONENT,
161 system_notifier::kNotifierSessionLengthTimeout), 161 system_notifier::kNotifierSessionLengthTimeout),
162 data, 162 data,
163 NULL /* delegate */)); 163 NULL /* delegate */));
164 notification->SetSystemPriority(); 164 notification->SetSystemPriority();
165 if (message_center->HasNotification(kNotificationId)) 165 if (message_center->FindVisibleNotificationById(kNotificationId))
166 message_center->UpdateNotification(kNotificationId, notification.Pass()); 166 message_center->UpdateNotification(kNotificationId, notification.Pass());
167 else 167 else
168 message_center->AddNotification(notification.Pass()); 168 message_center->AddNotification(notification.Pass());
169 last_limit_state_ = limit_state_; 169 last_limit_state_ = limit_state_;
170 } 170 }
171 171
172 void TraySessionLengthLimit::UpdateTrayBubbleView() const { 172 void TraySessionLengthLimit::UpdateTrayBubbleView() const {
173 if (!tray_bubble_view_) 173 if (!tray_bubble_view_)
174 return; 174 return;
175 if (limit_state_ == LIMIT_NONE) 175 if (limit_state_ == LIMIT_NONE)
(...skipping 15 matching lines...) Expand all
191 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const { 191 base::string16 TraySessionLengthLimit::ComposeTrayBubbleMessage() const {
192 return l10n_util::GetStringFUTF16( 192 return l10n_util::GetStringFUTF16(
193 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT, 193 IDS_ASH_STATUS_TRAY_BUBBLE_SESSION_LENGTH_LIMIT,
194 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, 194 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION,
195 ui::TimeFormat::LENGTH_LONG, 195 ui::TimeFormat::LENGTH_LONG,
196 10, 196 10,
197 remaining_session_time_)); 197 remaining_session_time_));
198 } 198 }
199 199
200 } // namespace ash 200 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698