Commit ea32e7f8 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Fetch printer type based on destination

Using getPrinterTypeForDestination to always get the correct printer
type allows us to remove the standalone PDF check in
NativeLayer.getPrinterCapabilities.

It is safe to use Destination and RecentDestination as arguments to
getPrinterTypeForDestination because objects have |id| and |origin|.

Bug: 1112416
Change-Id: Ic94d1834485fab72c941cfc914701c26b58752c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376383Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801934}
parent 2f675c0b
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
import {assert} from 'chrome://resources/js/assert.m.js';
import {CloudOrigins, Destination, DestinationOrigin} from './destination.js';
import {CloudOrigins, Destination, DestinationOrigin, RecentDestination} from './destination.js';
/**
* Printer types for capabilities and printer list requests.
......@@ -38,8 +38,8 @@ export const originToType = function(origin) {
};
/**
* @param {!Destination} destination The destination to figure
* out the printer type of.
* @param {!Destination|!RecentDestination} destination The destination to
* figure out the printer type of.
* @return {!PrinterType} Map the destination to a PrinterType.
*/
export function getPrinterTypeForDestination(destination) {
......
......@@ -13,7 +13,7 @@ import {Metrics, MetricsContext} from '../metrics.js';
import {CapabilitiesResponse, LocalDestinationInfo, NativeLayer, NativeLayerImpl, PrinterSetupResponse, PrivetPrinterDescription, ProvisionalDestinationInfo} from '../native_layer.js';
import {Cdd, CloudOrigins, createDestinationKey, createRecentDestinationKey, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationProvisionalType, DestinationType, RecentDestination} from './destination.js';
import {DestinationMatch, originToType, PrinterType} from './destination_match.js';
import {DestinationMatch, getPrinterTypeForDestination, originToType, PrinterType} from './destination_match.js';
import {parseDestination, parseExtensionDestination} from './local_parsers.js';
/**
......@@ -467,7 +467,7 @@ export class DestinationStore extends EventTarget {
}
let error = false;
const type = originToType(origin);
const type = getPrinterTypeForDestination(serializedDestination);
switch (type) {
case PrinterType.LOCAL_PRINTER:
this.nativeLayer_.getPrinterCapabilities(id, type).then(
......@@ -740,7 +740,7 @@ export class DestinationStore extends EventTarget {
// Request destination capabilities from backend, since they are not
// known yet.
if (destination.capabilities === null) {
const type = originToType(destination.origin);
const type = getPrinterTypeForDestination(destination);
if (type !== PrinterType.CLOUD_PRINTER) {
this.nativeLayer_.getPrinterCapabilities(destination.id, type)
.then(
......
......@@ -320,11 +320,7 @@ export class NativeLayerImpl {
/** @override */
getPrinterCapabilities(destinationId, type) {
return sendWithPromise(
'getPrinterCapabilities', destinationId,
destinationId === Destination.GooglePromotedId.SAVE_AS_PDF ?
PrinterType.PDF_PRINTER :
type);
return sendWithPromise('getPrinterCapabilities', destinationId, type);
}
// <if expr="chromeos">
......
......@@ -463,7 +463,7 @@ suite(destination_store_test.suiteName, function() {
.then(function(args) {
assertEquals(
Destination.GooglePromotedId.SAVE_AS_PDF, args.destinationId);
assertEquals(PrinterType.LOCAL_PRINTER, args.printerType);
assertEquals(PrinterType.PDF_PRINTER, args.printerType);
assertEquals(
Destination.GooglePromotedId.SAVE_AS_PDF,
destinationStore.selectedDestination.id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment