| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 const PrivetURLFetcher::TokenCallback& callback) { | 362 const PrivetURLFetcher::TokenCallback& callback) { |
| 363 privet_client_->RefreshPrivetToken(callback); | 363 privet_client_->RefreshPrivetToken(callback); |
| 364 } | 364 } |
| 365 | 365 |
| 366 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( | 366 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( |
| 367 PrivetHTTPClientImpl* privet_client, | 367 PrivetHTTPClientImpl* privet_client, |
| 368 PrivetLocalPrintOperation::Delegate* delegate) | 368 PrivetLocalPrintOperation::Delegate* delegate) |
| 369 : privet_client_(privet_client), delegate_(delegate), | 369 : privet_client_(privet_client), delegate_(delegate), |
| 370 use_pdf_(false), has_capabilities_(false), has_extended_workflow_(false), | 370 use_pdf_(false), has_capabilities_(false), has_extended_workflow_(false), |
| 371 started_(false), offline_(false), invalid_job_retries_(0), | 371 started_(false), offline_(false), invalid_job_retries_(0), |
| 372 pwg_raster_converter_(PWGRasterConverter::CreateDefault()), | |
| 373 weak_factory_(this) { | 372 weak_factory_(this) { |
| 374 } | 373 } |
| 375 | 374 |
| 376 PrivetLocalPrintOperationImpl::~PrivetLocalPrintOperationImpl() { | 375 PrivetLocalPrintOperationImpl::~PrivetLocalPrintOperationImpl() { |
| 377 } | 376 } |
| 378 | 377 |
| 379 void PrivetLocalPrintOperationImpl::Start() { | 378 void PrivetLocalPrintOperationImpl::Start() { |
| 380 DCHECK(!started_); | 379 DCHECK(!started_); |
| 381 | 380 |
| 382 // We need to get the /info response so we can know which APIs are available. | 381 // We need to get the /info response so we can know which APIs are available. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 504 |
| 506 void PrivetLocalPrintOperationImpl::StartPrinting() { | 505 void PrivetLocalPrintOperationImpl::StartPrinting() { |
| 507 if (has_extended_workflow_ && !ticket_.empty() && jobid_.empty()) { | 506 if (has_extended_workflow_ && !ticket_.empty() && jobid_.empty()) { |
| 508 DoCreatejob(); | 507 DoCreatejob(); |
| 509 } else { | 508 } else { |
| 510 DoSubmitdoc(); | 509 DoSubmitdoc(); |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 | 512 |
| 514 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { | 513 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { |
| 514 if (!pwg_raster_converter_) |
| 515 pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); |
| 515 pwg_raster_converter_->Start( | 516 pwg_raster_converter_->Start( |
| 516 data_, | 517 data_, |
| 518 conversion_settings_, |
| 517 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, | 519 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, |
| 518 base::Unretained(this))); | 520 base::Unretained(this))); |
| 519 } | 521 } |
| 520 | 522 |
| 521 void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( | 523 void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( |
| 522 bool has_error, | 524 bool has_error, |
| 523 const base::DictionaryValue* value) { | 525 const base::DictionaryValue* value) { |
| 524 if (has_error) { | 526 if (has_error) { |
| 525 delegate_->OnPrivetPrintingError(this, 200); | 527 delegate_->OnPrivetPrintingError(this, 200); |
| 526 return; | 528 return; |
| 527 } | 529 } |
| 528 | 530 |
| 529 const base::ListValue* supported_content_types; | 531 const base::ListValue* supported_content_types; |
| 530 use_pdf_ = false; | 532 use_pdf_ = false; |
| 531 | 533 |
| 532 if (value->GetList(kPrivetCDDKeySupportedContentTypes, | 534 if (value->GetList(kPrivetCDDKeySupportedContentTypes, |
| 533 &supported_content_types)) { | 535 &supported_content_types)) { |
| 534 for (size_t i = 0; i < supported_content_types->GetSize(); | 536 for (size_t i = 0; i < supported_content_types->GetSize(); i++) { |
| 535 i++) { | |
| 536 const base::DictionaryValue* content_type_value; | 537 const base::DictionaryValue* content_type_value; |
| 537 std::string content_type; | 538 std::string content_type; |
| 538 | 539 |
| 539 if (supported_content_types->GetDictionary(i, &content_type_value) && | 540 if (supported_content_types->GetDictionary(i, &content_type_value) && |
| 540 content_type_value->GetString(kPrivetCDDKeyContentType, | 541 content_type_value->GetString(kPrivetCDDKeyContentType, |
| 541 &content_type) && | 542 &content_type) && |
| 542 (content_type == kPrivetContentTypePDF || | 543 (content_type == kPrivetContentTypePDF || |
| 543 content_type == kPrivetContentTypeAny) ) { | 544 content_type == kPrivetContentTypeAny) ) { |
| 544 use_pdf_ = true; | 545 use_pdf_ = true; |
| 545 } | 546 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 void PrivetLocalPrintOperationImpl::SetJobname(const std::string& jobname) { | 667 void PrivetLocalPrintOperationImpl::SetJobname(const std::string& jobname) { |
| 667 DCHECK(!started_); | 668 DCHECK(!started_); |
| 668 jobname_ = jobname; | 669 jobname_ = jobname; |
| 669 } | 670 } |
| 670 | 671 |
| 671 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { | 672 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { |
| 672 DCHECK(!started_); | 673 DCHECK(!started_); |
| 673 offline_ = offline; | 674 offline_ = offline; |
| 674 } | 675 } |
| 675 | 676 |
| 677 void PrivetLocalPrintOperationImpl::SetConversionSettings( |
| 678 const printing::PdfRenderSettings& conversion_settings) { |
| 679 DCHECK(!started_); |
| 680 conversion_settings_ = conversion_settings; |
| 681 } |
| 682 |
| 676 void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting( | 683 void PrivetLocalPrintOperationImpl::SetPWGRasterConverterForTesting( |
| 677 scoped_ptr<PWGRasterConverter> pwg_raster_converter) { | 684 scoped_ptr<PWGRasterConverter> pwg_raster_converter) { |
| 678 pwg_raster_converter_ = pwg_raster_converter.Pass(); | 685 pwg_raster_converter_ = pwg_raster_converter.Pass(); |
| 679 } | 686 } |
| 680 | 687 |
| 681 PrivetHTTPClientImpl::PrivetHTTPClientImpl( | 688 PrivetHTTPClientImpl::PrivetHTTPClientImpl( |
| 682 const std::string& name, | 689 const std::string& name, |
| 683 const net::HostPortPair& host_port, | 690 const net::HostPortPair& host_port, |
| 684 net::URLRequestContextGetter* request_context) | 691 net::URLRequestContextGetter* request_context) |
| 685 : name_(name), | 692 : name_(name), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 TokenCallbackVector token_callbacks; | 783 TokenCallbackVector token_callbacks; |
| 777 token_callbacks_.swap(token_callbacks); | 784 token_callbacks_.swap(token_callbacks); |
| 778 | 785 |
| 779 for (TokenCallbackVector::iterator i = token_callbacks.begin(); | 786 for (TokenCallbackVector::iterator i = token_callbacks.begin(); |
| 780 i != token_callbacks.end(); i++) { | 787 i != token_callbacks.end(); i++) { |
| 781 i->Run(token); | 788 i->Run(token); |
| 782 } | 789 } |
| 783 } | 790 } |
| 784 | 791 |
| 785 } // namespace local_discovery | 792 } // namespace local_discovery |
| OLD | NEW |