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

Side by Side Diff: chrome/browser/chromeos/printing/cups_print_job_notification.cc

Issue 2708233006: Report print jobs that are aborted by CUPS as errors. (Closed)
Patch Set: address comments from xdai Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/chromeos/printing/cups_print_job_notification.h" 5 #include "chrome/browser/chromeos/printing/cups_print_job_notification.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 base::string16(), // display_source 77 base::string16(), // display_source
78 GURL(kCupsPrintJobNotificationId), 78 GURL(kCupsPrintJobNotificationId),
79 notification_id_, // tag 79 notification_id_, // tag
80 message_center::RichNotificationData(), delegate_.get())); 80 message_center::RichNotificationData(), delegate_.get()));
81 UpdateNotification(); 81 UpdateNotification();
82 } 82 }
83 83
84 CupsPrintJobNotification::~CupsPrintJobNotification() {} 84 CupsPrintJobNotification::~CupsPrintJobNotification() {}
85 85
86 void CupsPrintJobNotification::OnPrintJobStatusUpdated() { 86 void CupsPrintJobNotification::OnPrintJobStatusUpdated() {
87 // After cancellation, ignore all updates.
88 if (cancelled_by_user_)
89 return;
90
87 UpdateNotification(); 91 UpdateNotification();
88 } 92 }
89 93
90 void CupsPrintJobNotification::CloseNotificationByUser() { 94 void CupsPrintJobNotification::CloseNotificationByUser() {
91 closed_in_middle_ = true; 95 closed_in_middle_ = true;
92 g_browser_process->message_center()->RemoveNotification(GetNotificationId(), 96 g_browser_process->message_center()->RemoveNotification(GetNotificationId(),
93 true /* by_user */); 97 true /* by_user */);
94 } 98 }
95 99
96 void CupsPrintJobNotification::ClickOnNotificationButton(int button_index) { 100 void CupsPrintJobNotification::ClickOnNotificationButton(int button_index) {
97 DCHECK(button_index >= 0 && 101 DCHECK(button_index >= 0 &&
98 static_cast<size_t>(button_index) < button_commands_->size()); 102 static_cast<size_t>(button_index) < button_commands_->size());
99 103
100 CupsPrintJobNotification::ButtonCommand button_command = 104 CupsPrintJobNotification::ButtonCommand button_command =
101 button_commands_->at(button_index); 105 button_commands_->at(button_index);
102 CupsPrintJobManager* print_job_manager = 106 CupsPrintJobManager* print_job_manager =
103 CupsPrintJobManagerFactory::GetForBrowserContext(profile_); 107 CupsPrintJobManagerFactory::GetForBrowserContext(profile_);
104 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_); 108 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_);
105 109
106 switch (button_command) { 110 switch (button_command) {
107 case ButtonCommand::CANCEL_PRINTING: 111 case ButtonCommand::CANCEL_PRINTING:
108 if (print_job_manager->CancelPrintJob(print_job_)) { 112 if (print_job_manager->CancelPrintJob(print_job_)) {
109 // only clean up the nofitication if cancel was successful. 113 // only clean up the nofitication if cancel was successful.
110 g_browser_process->notification_ui_manager()->CancelById( 114 g_browser_process->notification_ui_manager()->CancelById(
111 GetNotificationId(), profile_id); 115 GetNotificationId(), profile_id);
112 // |print_job_| is deleted by CupsPrintManager when the print job is 116 cancelled_by_user_ = true;
113 // cancelled, thus set it to nullptr.
114 print_job_ = nullptr;
115 } 117 }
116 break; 118 break;
117 case ButtonCommand::PAUSE_PRINTING: 119 case ButtonCommand::PAUSE_PRINTING:
118 print_job_manager->SuspendPrintJob(print_job_); 120 print_job_manager->SuspendPrintJob(print_job_);
119 break; 121 break;
120 case ButtonCommand::RESUME_PRINTING: 122 case ButtonCommand::RESUME_PRINTING:
121 print_job_manager->ResumePrintJob(print_job_); 123 print_job_manager->ResumePrintJob(print_job_);
122 break; 124 break;
123 case ButtonCommand::GET_HELP: 125 case ButtonCommand::GET_HELP:
124 break; 126 break;
125 } 127 }
126 } 128 }
127 129
128 const std::string& CupsPrintJobNotification::GetNotificationId() { 130 const std::string& CupsPrintJobNotification::GetNotificationId() {
129 return notification_id_; 131 return notification_id_;
130 } 132 }
131 133
132 void CupsPrintJobNotification::UpdateNotification() { 134 void CupsPrintJobNotification::UpdateNotification() {
133 DCHECK(print_job_->state() != CupsPrintJob::State::STATE_CANCELLED);
134
135 UpdateNotificationTitle(); 135 UpdateNotificationTitle();
136 UpdateNotificationIcon(); 136 UpdateNotificationIcon();
137 UpdateNotificationBodyMessage(); 137 UpdateNotificationBodyMessage();
138 UpdateNotificationType(); 138 UpdateNotificationType();
139 UpdateNotificationButtons(); 139 UpdateNotificationButtons();
140 140
141 // |STATE_PAGE_DONE| is special since if the user closes the notification in 141 // |STATE_PAGE_DONE| is special since if the user closes the notification in
142 // the middle, which means they're not interested in the printing progress, we 142 // the middle, which means they're not interested in the printing progress, we
143 // should prevent showing the following printing progress. 143 // should prevent showing the following printing progress.
144 if (print_job_->state() == CupsPrintJob::State::STATE_PAGE_DONE) { 144 if (print_job_->state() == CupsPrintJob::State::STATE_PAGE_DONE) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 case CupsPrintJob::State::STATE_PAGE_DONE: 177 case CupsPrintJob::State::STATE_PAGE_DONE:
178 case CupsPrintJob::State::STATE_SUSPENDED: 178 case CupsPrintJob::State::STATE_SUSPENDED:
179 case CupsPrintJob::State::STATE_RESUMED: 179 case CupsPrintJob::State::STATE_RESUMED:
180 notification_->set_icon( 180 notification_->set_icon(
181 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_PRINTING)); 181 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_PRINTING));
182 break; 182 break;
183 case CupsPrintJob::State::STATE_DOCUMENT_DONE: 183 case CupsPrintJob::State::STATE_DOCUMENT_DONE:
184 notification_->set_icon( 184 notification_->set_icon(
185 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_DONE)); 185 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_DONE));
186 break; 186 break;
187 case CupsPrintJob::State::STATE_CANCELLED:
187 case CupsPrintJob::State::STATE_ERROR: 188 case CupsPrintJob::State::STATE_ERROR:
188 notification_->set_icon( 189 notification_->set_icon(
189 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_ERROR)); 190 bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_ERROR));
190 break; 191 case CupsPrintJob::State::STATE_NONE:
191 default:
192 break; 192 break;
193 } 193 }
194 } 194 }
195 195
196 void CupsPrintJobNotification::UpdateNotificationBodyMessage() { 196 void CupsPrintJobNotification::UpdateNotificationBodyMessage() {
197 base::string16 message; 197 base::string16 message;
198 switch (print_job_->state()) { 198 switch (print_job_->state()) {
199 case CupsPrintJob::State::STATE_NONE: 199 case CupsPrintJob::State::STATE_NONE:
200 break; 200 break;
201 case CupsPrintJob::State::STATE_WAITING: 201 case CupsPrintJob::State::STATE_WAITING:
(...skipping 11 matching lines...) Expand all
213 base::IntToString16(print_job_->total_page_number()), 213 base::IntToString16(print_job_->total_page_number()),
214 base::UTF8ToUTF16(print_job_->printer().display_name())); 214 base::UTF8ToUTF16(print_job_->printer().display_name()));
215 215
216 break; 216 break;
217 case CupsPrintJob::State::STATE_DOCUMENT_DONE: 217 case CupsPrintJob::State::STATE_DOCUMENT_DONE:
218 message = l10n_util::GetStringFUTF16( 218 message = l10n_util::GetStringFUTF16(
219 IDS_PRINT_JOB_DONE_NOTIFICATION_MESSAGE, 219 IDS_PRINT_JOB_DONE_NOTIFICATION_MESSAGE,
220 base::IntToString16(print_job_->total_page_number()), 220 base::IntToString16(print_job_->total_page_number()),
221 base::UTF8ToUTF16(print_job_->printer().display_name())); 221 base::UTF8ToUTF16(print_job_->printer().display_name()));
222 break; 222 break;
223 case CupsPrintJob::State::STATE_CANCELLED:
223 case CupsPrintJob::State::STATE_ERROR: 224 case CupsPrintJob::State::STATE_ERROR:
224 message = l10n_util::GetStringFUTF16( 225 message = l10n_util::GetStringFUTF16(
225 IDS_PRINT_JOB_ERROR_NOTIFICATION_MESSAGE, 226 IDS_PRINT_JOB_ERROR_NOTIFICATION_MESSAGE,
226 base::IntToString16(print_job_->total_page_number()), 227 base::IntToString16(print_job_->total_page_number()),
227 base::UTF8ToUTF16(print_job_->printer().display_name())); 228 base::UTF8ToUTF16(print_job_->printer().display_name()));
228 break; 229 break;
229 default: 230 default:
230 break; 231 break;
231 } 232 }
232 notification_->set_message(message); 233 notification_->set_message(message);
233 } 234 }
234 235
235 void CupsPrintJobNotification::UpdateNotificationType() { 236 void CupsPrintJobNotification::UpdateNotificationType() {
236 switch (print_job_->state()) { 237 switch (print_job_->state()) {
237 case CupsPrintJob::State::STATE_STARTED: 238 case CupsPrintJob::State::STATE_STARTED:
238 case CupsPrintJob::State::STATE_PAGE_DONE: 239 case CupsPrintJob::State::STATE_PAGE_DONE:
239 case CupsPrintJob::State::STATE_SUSPENDED: 240 case CupsPrintJob::State::STATE_SUSPENDED:
240 case CupsPrintJob::State::STATE_RESUMED: 241 case CupsPrintJob::State::STATE_RESUMED:
241 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS); 242 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
242 notification_->set_progress(print_job_->printed_page_number() * 100 / 243 notification_->set_progress(print_job_->printed_page_number() * 100 /
243 print_job_->total_page_number()); 244 print_job_->total_page_number());
244 break; 245 break;
245 case CupsPrintJob::State::STATE_NONE: 246 case CupsPrintJob::State::STATE_NONE:
246 case CupsPrintJob::State::STATE_WAITING: 247 case CupsPrintJob::State::STATE_WAITING:
247 case CupsPrintJob::State::STATE_DOCUMENT_DONE: 248 case CupsPrintJob::State::STATE_DOCUMENT_DONE:
248 case CupsPrintJob::State::STATE_ERROR: 249 case CupsPrintJob::State::STATE_ERROR:
249 default: 250 case CupsPrintJob::State::STATE_CANCELLED:
250 notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE); 251 notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE);
251 break; 252 break;
252 } 253 }
253 } 254 }
254 255
255 void CupsPrintJobNotification::UpdateNotificationButtons() { 256 void CupsPrintJobNotification::UpdateNotificationButtons() {
256 std::vector<message_center::ButtonInfo> buttons; 257 std::vector<message_center::ButtonInfo> buttons;
257 button_commands_ = GetButtonCommands(); 258 button_commands_ = GetButtonCommands();
258 for (auto& it : *button_commands_) { 259 for (auto& it : *button_commands_) {
259 message_center::ButtonInfo button_info = 260 message_center::ButtonInfo button_info =
(...skipping 13 matching lines...) Expand all
273 commands->push_back(ButtonCommand::CANCEL_PRINTING); 274 commands->push_back(ButtonCommand::CANCEL_PRINTING);
274 break; 275 break;
275 case CupsPrintJob::State::STATE_STARTED: 276 case CupsPrintJob::State::STATE_STARTED:
276 case CupsPrintJob::State::STATE_PAGE_DONE: 277 case CupsPrintJob::State::STATE_PAGE_DONE:
277 case CupsPrintJob::State::STATE_RESUMED: 278 case CupsPrintJob::State::STATE_RESUMED:
278 case CupsPrintJob::State::STATE_SUSPENDED: 279 case CupsPrintJob::State::STATE_SUSPENDED:
279 // TODO(crbug.com/679927): Add PAUSE and RESUME buttons. 280 // TODO(crbug.com/679927): Add PAUSE and RESUME buttons.
280 commands->push_back(ButtonCommand::CANCEL_PRINTING); 281 commands->push_back(ButtonCommand::CANCEL_PRINTING);
281 break; 282 break;
282 case CupsPrintJob::State::STATE_ERROR: 283 case CupsPrintJob::State::STATE_ERROR:
284 case CupsPrintJob::State::STATE_CANCELLED:
283 commands->push_back(ButtonCommand::GET_HELP); 285 commands->push_back(ButtonCommand::GET_HELP);
284 break; 286 break;
285 default: 287 default:
286 break; 288 break;
287 } 289 }
288 return commands; 290 return commands;
289 } 291 }
290 292
291 base::string16 CupsPrintJobNotification::GetButtonLabel( 293 base::string16 CupsPrintJobNotification::GetButtonLabel(
292 ButtonCommand button) const { 294 ButtonCommand button) const {
(...skipping 27 matching lines...) Expand all
320 icon = bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_PLAY); 322 icon = bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_PLAY);
321 break; 323 break;
322 case ButtonCommand::GET_HELP: 324 case ButtonCommand::GET_HELP:
323 icon = bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_HELP); 325 icon = bundle.GetImageNamed(IDR_PRINT_NOTIFICATION_HELP);
324 break; 326 break;
325 } 327 }
326 return icon; 328 return icon;
327 } 329 }
328 330
329 } // namespace chromeos 331 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698