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

Side by Side Diff: chrome/service/cloud_print/printer_job_handler.cc

Issue 2801019: No actual code change. Just added more logging information to help... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/service/cloud_print/printer_job_handler.h" 5 #include "chrome/service/cloud_print/printer_job_handler.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/md5.h" 9 #include "base/md5.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void PrinterJobHandler::Reset() { 64 void PrinterJobHandler::Reset() {
65 print_data_url_.clear(); 65 print_data_url_.clear();
66 job_details_.Clear(); 66 job_details_.Clear();
67 request_.reset(); 67 request_.reset();
68 print_thread_.Stop(); 68 print_thread_.Stop();
69 } 69 }
70 70
71 void PrinterJobHandler::Start() { 71 void PrinterJobHandler::Start() {
72 LOG(INFO) << "CP_PROXY: Start printer job handler, id: " << printer_id_ <<
73 ", task in progress: " << task_in_progress_;
72 if (task_in_progress_) { 74 if (task_in_progress_) {
73 // Multiple Starts can get posted because of multiple notifications 75 // Multiple Starts can get posted because of multiple notifications
74 // We want to ignore the other ones that happen when a task is in progress. 76 // We want to ignore the other ones that happen when a task is in progress.
75 return; 77 return;
76 } 78 }
77 Reset(); 79 Reset();
78 if (!shutting_down_) { 80 if (!shutting_down_) {
79 // Check if we have work to do. 81 // Check if we have work to do.
80 if (HavePendingTasks()) { 82 if (HavePendingTasks()) {
81 if (printer_delete_pending_) { 83 if (printer_delete_pending_) {
(...skipping 17 matching lines...) Expand all
99 CloudPrintHelpers::GetUrlForJobFetch( 101 CloudPrintHelpers::GetUrlForJobFetch(
100 cloud_print_server_url_, printer_id_), 102 cloud_print_server_url_, printer_id_),
101 &PrinterJobHandler::HandleJobMetadataResponse, 103 &PrinterJobHandler::HandleJobMetadataResponse,
102 &PrinterJobHandler::Stop); 104 &PrinterJobHandler::Stop);
103 } 105 }
104 } 106 }
105 } 107 }
106 } 108 }
107 109
108 void PrinterJobHandler::Stop() { 110 void PrinterJobHandler::Stop() {
111 LOG(INFO) << "CP_PROXY: Stop printer job handler, id: " << printer_id_;
109 task_in_progress_ = false; 112 task_in_progress_ = false;
110 Reset(); 113 Reset();
111 if (HavePendingTasks()) { 114 if (HavePendingTasks()) {
112 MessageLoop::current()->PostTask( 115 MessageLoop::current()->PostTask(
113 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Start)); 116 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Start));
114 } 117 }
115 } 118 }
116 119
117 void PrinterJobHandler::NotifyJobAvailable() { 120 void PrinterJobHandler::NotifyJobAvailable() {
121 LOG(INFO) << "CP_PROXY: Notify job available, id: " << printer_id_ <<
122 ", task in progress: " << task_in_progress_;
118 server_job_available_ = true; 123 server_job_available_ = true;
119 if (!task_in_progress_) { 124 if (!task_in_progress_) {
120 MessageLoop::current()->PostTask( 125 MessageLoop::current()->PostTask(
121 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Start)); 126 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Start));
122 } 127 }
123 } 128 }
124 129
125 bool PrinterJobHandler::UpdatePrinterInfo() { 130 bool PrinterJobHandler::UpdatePrinterInfo() {
131 LOG(INFO) << "CP_PROXY: Update printer info, id: " << printer_id_;
126 // We need to update the parts of the printer info that have changed 132 // We need to update the parts of the printer info that have changed
127 // (could be printer name, description, status or capabilities). 133 // (could be printer name, description, status or capabilities).
128 cloud_print::PrinterBasicInfo printer_info; 134 cloud_print::PrinterBasicInfo printer_info;
129 printer_watcher_->GetCurrentPrinterInfo(&printer_info); 135 printer_watcher_->GetCurrentPrinterInfo(&printer_info);
130 cloud_print::PrinterCapsAndDefaults printer_caps; 136 cloud_print::PrinterCapsAndDefaults printer_caps;
131 std::string post_data; 137 std::string post_data;
132 std::string mime_boundary; 138 std::string mime_boundary;
133 if (print_system_->GetPrinterCapsAndDefaults(printer_info.printer_name, 139 if (print_system_->GetPrinterCapsAndDefaults(printer_info.printer_name,
134 &printer_caps)) { 140 &printer_caps)) {
135 std::string caps_hash = MD5String(printer_caps.printer_capabilities); 141 std::string caps_hash = MD5String(printer_caps.printer_capabilities);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ret = true; 191 ret = true;
186 } 192 }
187 return ret; 193 return ret;
188 } 194 }
189 195
190 // URLFetcher::Delegate implementation. 196 // URLFetcher::Delegate implementation.
191 void PrinterJobHandler::OnURLFetchComplete( 197 void PrinterJobHandler::OnURLFetchComplete(
192 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 198 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
193 int response_code, const ResponseCookies& cookies, 199 int response_code, const ResponseCookies& cookies,
194 const std::string& data) { 200 const std::string& data) {
201 LOG(INFO) << "CP_PROXY: Printer job handler, OnURLFetchComplete, url: " <<
202 url << ", response code: " << response_code;
195 if (!shutting_down_) { 203 if (!shutting_down_) {
196 DCHECK(source == request_.get()); 204 DCHECK(source == request_.get());
197 // We need a next response handler because we are strictly a sequential 205 // We need a next response handler because we are strictly a sequential
198 // state machine. We need each response handler to tell us which state to 206 // state machine. We need each response handler to tell us which state to
199 // advance to next. 207 // advance to next.
200 DCHECK(next_response_handler_); 208 DCHECK(next_response_handler_);
201 if (!(this->*next_response_handler_)(source, url, status, 209 if (!(this->*next_response_handler_)(source, url, status,
202 response_code, cookies, data)) { 210 response_code, cookies, data)) {
203 // By contract, if the response handler returns false, it wants us to 211 // By contract, if the response handler returns false, it wants us to
204 // retry the request (upto the usual limit after which we give up and 212 // retry the request (upto the usual limit after which we give up and
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 FROM_HERE, NewRunnableMethod(index->get(), 255 FROM_HERE, NewRunnableMethod(index->get(),
248 &JobStatusUpdater::UpdateStatus)); 256 &JobStatusUpdater::UpdateStatus));
249 } 257 }
250 } 258 }
251 259
252 bool PrinterJobHandler::HandlePrinterUpdateResponse( 260 bool PrinterJobHandler::HandlePrinterUpdateResponse(
253 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 261 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
254 int response_code, const ResponseCookies& cookies, 262 int response_code, const ResponseCookies& cookies,
255 const std::string& data) { 263 const std::string& data) {
256 bool ret = false; 264 bool ret = false;
265 LOG(INFO) << "CP_PROXY: Handle printer update response, id: " << printer_id_;
257 // If there was a network error or a non-200 response (which, for our purposes 266 // If there was a network error or a non-200 response (which, for our purposes
258 // is the same as a network error), we want to retry. 267 // is the same as a network error), we want to retry.
259 if (status.is_success() && (response_code == 200)) { 268 if (status.is_success() && (response_code == 200)) {
260 bool succeeded = false; 269 bool succeeded = false;
261 DictionaryValue* response_dict = NULL; 270 DictionaryValue* response_dict = NULL;
262 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); 271 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict);
263 // If we get valid JSON back, we are done. 272 // If we get valid JSON back, we are done.
264 if (NULL != response_dict) { 273 if (NULL != response_dict) {
265 ret = true; 274 ret = true;
266 } 275 }
267 } 276 }
268 if (ret) { 277 if (ret) {
269 // We are done here. Go to the Stop state 278 // We are done here. Go to the Stop state
270 MessageLoop::current()->PostTask( 279 MessageLoop::current()->PostTask(
271 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop)); 280 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop));
272 } else { 281 } else {
273 // Since we failed to update the server, set the flag again. 282 // Since we failed to update the server, set the flag again.
274 printer_update_pending_ = true; 283 printer_update_pending_ = true;
275 } 284 }
276 return ret; 285 return ret;
277 } 286 }
278 287
279 bool PrinterJobHandler::HandlePrinterDeleteResponse( 288 bool PrinterJobHandler::HandlePrinterDeleteResponse(
280 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 289 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
281 int response_code, const ResponseCookies& cookies, 290 int response_code, const ResponseCookies& cookies,
282 const std::string& data) { 291 const std::string& data) {
283 bool ret = false; 292 bool ret = false;
293 LOG(INFO) << "CP_PROXY: Handler printer delete response, id: " << printer_id_;
284 // If there was a network error or a non-200 response (which, for our purposes 294 // If there was a network error or a non-200 response (which, for our purposes
285 // is the same as a network error), we want to retry. 295 // is the same as a network error), we want to retry.
286 if (status.is_success() && (response_code == 200)) { 296 if (status.is_success() && (response_code == 200)) {
287 bool succeeded = false; 297 bool succeeded = false;
288 DictionaryValue* response_dict = NULL; 298 DictionaryValue* response_dict = NULL;
289 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); 299 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict);
290 // If we get valid JSON back, we are done. 300 // If we get valid JSON back, we are done.
291 if (NULL != response_dict) { 301 if (NULL != response_dict) {
292 ret = true; 302 ret = true;
293 } 303 }
294 } 304 }
295 if (ret) { 305 if (ret) {
296 // The printer has been deleted. Shutdown the handler class. 306 // The printer has been deleted. Shutdown the handler class.
297 MessageLoop::current()->PostTask( 307 MessageLoop::current()->PostTask(
298 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Shutdown)); 308 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Shutdown));
299 } else { 309 } else {
300 // Since we failed to update the server, set the flag again. 310 // Since we failed to update the server, set the flag again.
301 printer_delete_pending_ = true; 311 printer_delete_pending_ = true;
302 } 312 }
303 return ret; 313 return ret;
304 } 314 }
305 315
306 bool PrinterJobHandler::HandleJobMetadataResponse( 316 bool PrinterJobHandler::HandleJobMetadataResponse(
307 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 317 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
308 int response_code, const ResponseCookies& cookies, 318 int response_code, const ResponseCookies& cookies,
309 const std::string& data) { 319 const std::string& data) {
320 LOG(INFO) << "CP_PROXY: Handle job metadata response, id: " << printer_id_;
310 // If there was a network error or a non-200 response (which, for our purposes 321 // If there was a network error or a non-200 response (which, for our purposes
311 // is the same as a network error), we want to retry. 322 // is the same as a network error), we want to retry.
312 if (!status.is_success() || (response_code != 200)) { 323 if (!status.is_success() || (response_code != 200)) {
313 return false; 324 return false;
314 } 325 }
315 bool succeeded = false; 326 bool succeeded = false;
316 DictionaryValue* response_dict = NULL; 327 DictionaryValue* response_dict = NULL;
317 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); 328 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict);
318 if (NULL == response_dict) { 329 if (NULL == response_dict) {
319 // If we did not get a valid JSON response, we need to retry. 330 // If we did not get a valid JSON response, we need to retry.
(...skipping 28 matching lines...) Expand all
348 delete response_dict; 359 delete response_dict;
349 DCHECK(next_task); 360 DCHECK(next_task);
350 MessageLoop::current()->PostTask(FROM_HERE, next_task); 361 MessageLoop::current()->PostTask(FROM_HERE, next_task);
351 return true; 362 return true;
352 } 363 }
353 364
354 bool PrinterJobHandler::HandlePrintTicketResponse( 365 bool PrinterJobHandler::HandlePrintTicketResponse(
355 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 366 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
356 int response_code, const ResponseCookies& cookies, 367 int response_code, const ResponseCookies& cookies,
357 const std::string& data) { 368 const std::string& data) {
369 LOG(INFO) << "CP_PROXY: Handle print ticket response, id: " << printer_id_;
358 // If there was a network error or a non-200 response (which, for our purposes 370 // If there was a network error or a non-200 response (which, for our purposes
359 // is the same as a network error), we want to retry. 371 // is the same as a network error), we want to retry.
360 if (!status.is_success() || (response_code != 200)) { 372 if (!status.is_success() || (response_code != 200)) {
361 return false; 373 return false;
362 } 374 }
363 if (print_system_->ValidatePrintTicket(printer_info_.printer_name, data)) { 375 if (print_system_->ValidatePrintTicket(printer_info_.printer_name, data)) {
364 job_details_.print_ticket_ = data; 376 job_details_.print_ticket_ = data;
365 MessageLoop::current()->PostTask( 377 MessageLoop::current()->PostTask(
366 FROM_HERE, 378 FROM_HERE,
367 NewRunnableMethod(this, 379 NewRunnableMethod(this,
368 &PrinterJobHandler::MakeServerRequest, 380 &PrinterJobHandler::MakeServerRequest,
369 GURL(print_data_url_.c_str()), 381 GURL(print_data_url_.c_str()),
370 &PrinterJobHandler::HandlePrintDataResponse, 382 &PrinterJobHandler::HandlePrintDataResponse,
371 &PrinterJobHandler::FailedFetchingJobData)); 383 &PrinterJobHandler::FailedFetchingJobData));
372 } else { 384 } else {
373 // The print ticket was not valid. We are done here. 385 // The print ticket was not valid. We are done here.
374 FailedFetchingJobData(); 386 FailedFetchingJobData();
375 } 387 }
376 return true; 388 return true;
377 } 389 }
378 390
379 bool PrinterJobHandler::HandlePrintDataResponse(const URLFetcher* source, 391 bool PrinterJobHandler::HandlePrintDataResponse(const URLFetcher* source,
380 const GURL& url, 392 const GURL& url,
381 const URLRequestStatus& status, 393 const URLRequestStatus& status,
382 int response_code, 394 int response_code,
383 const ResponseCookies& cookies, 395 const ResponseCookies& cookies,
384 const std::string& data) { 396 const std::string& data) {
397 LOG(INFO) << "CP_PROXY: Handle print data response, id: " << printer_id_;
385 // If there was a network error or a non-200 response (which, for our purposes 398 // If there was a network error or a non-200 response (which, for our purposes
386 // is the same as a network error), we want to retry. 399 // is the same as a network error), we want to retry.
387 if (!status.is_success() || (response_code != 200)) { 400 if (!status.is_success() || (response_code != 200)) {
388 return false; 401 return false;
389 } 402 }
390 Task* next_task = NULL; 403 Task* next_task = NULL;
391 if (file_util::CreateTemporaryFile(&job_details_.print_data_file_path_)) { 404 if (file_util::CreateTemporaryFile(&job_details_.print_data_file_path_)) {
392 int ret = file_util::WriteFile(job_details_.print_data_file_path_, 405 int ret = file_util::WriteFile(job_details_.print_data_file_path_,
393 data.c_str(), 406 data.c_str(),
394 data.length()); 407 data.length());
395 source->response_headers()->GetMimeType( 408 source->response_headers()->GetMimeType(
396 &job_details_.print_data_mime_type_); 409 &job_details_.print_data_mime_type_);
397 DCHECK(ret == static_cast<int>(data.length())); 410 DCHECK(ret == static_cast<int>(data.length()));
398 if (ret == static_cast<int>(data.length())) { 411 if (ret == static_cast<int>(data.length())) {
399 next_task = NewRunnableMethod(this, &PrinterJobHandler::StartPrinting); 412 next_task = NewRunnableMethod(this, &PrinterJobHandler::StartPrinting);
400 } 413 }
401 } 414 }
402 // If there was no task allocated above, then there was an error in 415 // If there was no task allocated above, then there was an error in
403 // saving the print data, bail out here. 416 // saving the print data, bail out here.
404 if (!next_task) { 417 if (!next_task) {
405 next_task = NewRunnableMethod(this, &PrinterJobHandler::JobFailed, 418 next_task = NewRunnableMethod(this, &PrinterJobHandler::JobFailed,
406 JOB_DOWNLOAD_FAILED); 419 JOB_DOWNLOAD_FAILED);
407 } 420 }
408 MessageLoop::current()->PostTask(FROM_HERE, next_task); 421 MessageLoop::current()->PostTask(FROM_HERE, next_task);
409 return true; 422 return true;
410 } 423 }
411 424
412 void PrinterJobHandler::StartPrinting() { 425 void PrinterJobHandler::StartPrinting() {
426 LOG(INFO) << "CP_PROXY: Start printing, id: " << printer_id_;
413 // We are done with the request object for now. 427 // We are done with the request object for now.
414 request_.reset(); 428 request_.reset();
415 if (!shutting_down_) { 429 if (!shutting_down_) {
416 if (!print_thread_.Start()) { 430 if (!print_thread_.Start()) {
417 JobFailed(PRINT_FAILED); 431 JobFailed(PRINT_FAILED);
418 } else { 432 } else {
419 print_thread_.message_loop()->PostTask( 433 print_thread_.message_loop()->PostTask(
420 FROM_HERE, NewRunnableFunction(&PrinterJobHandler::DoPrint, 434 FROM_HERE, NewRunnableFunction(&PrinterJobHandler::DoPrint,
421 job_details_, 435 job_details_,
422 printer_info_.printer_name, 436 printer_info_.printer_name,
423 print_system_, this, 437 print_system_, this,
424 MessageLoop::current())); 438 MessageLoop::current()));
425 } 439 }
426 } 440 }
427 } 441 }
428 442
429 void PrinterJobHandler::JobFailed(PrintJobError error) { 443 void PrinterJobHandler::JobFailed(PrintJobError error) {
444 LOG(INFO) << "CP_PROXY: Job failed, id: " << printer_id_;
430 if (!shutting_down_) { 445 if (!shutting_down_) {
431 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error); 446 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error);
432 } 447 }
433 } 448 }
434 449
435 void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) { 450 void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) {
451 LOG(INFO) << "CP_PROXY: Job spooled, printer id: " << printer_id_ <<
452 ", job id: " << local_job_id;
436 if (!shutting_down_) { 453 if (!shutting_down_) {
437 local_job_id_ = local_job_id; 454 local_job_id_ = local_job_id;
438 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS); 455 UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS);
439 print_thread_.Stop(); 456 print_thread_.Stop();
440 } 457 }
441 } 458 }
442 459
443 void PrinterJobHandler::Shutdown() { 460 void PrinterJobHandler::Shutdown() {
461 LOG(INFO) << "CP_PROXY: Printer job handler shutdown, id: " << printer_id_;
444 Reset(); 462 Reset();
445 shutting_down_ = true; 463 shutting_down_ = true;
446 while (!job_status_updater_list_.empty()) { 464 while (!job_status_updater_list_.empty()) {
447 // Calling Stop() will cause the OnJobCompleted to be called which will 465 // Calling Stop() will cause the OnJobCompleted to be called which will
448 // remove the updater object from the list. 466 // remove the updater object from the list.
449 job_status_updater_list_.front()->Stop(); 467 job_status_updater_list_.front()->Stop();
450 } 468 }
451 if (delegate_) { 469 if (delegate_) {
452 delegate_->OnPrinterJobHandlerShutdown(this, printer_id_); 470 delegate_->OnPrinterJobHandlerShutdown(this, printer_id_);
453 } 471 }
454 } 472 }
455 473
456 void PrinterJobHandler::HandleServerError(const GURL& url) { 474 void PrinterJobHandler::HandleServerError(const GURL& url) {
475 LOG(INFO) << "CP_PROXY: Handle server error, printer id: " << printer_id_ <<
476 ", url: " << url;
457 Task* task_to_retry = NewRunnableMethod(this, 477 Task* task_to_retry = NewRunnableMethod(this,
458 &PrinterJobHandler::FetchURL, url); 478 &PrinterJobHandler::FetchURL, url);
459 Task* task_on_give_up = NewRunnableMethod(this, next_failure_handler_); 479 Task* task_on_give_up = NewRunnableMethod(this, next_failure_handler_);
460 CloudPrintHelpers::HandleServerError(&server_error_count_, kMaxRetryCount, 480 CloudPrintHelpers::HandleServerError(&server_error_count_, kMaxRetryCount,
461 -1, kBaseRetryInterval, task_to_retry, 481 -1, kBaseRetryInterval, task_to_retry,
462 task_on_give_up); 482 task_on_give_up);
463 } 483 }
464 484
465 void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status, 485 void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status,
466 PrintJobError error) { 486 PrintJobError error) {
487 LOG(INFO) << "CP_PROXY: Update job status, id: " << printer_id_;
467 if (!shutting_down_) { 488 if (!shutting_down_) {
468 if (!job_details_.job_id_.empty()) { 489 if (!job_details_.job_id_.empty()) {
469 LOG(INFO) << "CP: Updating status, jod id: " << job_details_.job_id_ << 490 LOG(INFO) << "CP_PROXY: Updating status, jod id: " <<
470 ", status: " << status; 491 job_details_.job_id_ << ", status: " << status;
471 492
472 ResponseHandler response_handler = NULL; 493 ResponseHandler response_handler = NULL;
473 if (error == SUCCESS) { 494 if (error == SUCCESS) {
474 response_handler = 495 response_handler =
475 &PrinterJobHandler::HandleSuccessStatusUpdateResponse; 496 &PrinterJobHandler::HandleSuccessStatusUpdateResponse;
476 } else { 497 } else {
477 response_handler = 498 response_handler =
478 &PrinterJobHandler::HandleFailureStatusUpdateResponse; 499 &PrinterJobHandler::HandleFailureStatusUpdateResponse;
479 } 500 }
480 MakeServerRequest( 501 MakeServerRequest(
481 CloudPrintHelpers::GetUrlForJobStatusUpdate(cloud_print_server_url_, 502 CloudPrintHelpers::GetUrlForJobStatusUpdate(cloud_print_server_url_,
482 job_details_.job_id_, 503 job_details_.job_id_,
483 status), 504 status),
484 response_handler, 505 response_handler,
485 &PrinterJobHandler::Stop); 506 &PrinterJobHandler::Stop);
486 } 507 }
487 } 508 }
488 } 509 }
489 510
490 bool PrinterJobHandler::HandleSuccessStatusUpdateResponse( 511 bool PrinterJobHandler::HandleSuccessStatusUpdateResponse(
491 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 512 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
492 int response_code, const ResponseCookies& cookies, 513 int response_code, const ResponseCookies& cookies,
493 const std::string& data) { 514 const std::string& data) {
515 LOG(INFO) << "CP_PROXY: Handle success status update response, id: " <<
516 printer_id_;
494 // If there was a network error or a non-200 response (which, for our purposes 517 // If there was a network error or a non-200 response (which, for our purposes
495 // is the same as a network error), we want to retry. 518 // is the same as a network error), we want to retry.
496 if (!status.is_success() || (response_code != 200)) { 519 if (!status.is_success() || (response_code != 200)) {
497 return false; 520 return false;
498 } 521 }
499 // The print job has been spooled locally. We now need to create an object 522 // The print job has been spooled locally. We now need to create an object
500 // that monitors the status of the job and updates the server. 523 // that monitors the status of the job and updates the server.
501 scoped_refptr<JobStatusUpdater> job_status_updater = 524 scoped_refptr<JobStatusUpdater> job_status_updater =
502 new JobStatusUpdater(printer_info_.printer_name, job_details_.job_id_, 525 new JobStatusUpdater(printer_info_.printer_name, job_details_.job_id_,
503 local_job_id_, auth_token_, cloud_print_server_url_, 526 local_job_id_, auth_token_, cloud_print_server_url_,
(...skipping 10 matching lines...) Expand all
514 } 537 }
515 MessageLoop::current()->PostTask( 538 MessageLoop::current()->PostTask(
516 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop)); 539 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop));
517 return true; 540 return true;
518 } 541 }
519 542
520 bool PrinterJobHandler::HandleFailureStatusUpdateResponse( 543 bool PrinterJobHandler::HandleFailureStatusUpdateResponse(
521 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 544 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
522 int response_code, const ResponseCookies& cookies, 545 int response_code, const ResponseCookies& cookies,
523 const std::string& data) { 546 const std::string& data) {
547 LOG(INFO) << "CP_PROXY: Handle failure status update response, id: " <<
548 printer_id_;
524 // If there was a network error or a non-200 response (which, for our purposes 549 // If there was a network error or a non-200 response (which, for our purposes
525 // is the same as a network error), we want to retry. 550 // is the same as a network error), we want to retry.
526 if (!status.is_success() || (response_code != 200)) { 551 if (!status.is_success() || (response_code != 200)) {
527 return false; 552 return false;
528 } 553 }
529 MessageLoop::current()->PostTask( 554 MessageLoop::current()->PostTask(
530 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop)); 555 FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop));
531 return true; 556 return true;
532 } 557 }
533 558
534 void PrinterJobHandler::MakeServerRequest(const GURL& url, 559 void PrinterJobHandler::MakeServerRequest(const GURL& url,
535 ResponseHandler response_handler, 560 ResponseHandler response_handler,
536 FailureHandler failure_handler) { 561 FailureHandler failure_handler) {
562 LOG(INFO) << "CP_PROXY: Printer job handle, make server request, id: " <<
563 printer_id_ << ", url: " << url;
537 if (!shutting_down_) { 564 if (!shutting_down_) {
538 server_error_count_ = 0; 565 server_error_count_ = 0;
539 // Set up the next response handler 566 // Set up the next response handler
540 next_response_handler_ = response_handler; 567 next_response_handler_ = response_handler;
541 next_failure_handler_ = failure_handler; 568 next_failure_handler_ = failure_handler;
542 FetchURL(url); 569 FetchURL(url);
543 } 570 }
544 } 571 }
545 572
546 void PrinterJobHandler::FetchURL(const GURL& url) { 573 void PrinterJobHandler::FetchURL(const GURL& url) {
574 LOG(INFO) << "CP_PROXY: PrinterJobHandler::FetchURL, url: " << url;
547 request_.reset(new URLFetcher(url, URLFetcher::GET, this)); 575 request_.reset(new URLFetcher(url, URLFetcher::GET, this));
548 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_); 576 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_);
549 request_->Start(); 577 request_->Start();
550 } 578 }
551 579
552 bool PrinterJobHandler::HavePendingTasks() { 580 bool PrinterJobHandler::HavePendingTasks() {
553 return server_job_available_ || printer_update_pending_ || 581 return server_job_available_ || printer_update_pending_ ||
554 printer_delete_pending_; 582 printer_delete_pending_;
555 } 583 }
556 584
557 void PrinterJobHandler::FailedFetchingJobData() { 585 void PrinterJobHandler::FailedFetchingJobData() {
558 if (!shutting_down_) { 586 if (!shutting_down_) {
559 LOG(ERROR) << "CP: Failed fetching job data for printer: " << 587 LOG(ERROR) << "CP_PROXY: Failed fetching job data for printer: " <<
560 printer_info_.printer_name << ", job id: " << job_details_.job_id_; 588 printer_info_.printer_name << ", job id: " << job_details_.job_id_;
561 JobFailed(INVALID_JOB_DATA); 589 JobFailed(INVALID_JOB_DATA);
562 } 590 }
563 } 591 }
564 592
565 void PrinterJobHandler::DoPrint(const JobDetails& job_details, 593 void PrinterJobHandler::DoPrint(const JobDetails& job_details,
566 const std::string& printer_name, 594 const std::string& printer_name,
567 scoped_refptr<cloud_print::PrintSystem> print_system, 595 scoped_refptr<cloud_print::PrintSystem> print_system,
568 PrinterJobHandler* job_handler, 596 PrinterJobHandler* job_handler,
569 MessageLoop* job_message_loop) { 597 MessageLoop* job_message_loop) {
570 DCHECK(job_handler); 598 DCHECK(job_handler);
571 DCHECK(job_message_loop); 599 DCHECK(job_message_loop);
600 LOG(INFO) << "CP_PROXY: Printing: " << printer_name;
572 cloud_print::PlatformJobId job_id = -1; 601 cloud_print::PlatformJobId job_id = -1;
573 if (print_system->SpoolPrintJob(job_details.print_ticket_, 602 if (print_system->SpoolPrintJob(job_details.print_ticket_,
574 job_details.print_data_file_path_, 603 job_details.print_data_file_path_,
575 job_details.print_data_mime_type_, 604 job_details.print_data_mime_type_,
576 printer_name, 605 printer_name,
577 job_details.job_title_, &job_id)) { 606 job_details.job_title_, &job_id)) {
578 job_message_loop->PostTask(FROM_HERE, 607 job_message_loop->PostTask(FROM_HERE,
579 NewRunnableMethod(job_handler, 608 NewRunnableMethod(job_handler,
580 &PrinterJobHandler::JobSpooled, 609 &PrinterJobHandler::JobSpooled,
581 job_id)); 610 job_id));
582 } else { 611 } else {
583 job_message_loop->PostTask(FROM_HERE, 612 job_message_loop->PostTask(FROM_HERE,
584 NewRunnableMethod(job_handler, 613 NewRunnableMethod(job_handler,
585 &PrinterJobHandler::JobFailed, 614 &PrinterJobHandler::JobFailed,
586 PRINT_FAILED)); 615 PRINT_FAILED));
587 } 616 }
588 } 617 }
589 618
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698