OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_discovery/privet_http_impl.h" | 5 #include "chrome/browser/local_discovery/privet_http_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 delegate_->OnPrivetPrintingRequestPWGRaster(this); | 541 delegate_->OnPrivetPrintingRequestPWGRaster(this); |
542 } | 542 } |
543 | 543 |
544 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( | 544 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( |
545 bool has_error, | 545 bool has_error, |
546 const base::DictionaryValue* value) { | 546 const base::DictionaryValue* value) { |
547 std::string error; | 547 std::string error; |
548 // This error is only relevant in the case of extended workflow: | 548 // This error is only relevant in the case of extended workflow: |
549 // If the print job ID is invalid, retry createjob and submitdoc, | 549 // If the print job ID is invalid, retry createjob and submitdoc, |
550 // rather than simply retrying the current request. | 550 // rather than simply retrying the current request. |
551 if (has_error) { | 551 if (has_error && value->GetString(kPrivetKeyError, &error)) { |
552 if (has_extended_workflow_ && | 552 if (has_extended_workflow_ && |
553 value->GetString(kPrivetKeyError, &error) && | |
554 error == kPrivetErrorInvalidPrintJob && | 553 error == kPrivetErrorInvalidPrintJob && |
555 invalid_job_retries_ < kPrivetLocalPrintMaxRetries) { | 554 invalid_job_retries_ < kPrivetLocalPrintMaxRetries) { |
556 invalid_job_retries_++; | 555 invalid_job_retries_++; |
557 | 556 |
558 int timeout = kPrivetLocalPrintDefaultTimeout; | 557 int timeout = kPrivetLocalPrintDefaultTimeout; |
559 value->GetInteger(kPrivetKeyTimeout, &timeout); | 558 value->GetInteger(kPrivetKeyTimeout, &timeout); |
560 | 559 |
561 double random_scaling_factor = | 560 double random_scaling_factor = |
562 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; | 561 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; |
563 | 562 |
564 timeout = static_cast<int>(timeout * random_scaling_factor); | 563 timeout = static_cast<int>(timeout * random_scaling_factor); |
565 | 564 |
566 timeout = std::max(timeout, kPrivetMinimumTimeout); | 565 timeout = std::max(timeout, kPrivetMinimumTimeout); |
567 | 566 |
568 base::MessageLoop::current()->PostDelayedTask( | 567 base::MessageLoop::current()->PostDelayedTask( |
569 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob, | 568 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob, |
570 weak_factory_.GetWeakPtr()), | 569 weak_factory_.GetWeakPtr()), |
571 base::TimeDelta::FromSeconds(timeout)); | 570 base::TimeDelta::FromSeconds(timeout)); |
| 571 } else if (use_pdf_ && error == kPrivetErrorInvalidDocumentType) { |
| 572 use_pdf_ = false; |
| 573 delegate_->OnPrivetPrintingRequestPWGRaster(this); |
572 } else { | 574 } else { |
573 delegate_->OnPrivetPrintingError(this, 200); | 575 delegate_->OnPrivetPrintingError(this, 200); |
574 } | 576 } |
575 | 577 |
576 return; | 578 return; |
577 } | 579 } |
578 | 580 |
579 | |
580 // If we've gotten this far, there are no errors, so we've effectively | 581 // If we've gotten this far, there are no errors, so we've effectively |
581 // succeeded. | 582 // succeeded. |
582 delegate_->OnPrivetPrintingDone(this); | 583 delegate_->OnPrivetPrintingDone(this); |
583 } | 584 } |
584 | 585 |
585 void PrivetLocalPrintOperationImpl::OnCreatejobResponse( | 586 void PrivetLocalPrintOperationImpl::OnCreatejobResponse( |
586 bool has_error, | 587 bool has_error, |
587 const base::DictionaryValue* value) { | 588 const base::DictionaryValue* value) { |
588 if (has_error) { | 589 if (has_error) { |
589 delegate_->OnPrivetPrintingError(this, 200); | 590 delegate_->OnPrivetPrintingError(this, 200); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 DCHECK(!started_); | 653 DCHECK(!started_); |
653 jobname_ = jobname; | 654 jobname_ = jobname; |
654 } | 655 } |
655 | 656 |
656 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { | 657 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { |
657 DCHECK(!started_); | 658 DCHECK(!started_); |
658 offline_ = offline; | 659 offline_ = offline; |
659 } | 660 } |
660 | 661 |
661 void PrivetLocalPrintOperationImpl::SendDataInternal() { | 662 void PrivetLocalPrintOperationImpl::SendDataInternal() { |
662 if (has_extended_workflow_ && !ticket_.empty()) { | 663 if (has_extended_workflow_ && !ticket_.empty() && jobid_.empty()) { |
663 DoCreatejob(); | 664 DoCreatejob(); |
664 } else { | 665 } else { |
665 DoSubmitdoc(); | 666 DoSubmitdoc(); |
666 } | 667 } |
667 } | 668 } |
668 | 669 |
669 PrivetHTTPClientImpl::PrivetHTTPClientImpl( | 670 PrivetHTTPClientImpl::PrivetHTTPClientImpl( |
670 const std::string& name, | 671 const std::string& name, |
671 const net::HostPortPair& host_port, | 672 const net::HostPortPair& host_port, |
672 net::URLRequestContextGetter* request_context) | 673 net::URLRequestContextGetter* request_context) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 TokenCallbackVector token_callbacks; | 765 TokenCallbackVector token_callbacks; |
765 token_callbacks_.swap(token_callbacks); | 766 token_callbacks_.swap(token_callbacks); |
766 | 767 |
767 for (TokenCallbackVector::iterator i = token_callbacks.begin(); | 768 for (TokenCallbackVector::iterator i = token_callbacks.begin(); |
768 i != token_callbacks.end(); i++) { | 769 i != token_callbacks.end(); i++) { |
769 i->Run(token); | 770 i->Run(token); |
770 } | 771 } |
771 } | 772 } |
772 | 773 |
773 } // namespace local_discovery | 774 } // namespace local_discovery |
OLD | NEW |