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

Side by Side Diff: chrome/service/cloud_print/cloud_print_proxy_backend.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
« no previous file with comments | « no previous file | chrome/service/cloud_print/printer_job_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cloud_print_proxy_backend.h" 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 proxy_id); 283 proxy_id);
284 } 284 }
285 } 285 }
286 } 286 }
287 287
288 void CloudPrintProxyBackend::Core::DoInitializeWithToken( 288 void CloudPrintProxyBackend::Core::DoInitializeWithToken(
289 const std::string cloud_print_token, 289 const std::string cloud_print_token,
290 const std::string cloud_print_xmpp_token, 290 const std::string cloud_print_xmpp_token,
291 const std::string email, const std::string& proxy_id) { 291 const std::string email, const std::string& proxy_id) {
292 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 292 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
293 LOG(INFO) << "CP_PROXY: Starting proxy, id: " << proxy_id;
293 294
294 print_system_ = 295 print_system_ =
295 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get()); 296 cloud_print::PrintSystem::CreateInstance(print_system_settings_.get());
296 if (!print_system_.get()) { 297 if (!print_system_.get()) {
297 NOTREACHED(); 298 NOTREACHED();
298 return; // No print system available, fail initalization. 299 return; // No print system available, fail initalization.
299 } 300 }
300 301
301 // TODO(sanjeevr): Validate the tokens. 302 // TODO(sanjeevr): Validate the tokens.
302 auth_token_ = cloud_print_token; 303 auth_token_ = cloud_print_token;
(...skipping 29 matching lines...) Expand all
332 333
333 void CloudPrintProxyBackend::Core::EndRegistration() { 334 void CloudPrintProxyBackend::Core::EndRegistration() {
334 request_.reset(); 335 request_.reset();
335 if (new_printers_available_) { 336 if (new_printers_available_) {
336 new_printers_available_ = false; 337 new_printers_available_ = false;
337 StartRegistration(); 338 StartRegistration();
338 } 339 }
339 } 340 }
340 341
341 void CloudPrintProxyBackend::Core::DoShutdown() { 342 void CloudPrintProxyBackend::Core::DoShutdown() {
343 LOG(INFO) << "CP_PROXY: Shutdown proxy.";
sanjeevr 2010/06/25 20:39:42 Trace proxy id here as well
342 if (print_server_watcher_ != NULL) 344 if (print_server_watcher_ != NULL)
343 print_server_watcher_->StopWatching(); 345 print_server_watcher_->StopWatching();
344 346
345 // Need to kill all running jobs. 347 // Need to kill all running jobs.
346 while (!job_handler_map_.empty()) { 348 while (!job_handler_map_.empty()) {
347 JobHandlerMap::iterator index = job_handler_map_.begin(); 349 JobHandlerMap::iterator index = job_handler_map_.begin();
348 // Shutdown will call our OnPrinterJobHandlerShutdown method which will 350 // Shutdown will call our OnPrinterJobHandlerShutdown method which will
349 // remove this from the map. 351 // remove this from the map.
350 index->second->Shutdown(); 352 index->second->Shutdown();
351 } 353 }
352 } 354 }
353 355
354 void CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters( 356 void CloudPrintProxyBackend::Core::DoRegisterSelectedPrinters(
355 const cloud_print::PrinterList& printer_list) { 357 const cloud_print::PrinterList& printer_list) {
356 if (!print_system_.get()) 358 if (!print_system_.get())
357 return; // No print system available. 359 return; // No print system available.
358 server_error_count_ = 0; 360 server_error_count_ = 0;
359 printer_list_.assign(printer_list.begin(), printer_list.end()); 361 printer_list_.assign(printer_list.begin(), printer_list.end());
360 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 362 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
361 next_upload_index_ = 0; 363 next_upload_index_ = 0;
362 RegisterNextPrinter(); 364 RegisterNextPrinter();
363 } 365 }
364 366
365 void CloudPrintProxyBackend::Core::DoHandlePrinterNotification( 367 void CloudPrintProxyBackend::Core::DoHandlePrinterNotification(
366 const std::string& printer_id) { 368 const std::string& printer_id) {
369 LOG(INFO) << "CP_PROXY: Handle printer notification, id: " << printer_id;
367 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); 370 JobHandlerMap::iterator index = job_handler_map_.find(printer_id);
368 if (index != job_handler_map_.end()) 371 if (index != job_handler_map_.end())
369 index->second->NotifyJobAvailable(); 372 index->second->NotifyJobAvailable();
370 } 373 }
371 374
372 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { 375 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() {
373 request_.reset( 376 request_.reset(
374 new URLFetcher( 377 new URLFetcher(
375 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, 378 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_,
376 proxy_id_), 379 proxy_id_),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 mime_boundary, 414 mime_boundary,
412 std::string() , &post_data); 415 std::string() , &post_data);
413 CloudPrintHelpers::AddMultipartValueForUpload( 416 CloudPrintHelpers::AddMultipartValueForUpload(
414 kPrinterStatusValue, StringPrintf("%d", info.printer_status), 417 kPrinterStatusValue, StringPrintf("%d", info.printer_status),
415 mime_boundary, std::string(), &post_data); 418 mime_boundary, std::string(), &post_data);
416 // Add printer options as tags. 419 // Add printer options as tags.
417 std::map<std::string, std::string>::const_iterator it; 420 std::map<std::string, std::string>::const_iterator it;
418 for (it = info.options.begin(); it != info.options.end(); ++it) { 421 for (it = info.options.begin(); it != info.options.end(); ++it) {
419 // TODO(gene) Escape '=' char from name. Warning for now. 422 // TODO(gene) Escape '=' char from name. Warning for now.
420 if (it->first.find('=') != std::string::npos) { 423 if (it->first.find('=') != std::string::npos) {
421 LOG(WARNING) << "CUPS option name contains '=' character"; 424 LOG(WARNING) << "CP_PROXY: CUPS option name contains '=' character";
422 NOTREACHED(); 425 NOTREACHED();
423 } 426 }
424 std::string msg(it->first); 427 std::string msg(it->first);
425 msg += "="; 428 msg += "=";
426 msg += it->second; 429 msg += it->second;
427 CloudPrintHelpers::AddMultipartValueForUpload( 430 CloudPrintHelpers::AddMultipartValueForUpload(
428 kPrinterTagValue, msg, mime_boundary, std::string(), &post_data); 431 kPrinterTagValue, msg, mime_boundary, std::string(), &post_data);
429 } 432 }
430 CloudPrintHelpers::AddMultipartValueForUpload( 433 CloudPrintHelpers::AddMultipartValueForUpload(
431 kPrinterCapsValue, last_uploaded_printer_info_.printer_capabilities, 434 kPrinterCapsValue, last_uploaded_printer_info_.printer_capabilities,
(...skipping 17 matching lines...) Expand all
449 new URLFetcher( 452 new URLFetcher(
450 CloudPrintHelpers::GetUrlForPrinterRegistration( 453 CloudPrintHelpers::GetUrlForPrinterRegistration(
451 cloud_print_server_url_), 454 cloud_print_server_url_),
452 URLFetcher::POST, this)); 455 URLFetcher::POST, this));
453 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_); 456 CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_);
454 request_->set_upload_data(mime_type, post_data); 457 request_->set_upload_data(mime_type, post_data);
455 next_response_handler_ = 458 next_response_handler_ =
456 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; 459 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse;
457 request_->Start(); 460 request_->Start();
458 } else { 461 } else {
459 LOG(ERROR) << "CP: Failed to get printer info for: " << info.printer_name; 462 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " <<
463 info.printer_name;
460 next_upload_index_++; 464 next_upload_index_++;
461 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, 465 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
462 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); 466 &CloudPrintProxyBackend::Core::RegisterNextPrinter));
463 } 467 }
464 } else { 468 } else {
465 EndRegistration(); 469 EndRegistration();
466 } 470 }
467 } 471 }
468 472
469 // URLFetcher::Delegate implementation. 473 // URLFetcher::Delegate implementation.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 HandleServerError(NewRunnableMethod(this, &Core::GetRegisteredPrinters)); 543 HandleServerError(NewRunnableMethod(this, &Core::GetRegisteredPrinters));
540 } 544 }
541 } 545 }
542 546
543 void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter( 547 void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
544 DictionaryValue* printer_data) { 548 DictionaryValue* printer_data) {
545 DCHECK(printer_data); 549 DCHECK(printer_data);
546 std::string printer_id; 550 std::string printer_id;
547 printer_data->GetString(kIdValue, &printer_id); 551 printer_data->GetString(kIdValue, &printer_id);
548 DCHECK(!printer_id.empty()); 552 DCHECK(!printer_id.empty());
553 LOG(INFO) << "CP_PROXY: Init job handler for printer id: " << printer_id;
549 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); 554 JobHandlerMap::iterator index = job_handler_map_.find(printer_id);
550 // We might already have a job handler for this printer 555 // We might already have a job handler for this printer
551 if (index == job_handler_map_.end()) { 556 if (index == job_handler_map_.end()) {
552 cloud_print::PrinterBasicInfo printer_info; 557 cloud_print::PrinterBasicInfo printer_info;
553 printer_data->GetString(kNameValue, &printer_info.printer_name); 558 printer_data->GetString(kNameValue, &printer_info.printer_name);
554 DCHECK(!printer_info.printer_name.empty()); 559 DCHECK(!printer_info.printer_name.empty());
555 printer_data->GetString(UTF8ToWide(kPrinterDescValue), 560 printer_data->GetString(UTF8ToWide(kPrinterDescValue),
556 &printer_info.printer_description); 561 &printer_info.printer_description);
557 printer_data->GetInteger(UTF8ToWide(kPrinterStatusValue), 562 printer_data->GetInteger(UTF8ToWide(kPrinterStatusValue),
558 &printer_info.printer_status); 563 &printer_info.printer_status);
559 std::string caps_hash; 564 std::string caps_hash;
560 printer_data->GetString(kPrinterCapsHashValue, &caps_hash); 565 printer_data->GetString(kPrinterCapsHashValue, &caps_hash);
561 scoped_refptr<PrinterJobHandler> job_handler; 566 scoped_refptr<PrinterJobHandler> job_handler;
562 job_handler = new PrinterJobHandler(printer_info, printer_id, caps_hash, 567 job_handler = new PrinterJobHandler(printer_info, printer_id, caps_hash,
563 auth_token_, cloud_print_server_url_, 568 auth_token_, cloud_print_server_url_,
564 print_system_.get(), this); 569 print_system_.get(), this);
565 job_handler_map_[printer_id] = job_handler; 570 job_handler_map_[printer_id] = job_handler;
566 job_handler->Initialize(); 571 job_handler->Initialize();
567 } 572 }
568 } 573 }
569 574
570 void CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse( 575 void CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse(
571 const URLFetcher* source, const GURL& url, const URLRequestStatus& status, 576 const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
572 int response_code, const ResponseCookies& cookies, 577 int response_code, const ResponseCookies& cookies,
573 const std::string& data) { 578 const std::string& data) {
579 LOG(INFO) << "CP_PROXY: Handle register printer response, code: " <<
580 response_code;
574 Task* next_task = 581 Task* next_task =
575 NewRunnableMethod(this, 582 NewRunnableMethod(this,
576 &CloudPrintProxyBackend::Core::RegisterNextPrinter); 583 &CloudPrintProxyBackend::Core::RegisterNextPrinter);
577 if (status.is_success() && (response_code == 200)) { 584 if (status.is_success() && (response_code == 200)) {
578 bool succeeded = false; 585 bool succeeded = false;
579 DictionaryValue* response_dict = NULL; 586 DictionaryValue* response_dict = NULL;
580 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict); 587 CloudPrintHelpers::ParseResponseJSON(data, &succeeded, &response_dict);
581 if (succeeded) { 588 if (succeeded) {
582 DCHECK(response_dict); 589 DCHECK(response_dict);
583 ListValue* printer_list = NULL; 590 ListValue* printer_list = NULL;
584 response_dict->GetList(kPrinterListValue, &printer_list); 591 response_dict->GetList(kPrinterListValue, &printer_list);
585 // There should be a "printers" value in the JSON 592 // There should be a "printers" value in the JSON
586 DCHECK(printer_list); 593 DCHECK(printer_list);
587 if (printer_list) { 594 if (printer_list) {
588 DictionaryValue* printer_data = NULL; 595 DictionaryValue* printer_data = NULL;
589 if (printer_list->GetDictionary(0, &printer_data)) { 596 if (printer_list->GetDictionary(0, &printer_data)) {
590 InitJobHandlerForPrinter(printer_data); 597 InitJobHandlerForPrinter(printer_data);
591 } 598 }
592 } 599 }
593 } 600 }
594 server_error_count_ = 0; 601 server_error_count_ = 0;
595 next_upload_index_++; 602 next_upload_index_++;
596 MessageLoop::current()->PostTask(FROM_HERE, next_task); 603 MessageLoop::current()->PostTask(FROM_HERE, next_task);
597 } else { 604 } else {
598 HandleServerError(next_task); 605 HandleServerError(next_task);
599 } 606 }
600 } 607 }
601 608
602 void CloudPrintProxyBackend::Core::HandleServerError(Task* task_to_retry) { 609 void CloudPrintProxyBackend::Core::HandleServerError(Task* task_to_retry) {
610 LOG(INFO) << "CP_PROXY: Server error.";
603 CloudPrintHelpers::HandleServerError( 611 CloudPrintHelpers::HandleServerError(
604 &server_error_count_, -1, kMaxRetryInterval, kBaseRetryInterval, 612 &server_error_count_, -1, kMaxRetryInterval, kBaseRetryInterval,
605 task_to_retry, NULL); 613 task_to_retry, NULL);
606 } 614 }
607 615
608 bool CloudPrintProxyBackend::Core::RemovePrinterFromList( 616 bool CloudPrintProxyBackend::Core::RemovePrinterFromList(
609 const std::string& printer_name) { 617 const std::string& printer_name) {
610 bool ret = false; 618 bool ret = false;
611 for (cloud_print::PrinterList::iterator index = printer_list_.begin(); 619 for (cloud_print::PrinterList::iterator index = printer_list_.begin();
612 index != printer_list_.end(); index++) { 620 index != printer_list_.end(); index++) {
613 if (0 == base::strcasecmp(index->printer_name.c_str(), 621 if (0 == base::strcasecmp(index->printer_name.c_str(),
614 printer_name.c_str())) { 622 printer_name.c_str())) {
615 index = printer_list_.erase(index); 623 index = printer_list_.erase(index);
616 ret = true; 624 ret = true;
617 break; 625 break;
618 } 626 }
619 } 627 }
620 return ret; 628 return ret;
621 } 629 }
622 630
623 void CloudPrintProxyBackend::Core::OnNotificationStateChange( 631 void CloudPrintProxyBackend::Core::OnNotificationStateChange(
624 bool notification_enabled) {} 632 bool notification_enabled) {}
625 633
626 void CloudPrintProxyBackend::Core::OnIncomingNotification( 634 void CloudPrintProxyBackend::Core::OnIncomingNotification(
627 const IncomingNotificationData& notification_data) { 635 const IncomingNotificationData& notification_data) {
636 LOG(INFO) << "CP_PROXY: Incoming notification.";
628 if (0 == base::strcasecmp(kCloudPrintTalkServiceUrl, 637 if (0 == base::strcasecmp(kCloudPrintTalkServiceUrl,
629 notification_data.service_url.c_str())) { 638 notification_data.service_url.c_str())) {
630 backend_->core_thread_.message_loop()->PostTask( 639 backend_->core_thread_.message_loop()->PostTask(
631 FROM_HERE, 640 FROM_HERE,
632 NewRunnableMethod( 641 NewRunnableMethod(
633 this, &CloudPrintProxyBackend::Core::DoHandlePrinterNotification, 642 this, &CloudPrintProxyBackend::Core::DoHandlePrinterNotification,
634 notification_data.service_specific_data)); 643 notification_data.service_specific_data));
635 } 644 }
636 } 645 }
637 646
638 void CloudPrintProxyBackend::Core::OnOutgoingNotification() {} 647 void CloudPrintProxyBackend::Core::OnOutgoingNotification() {}
639 648
640 // cloud_print::PrinterChangeNotifier::Delegate implementation 649 // cloud_print::PrinterChangeNotifier::Delegate implementation
641 void CloudPrintProxyBackend::Core::OnPrinterAdded() { 650 void CloudPrintProxyBackend::Core::OnPrinterAdded() {
642 if (request_.get()) { 651 if (request_.get()) {
643 new_printers_available_ = true; 652 new_printers_available_ = true;
644 } else { 653 } else {
645 StartRegistration(); 654 StartRegistration();
646 } 655 }
647 } 656 }
648 657
649 // PrinterJobHandler::Delegate implementation 658 // PrinterJobHandler::Delegate implementation
650 void CloudPrintProxyBackend::Core::OnPrinterJobHandlerShutdown( 659 void CloudPrintProxyBackend::Core::OnPrinterJobHandlerShutdown(
651 PrinterJobHandler* job_handler, const std::string& printer_id) { 660 PrinterJobHandler* job_handler, const std::string& printer_id) {
661 LOG(INFO) << "CP_PROXY: Printer job handle shutdown, id " << printer_id;
652 job_handler_map_.erase(printer_id); 662 job_handler_map_.erase(printer_id);
653 } 663 }
654 664
OLDNEW
« no previous file with comments | « no previous file | chrome/service/cloud_print/printer_job_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698