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

Side by Side Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 2918243002: Change getExtensionPrinters to cr.sendWithPromise (Closed)
Patch Set: Fix Created 3 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/native_layer.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * A data store that stores destinations and dispatches events when the data 9 * A data store that stores destinations and dispatches events when the data
10 * store changes. 10 * store changes.
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 1103
1104 /** Initializes loading of extension managed print destinations. */ 1104 /** Initializes loading of extension managed print destinations. */
1105 startLoadExtensionDestinations: function() { 1105 startLoadExtensionDestinations: function() {
1106 if (this.hasLoadedAllExtensionDestinations_) 1106 if (this.hasLoadedAllExtensionDestinations_)
1107 return; 1107 return;
1108 1108
1109 if (this.isExtensionDestinationSearchInProgress_) 1109 if (this.isExtensionDestinationSearchInProgress_)
1110 clearTimeout(this.extensionSearchTimeout_); 1110 clearTimeout(this.extensionSearchTimeout_);
1111 1111
1112 this.isExtensionDestinationSearchInProgress_ = true; 1112 this.isExtensionDestinationSearchInProgress_ = true;
1113 this.nativeLayer_.startGetExtensionDestinations(); 1113
1114 cr.addWebUIListener('extension-printers-added',
1115 this.onExtensionPrintersAdded_.bind(this));
1116 this.nativeLayer_.getExtensionPrinters().then(
1117 this.onExtensionPrintersDone_.bind(this));
1114 cr.dispatchSimpleEvent( 1118 cr.dispatchSimpleEvent(
1115 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); 1119 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
1116 this.extensionSearchTimeout_ = setTimeout( 1120 this.extensionSearchTimeout_ = setTimeout(
1117 this.endExtensionPrinterSearch_.bind(this), 1121 this.endExtensionPrinterSearch_.bind(this),
1118 DestinationStore.EXTENSION_SEARCH_DURATION_); 1122 DestinationStore.EXTENSION_SEARCH_DURATION_);
1119 }, 1123 },
1120 1124
1121 /** 1125 /**
1122 * Initiates loading of cloud destinations. 1126 * Initiates loading of cloud destinations.
1123 * @param {print_preview.DestinationOrigin=} opt_origin Search destinations 1127 * @param {print_preview.DestinationOrigin=} opt_origin Search destinations
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 this.tracker_.add( 1380 this.tracker_.add(
1377 nativeLayerEventTarget, 1381 nativeLayerEventTarget,
1378 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, 1382 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED,
1379 this.onPrivetPrinterAdded_.bind(this)); 1383 this.onPrivetPrinterAdded_.bind(this));
1380 this.tracker_.add( 1384 this.tracker_.add(
1381 nativeLayerEventTarget, 1385 nativeLayerEventTarget,
1382 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, 1386 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET,
1383 this.onPrivetCapabilitiesSet_.bind(this)); 1387 this.onPrivetCapabilitiesSet_.bind(this));
1384 this.tracker_.add( 1388 this.tracker_.add(
1385 nativeLayerEventTarget, 1389 nativeLayerEventTarget,
1386 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED,
1387 this.onExtensionPrintersAdded_.bind(this));
1388 this.tracker_.add(
1389 nativeLayerEventTarget,
1390 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, 1390 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET,
1391 this.onExtensionCapabilitiesSet_.bind(this)); 1391 this.onExtensionCapabilitiesSet_.bind(this));
1392 this.tracker_.add( 1392 this.tracker_.add(
1393 nativeLayerEventTarget, 1393 nativeLayerEventTarget,
1394 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, 1394 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED,
1395 this.handleProvisionalDestinationResolved_.bind(this)); 1395 this.handleProvisionalDestinationResolved_.bind(this));
1396 }, 1396 },
1397 1397
1398 /** 1398 /**
1399 * Creates a local PDF print destination. 1399 * Creates a local PDF print destination.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 print_preview.PrivetDestinationParser.parse(event.printer); 1618 print_preview.PrivetDestinationParser.parse(event.printer);
1619 destinations.forEach(function(dest) { 1619 destinations.forEach(function(dest) {
1620 dest.capabilities = event.capabilities; 1620 dest.capabilities = event.capabilities;
1621 this.updateDestination_(dest); 1621 this.updateDestination_(dest);
1622 }, this); 1622 }, this);
1623 }, 1623 },
1624 1624
1625 /** 1625 /**
1626 * Called when an extension responds to a getExtensionDestinations 1626 * Called when an extension responds to a getExtensionDestinations
1627 * request. 1627 * request.
1628 * @param {Object} event Contains information about list of printers 1628 * @param {Array<!{extensionId: string,
dpapad 2017/06/03 01:00:00 !Array It does not seem that the function expects
rbpotter 2017/06/03 01:52:39 Done.
1629 * reported by the extension. 1629 * extensionName: string,
1630 * {@code done} parameter is set iff this is the final list of printers 1630 * id: string,
1631 * returned as part of getExtensionDestinations request. 1631 * name: string,
1632 * description: (string|undefined),
1633 * provisional: (boolean|undefined)}>} printers The list
1634 * containing information about printers added by an extension.
1632 * @private 1635 * @private
1633 */ 1636 */
1634 onExtensionPrintersAdded_: function(event) { 1637 onExtensionPrintersAdded_: function(printers) {
1635 this.insertDestinations_(event.printers.map(function(printer) { 1638 this.insertDestinations_(printers.map(function(printer) {
dpapad 2017/06/03 01:00:00 Nit: I think this is equivalent to the shorter th
rbpotter 2017/06/03 01:52:40 Done.
1636 return print_preview.ExtensionDestinationParser.parse(printer); 1639 return print_preview.ExtensionDestinationParser.parse(printer);
1637 })); 1640 }));
1641 },
1638 1642
1639 if (event.done && this.isExtensionDestinationSearchInProgress_) { 1643 /**
1644 * Called when all extensions are done adding printers.
1645 * @param {boolean} done Whether printers are done
1646 * @private
1647 */
1648 onExtensionPrintersDone_: function(done) {
1649 if (done && this.isExtensionDestinationSearchInProgress_) {
1640 clearTimeout(this.extensionSearchTimeout_); 1650 clearTimeout(this.extensionSearchTimeout_);
1641 this.endExtensionPrinterSearch_(); 1651 this.endExtensionPrinterSearch_();
1642 } 1652 }
1643 }, 1653 },
1644 1654
1645 /** 1655 /**
1646 * Called when capabilities for an extension managed printer are set. 1656 * Called when capabilities for an extension managed printer are set.
1647 * @param {Object} event Contains the printer's capabilities and ID. 1657 * @param {Object} event Contains the printer's capabilities and ID.
1648 * @private 1658 * @private
1649 */ 1659 */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 return this.getDestinationKey_( 1705 return this.getDestinationKey_(
1696 destination.origin, destination.id, destination.account); 1706 destination.origin, destination.id, destination.account);
1697 } 1707 }
1698 }; 1708 };
1699 1709
1700 // Export 1710 // Export
1701 return { 1711 return {
1702 DestinationStore: DestinationStore 1712 DestinationStore: DestinationStore
1703 }; 1713 };
1704 }); 1714 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/print_preview/native_layer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698