| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 480 |
| 481 if (offline_) { | 481 if (offline_) { |
| 482 url = net::AppendQueryParameter(url, | 482 url = net::AppendQueryParameter(url, |
| 483 kPrivetURLKeyOffline, | 483 kPrivetURLKeyOffline, |
| 484 kPrivetURLValueOffline); | 484 kPrivetURLValueOffline); |
| 485 } | 485 } |
| 486 | 486 |
| 487 url_fetcher_= privet_client_->CreateURLFetcher( | 487 url_fetcher_= privet_client_->CreateURLFetcher( |
| 488 url, net::URLFetcher::POST, this); | 488 url, net::URLFetcher::POST, this); |
| 489 | 489 |
| 490 DCHECK(!data_.empty()); | 490 std::string content_type = |
| 491 url_fetcher_->SetUploadData( | 491 use_pdf_ ? kPrivetContentTypePDF : kPrivetContentTypePWGRaster; |
| 492 use_pdf_ ? kPrivetContentTypePDF : kPrivetContentTypePWGRaster, | 492 |
| 493 data_); | 493 DCHECK(!data_.empty() || !data_file_.empty()); |
| 494 |
| 495 if (!data_file_.empty()) { |
| 496 url_fetcher_->SetUploadFilePath(content_type, data_file_); |
| 497 } else { |
| 498 url_fetcher_->SetUploadData(content_type, data_); |
| 499 } |
| 494 | 500 |
| 495 url_fetcher_->Start(); | 501 url_fetcher_->Start(); |
| 496 } | 502 } |
| 497 | 503 |
| 498 void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( | 504 void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse( |
| 499 bool has_error, | 505 bool has_error, |
| 500 const base::DictionaryValue* value) { | 506 const base::DictionaryValue* value) { |
| 501 if (has_error) { | 507 if (has_error) { |
| 502 delegate_->OnPrivetPrintingError(this, 200); | 508 delegate_->OnPrivetPrintingError(this, 200); |
| 503 return; | 509 return; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 608 } |
| 603 | 609 |
| 604 void PrivetLocalPrintOperationImpl::OnNeedPrivetToken( | 610 void PrivetLocalPrintOperationImpl::OnNeedPrivetToken( |
| 605 PrivetURLFetcher* fetcher, | 611 PrivetURLFetcher* fetcher, |
| 606 const PrivetURLFetcher::TokenCallback& callback) { | 612 const PrivetURLFetcher::TokenCallback& callback) { |
| 607 privet_client_->RefreshPrivetToken(callback); | 613 privet_client_->RefreshPrivetToken(callback); |
| 608 } | 614 } |
| 609 | 615 |
| 610 void PrivetLocalPrintOperationImpl::SendData(const std::string& data) { | 616 void PrivetLocalPrintOperationImpl::SendData(const std::string& data) { |
| 611 DCHECK(started_); | 617 DCHECK(started_); |
| 618 DCHECK(data_file_.empty()); |
| 612 data_ = data; | 619 data_ = data; |
| 613 | 620 |
| 614 if (has_extended_workflow_ && !ticket_.empty()) { | 621 SendDataInternal(); |
| 615 DoCreatejob(); | 622 } |
| 616 } else { | 623 |
| 617 DoSubmitdoc(); | 624 void PrivetLocalPrintOperationImpl::SendDataFile( |
| 618 } | 625 const base::FilePath& data_file) { |
| 626 DCHECK(started_); |
| 627 DCHECK(data_.empty()); |
| 628 data_file_ = data_file; |
| 629 |
| 630 SendDataInternal(); |
| 619 } | 631 } |
| 620 | 632 |
| 621 void PrivetLocalPrintOperationImpl::SetTicket(const std::string& ticket) { | 633 void PrivetLocalPrintOperationImpl::SetTicket(const std::string& ticket) { |
| 622 DCHECK(!started_); | 634 DCHECK(!started_); |
| 623 ticket_ = ticket; | 635 ticket_ = ticket; |
| 624 } | 636 } |
| 625 | 637 |
| 626 void PrivetLocalPrintOperationImpl::SetUsername(const std::string& user) { | 638 void PrivetLocalPrintOperationImpl::SetUsername(const std::string& user) { |
| 627 DCHECK(!started_); | 639 DCHECK(!started_); |
| 628 user_= user; | 640 user_= user; |
| 629 } | 641 } |
| 630 | 642 |
| 631 void PrivetLocalPrintOperationImpl::SetJobname(const std::string& jobname) { | 643 void PrivetLocalPrintOperationImpl::SetJobname(const std::string& jobname) { |
| 632 DCHECK(!started_); | 644 DCHECK(!started_); |
| 633 jobname_ = jobname; | 645 jobname_ = jobname; |
| 634 } | 646 } |
| 635 | 647 |
| 636 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { | 648 void PrivetLocalPrintOperationImpl::SetOffline(bool offline) { |
| 637 DCHECK(!started_); | 649 DCHECK(!started_); |
| 638 offline_ = offline; | 650 offline_ = offline; |
| 639 } | 651 } |
| 640 | 652 |
| 653 void PrivetLocalPrintOperationImpl::SendDataInternal() { |
| 654 if (has_extended_workflow_ && !ticket_.empty()) { |
| 655 DoCreatejob(); |
| 656 } else { |
| 657 DoSubmitdoc(); |
| 658 } |
| 659 } |
| 660 |
| 641 PrivetHTTPClientImpl::PrivetHTTPClientImpl( | 661 PrivetHTTPClientImpl::PrivetHTTPClientImpl( |
| 642 const std::string& name, | 662 const std::string& name, |
| 643 const net::HostPortPair& host_port, | 663 const net::HostPortPair& host_port, |
| 644 net::URLRequestContextGetter* request_context) | 664 net::URLRequestContextGetter* request_context) |
| 645 : name_(name), | 665 : name_(name), |
| 646 fetcher_factory_(request_context), | 666 fetcher_factory_(request_context), |
| 647 host_port_(host_port) { | 667 host_port_(host_port) { |
| 648 } | 668 } |
| 649 | 669 |
| 650 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() { | 670 PrivetHTTPClientImpl::~PrivetHTTPClientImpl() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 TokenCallbackVector token_callbacks; | 756 TokenCallbackVector token_callbacks; |
| 737 token_callbacks_.swap(token_callbacks); | 757 token_callbacks_.swap(token_callbacks); |
| 738 | 758 |
| 739 for (TokenCallbackVector::iterator i = token_callbacks.begin(); | 759 for (TokenCallbackVector::iterator i = token_callbacks.begin(); |
| 740 i != token_callbacks.end(); i++) { | 760 i != token_callbacks.end(); i++) { |
| 741 i->Run(token); | 761 i->Run(token); |
| 742 } | 762 } |
| 743 } | 763 } |
| 744 | 764 |
| 745 } // namespace local_discovery | 765 } // namespace local_discovery |
| OLD | NEW |