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

Side by Side Diff: chrome/browser/local_discovery/privet_http_impl.cc

Issue 935673004: Extract creation of PWG Raster converter settings out of privet_http_impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 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
OLDNEW
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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/local_discovery/privet_constants.h" 15 #include "chrome/browser/local_discovery/privet_constants.h"
16 #include "net/base/url_util.h" 16 #include "net/base/url_util.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 #if defined(ENABLE_PRINT_PREVIEW) 19 #if defined(ENABLE_PRINT_PREVIEW)
20 #include "chrome/browser/local_discovery/pwg_raster_converter.h" 20 #include "chrome/browser/local_discovery/pwg_raster_converter.h"
21 #include "components/cloud_devices/common/printer_description.h" 21 #include "components/cloud_devices/common/printer_description.h"
22 #include "printing/pdf_render_settings.h" 22 #include "printing/pdf_render_settings.h"
23 #include "printing/pwg_raster_settings.h" 23 #include "printing/pwg_raster_settings.h"
24 #include "printing/units.h"
25 #include "ui/gfx/geometry/rect.h"
26 #include "ui/gfx/text_elider.h" 24 #include "ui/gfx/text_elider.h"
27 #endif // ENABLE_PRINT_PREVIEW 25 #endif // ENABLE_PRINT_PREVIEW
28 26
29 namespace cloud_print { 27 namespace cloud_print {
30 extern const char kContentTypeJSON[]; 28 extern const char kContentTypeJSON[];
31 } 29 }
32 30
33 namespace local_discovery { 31 namespace local_discovery {
34 32
35 namespace { 33 namespace {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 #if defined(ENABLE_PRINT_PREVIEW) 390 #if defined(ENABLE_PRINT_PREVIEW)
393 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl( 391 PrivetLocalPrintOperationImpl::PrivetLocalPrintOperationImpl(
394 PrivetHTTPClient* privet_client, 392 PrivetHTTPClient* privet_client,
395 PrivetLocalPrintOperation::Delegate* delegate) 393 PrivetLocalPrintOperation::Delegate* delegate)
396 : privet_client_(privet_client), 394 : privet_client_(privet_client),
397 delegate_(delegate), 395 delegate_(delegate),
398 use_pdf_(false), 396 use_pdf_(false),
399 has_extended_workflow_(false), 397 has_extended_workflow_(false),
400 started_(false), 398 started_(false),
401 offline_(false), 399 offline_(false),
402 dpi_(printing::kDefaultPdfDpi),
403 invalid_job_retries_(0), 400 invalid_job_retries_(0),
404 weak_factory_(this) { 401 weak_factory_(this) {
405 } 402 }
406 403
407 PrivetLocalPrintOperationImpl::~PrivetLocalPrintOperationImpl() { 404 PrivetLocalPrintOperationImpl::~PrivetLocalPrintOperationImpl() {
408 } 405 }
409 406
410 void PrivetLocalPrintOperationImpl::Start() { 407 void PrivetLocalPrintOperationImpl::Start() {
411 DCHECK(!started_); 408 DCHECK(!started_);
412 409
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 442 }
446 443
447 StartInitialRequest(); 444 StartInitialRequest();
448 } else { 445 } else {
449 delegate_->OnPrivetPrintingError(this, -1); 446 delegate_->OnPrivetPrintingError(this, -1);
450 } 447 }
451 } 448 }
452 449
453 void PrivetLocalPrintOperationImpl::StartInitialRequest() { 450 void PrivetLocalPrintOperationImpl::StartInitialRequest() {
454 use_pdf_ = false; 451 use_pdf_ = false;
455 using namespace cloud_devices::printer; 452 cloud_devices::printer::ContentTypesCapability content_types;
456 ContentTypesCapability content_types;
457 if (content_types.LoadFrom(capabilities_)) { 453 if (content_types.LoadFrom(capabilities_)) {
458 use_pdf_ = content_types.Contains(kPrivetContentTypePDF) || 454 use_pdf_ = content_types.Contains(kPrivetContentTypePDF) ||
459 content_types.Contains(kPrivetContentTypeAny); 455 content_types.Contains(kPrivetContentTypeAny);
460 } 456 }
461 457
462 if (use_pdf_) { 458 if (use_pdf_) {
463 StartPrinting(); 459 StartPrinting();
464 } else { 460 } else {
465 DpiCapability dpis;
466 if (dpis.LoadFrom(capabilities_)) {
467 dpi_ = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical);
468 }
469 StartConvertToPWG(); 461 StartConvertToPWG();
470 } 462 }
471 } 463 }
472 464
473 void PrivetLocalPrintOperationImpl::DoCreatejob() { 465 void PrivetLocalPrintOperationImpl::DoCreatejob() {
474 current_response_ = base::Bind( 466 current_response_ = base::Bind(
475 &PrivetLocalPrintOperationImpl::OnCreatejobResponse, 467 &PrivetLocalPrintOperationImpl::OnCreatejobResponse,
476 base::Unretained(this)); 468 base::Unretained(this));
477 469
478 url_fetcher_ = privet_client_->CreateURLFetcher( 470 url_fetcher_ = privet_client_->CreateURLFetcher(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 531 }
540 532
541 void PrivetLocalPrintOperationImpl::StartPrinting() { 533 void PrivetLocalPrintOperationImpl::StartPrinting() {
542 if (has_extended_workflow_ && jobid_.empty()) { 534 if (has_extended_workflow_ && jobid_.empty()) {
543 DoCreatejob(); 535 DoCreatejob();
544 } else { 536 } else {
545 DoSubmitdoc(); 537 DoSubmitdoc();
546 } 538 }
547 } 539 }
548 540
549 void PrivetLocalPrintOperationImpl::FillPwgRasterSettings(
550 printing::PwgRasterSettings* transform_settings) {
551 using namespace cloud_devices::printer;
552 PwgRasterConfigCapability raster_capability;
553 // If the raster capability fails to load, raster_capability will contain
554 // the default value.
555 raster_capability.LoadFrom(capabilities_);
556
557 DuplexTicketItem duplex_item;
558 DuplexType duplex_value = NO_DUPLEX;
559
560 DocumentSheetBack document_sheet_back =
561 raster_capability.value().document_sheet_back;
562
563 if (duplex_item.LoadFrom(ticket_)) {
564 duplex_value = duplex_item.value();
565 }
566
567 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL;
568 switch (duplex_value) {
569 case NO_DUPLEX:
570 transform_settings->odd_page_transform = printing::TRANSFORM_NORMAL;
571 break;
572 case LONG_EDGE:
573 if (document_sheet_back == ROTATED) {
574 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180;
575 } else if (document_sheet_back == FLIPPED) {
576 transform_settings->odd_page_transform =
577 printing::TRANSFORM_FLIP_VERTICAL;
578 }
579 break;
580 case SHORT_EDGE:
581 if (document_sheet_back == MANUAL_TUMBLE) {
582 transform_settings->odd_page_transform = printing::TRANSFORM_ROTATE_180;
583 } else if (document_sheet_back == FLIPPED) {
584 transform_settings->odd_page_transform =
585 printing::TRANSFORM_FLIP_HORIZONTAL;
586 }
587 }
588
589 transform_settings->rotate_all_pages =
590 raster_capability.value().rotate_all_pages;
591
592 transform_settings->reverse_page_order =
593 raster_capability.value().reverse_order_streaming;
594 }
595
596 void PrivetLocalPrintOperationImpl::StartConvertToPWG() { 541 void PrivetLocalPrintOperationImpl::StartConvertToPWG() {
597 printing::PwgRasterSettings transform_settings;
598
599 FillPwgRasterSettings(&transform_settings);
600
601 if (!pwg_raster_converter_) 542 if (!pwg_raster_converter_)
602 pwg_raster_converter_ = PWGRasterConverter::CreateDefault(); 543 pwg_raster_converter_ = PWGRasterConverter::CreateDefault();
603 544
604 double scale = dpi_;
605 scale /= printing::kPointsPerInch;
606 // Make vertical rectangle to optimize streaming to printer. Fix orientation
607 // by autorotate.
608 gfx::Rect area(std::min(page_size_.width(), page_size_.height()) * scale,
609 std::max(page_size_.width(), page_size_.height()) * scale);
610 pwg_raster_converter_->Start( 545 pwg_raster_converter_->Start(
611 data_.get(), 546 data_.get(),
612 printing::PdfRenderSettings(area, dpi_, true), 547 PWGRasterConverter::GetConversionSettings(capabilities_, page_size_),
613 transform_settings, 548 PWGRasterConverter::GetBitmapSettings(capabilities_, ticket_),
614 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted, 549 base::Bind(&PrivetLocalPrintOperationImpl::OnPWGRasterConverted,
615 base::Unretained(this))); 550 base::Unretained(this)));
616 } 551 }
617 552
618 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse( 553 void PrivetLocalPrintOperationImpl::OnSubmitdocResponse(
619 bool has_error, 554 bool has_error,
620 const base::DictionaryValue* value) { 555 const base::DictionaryValue* value) {
621 std::string error; 556 std::string error;
622 // This error is only relevant in the case of extended workflow: 557 // This error is only relevant in the case of extended workflow:
623 // If the print job ID is invalid, retry createjob and submitdoc, 558 // If the print job ID is invalid, retry createjob and submitdoc,
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 PrivetLocalPrintOperation::Delegate* delegate) { 791 PrivetLocalPrintOperation::Delegate* delegate) {
857 #if defined(ENABLE_PRINT_PREVIEW) 792 #if defined(ENABLE_PRINT_PREVIEW)
858 return scoped_ptr<PrivetLocalPrintOperation>( 793 return scoped_ptr<PrivetLocalPrintOperation>(
859 new PrivetLocalPrintOperationImpl(info_client(), delegate)); 794 new PrivetLocalPrintOperationImpl(info_client(), delegate));
860 #else 795 #else
861 return scoped_ptr<PrivetLocalPrintOperation>(); 796 return scoped_ptr<PrivetLocalPrintOperation>();
862 #endif // ENABLE_PRINT_PREVIEW 797 #endif // ENABLE_PRINT_PREVIEW
863 } 798 }
864 799
865 } // namespace local_discovery 800 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.h ('k') | chrome/browser/local_discovery/pwg_raster_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698