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

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

Issue 575333002: Compile print_preview, part 2: reduce down to 260 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@I_print_preview
Patch Set: Created 6 years, 3 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 (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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 /** 49 /**
50 * Internal backing store for the data store. 50 * Internal backing store for the data store.
51 * @type {!Array.<!print_preview.Destination>} 51 * @type {!Array.<!print_preview.Destination>}
52 * @private 52 * @private
53 */ 53 */
54 this.destinations_ = []; 54 this.destinations_ = [];
55 55
56 /** 56 /**
57 * Cache used for constant lookup of destinations by origin and id. 57 * Cache used for constant lookup of destinations by origin and id.
58 * @type {object.<string, !print_preview.Destination>} 58 * @type {Object.<string, !print_preview.Destination>}
59 * @private 59 * @private
60 */ 60 */
61 this.destinationMap_ = {}; 61 this.destinationMap_ = {};
62 62
63 /** 63 /**
64 * Currently selected destination. 64 * Currently selected destination.
65 * @type {print_preview.Destination} 65 * @type {print_preview.Destination}
66 * @private 66 * @private
67 */ 67 */
68 this.selectedDestination_ = null; 68 this.selectedDestination_ = null;
(...skipping 16 matching lines...) Expand all
85 /** 85 /**
86 * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk 86 * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk
87 * mode. 87 * mode.
88 * @type {boolean} 88 * @type {boolean}
89 * @private 89 * @private
90 */ 90 */
91 this.pdfPrinterEnabled_ = false; 91 this.pdfPrinterEnabled_ = false;
92 92
93 /** 93 /**
94 * Used to fetch cloud-based print destinations. 94 * Used to fetch cloud-based print destinations.
95 * @type {print_preview.CloudPrintInterface} 95 * @type {cloudprint.CloudPrintInterface}
96 * @private 96 * @private
97 */ 97 */
98 this.cloudPrintInterface_ = null; 98 this.cloudPrintInterface_ = null;
99 99
100 /** 100 /**
101 * Maps user account to the list of origins for which destinations are 101 * Maps user account to the list of origins for which destinations are
102 * already loaded. 102 * already loaded.
103 * @type {!Object.<string, Array.<print_preview.Destination.Origin>>} 103 * @type {!Object.<string, Array.<print_preview.Destination.Origin>>}
104 * @private 104 * @private
105 */ 105 */
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 */ 264 */
265 get isLocalDestinationSearchInProgress() { 265 get isLocalDestinationSearchInProgress() {
266 return this.isLocalDestinationSearchInProgress_ || 266 return this.isLocalDestinationSearchInProgress_ ||
267 this.isPrivetDestinationSearchInProgress_; 267 this.isPrivetDestinationSearchInProgress_;
268 }, 268 },
269 269
270 /** 270 /**
271 * @return {boolean} Whether a search for cloud destinations is in progress. 271 * @return {boolean} Whether a search for cloud destinations is in progress.
272 */ 272 */
273 get isCloudDestinationSearchInProgress() { 273 get isCloudDestinationSearchInProgress() {
274 return this.cloudPrintInterface_ && 274 return !!this.cloudPrintInterface_ &&
Lei Zhang 2014/09/19 00:54:20 Is there a preference between !!foo vs. foo != nul
Vitaly Pavlenko 2014/09/19 00:57:59 I just insert the general !! cast in all cases. I
Aleksey Shlyapnikov 2014/09/19 18:54:42 This is a pointer check, why would we convert it t
Vitaly Pavlenko 2014/09/19 20:33:09 Otherwise Closure Compiler whines that we possibly
275 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; 275 this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
276 }, 276 },
277 277
278 /** 278 /**
279 * Initializes the destination store. Sets the initially selected 279 * Initializes the destination store. Sets the initially selected
280 * destination. If any inserted destinations match this ID, that destination 280 * destination. If any inserted destinations match this ID, that destination
281 * will be automatically selected. This method must be called after the 281 * will be automatically selected. This method must be called after the
282 * print_preview.AppState has been initialized. 282 * print_preview.AppState has been initialized.
283 * @param {boolean} isInAppKioskMode Whether the print preview is in App 283 * @param {boolean} isInAppKioskMode Whether the print preview is in App
284 * Kiosk mode. 284 * Kiosk mode.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 this, 336 this,
337 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); 337 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY);
338 } else { 338 } else {
339 this.selectDefaultDestination_(); 339 this.selectDefaultDestination_();
340 } 340 }
341 } 341 }
342 }, 342 },
343 343
344 /** 344 /**
345 * Sets the destination store's Google Cloud Print interface. 345 * Sets the destination store's Google Cloud Print interface.
346 * @param {!print_preview.CloudPrintInterface} cloudPrintInterface Interface 346 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface
347 * to set. 347 * to set.
348 */ 348 */
349 setCloudPrintInterface: function(cloudPrintInterface) { 349 setCloudPrintInterface: function(cloudPrintInterface) {
350 this.cloudPrintInterface_ = cloudPrintInterface; 350 this.cloudPrintInterface_ = cloudPrintInterface;
351 this.tracker_.add( 351 this.tracker_.add(
352 this.cloudPrintInterface_, 352 this.cloudPrintInterface_,
353 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE, 353 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE,
354 this.onCloudPrintSearchDone_.bind(this)); 354 this.onCloudPrintSearchDone_.bind(this));
355 this.tracker_.add( 355 this.tracker_.add(
356 this.cloudPrintInterface_, 356 this.cloudPrintInterface_,
(...skipping 16 matching lines...) Expand all
373 hasOnlyDefaultCloudDestinations: function() { 373 hasOnlyDefaultCloudDestinations: function() {
374 // TODO: Move the logic to print_preview. 374 // TODO: Move the logic to print_preview.
375 return this.destinations_.every(function(dest) { 375 return this.destinations_.every(function(dest) {
376 return dest.isLocal || 376 return dest.isLocal ||
377 dest.id == print_preview.Destination.GooglePromotedId.DOCS || 377 dest.id == print_preview.Destination.GooglePromotedId.DOCS ||
378 dest.id == print_preview.Destination.GooglePromotedId.FEDEX; 378 dest.id == print_preview.Destination.GooglePromotedId.FEDEX;
379 }); 379 });
380 }, 380 },
381 381
382 /** 382 /**
383 * @param {!print_preview.Destination} destination Destination to select. 383 * @param {print_preview.Destination} destination Destination to select.
384 */ 384 */
385 selectDestination: function(destination) { 385 selectDestination: function(destination) {
386 this.isInAutoSelectMode_ = false; 386 this.isInAutoSelectMode_ = false;
387 // When auto select expires, DESTINATION_SELECT event has to be dispatched 387 // When auto select expires, DESTINATION_SELECT event has to be dispatched
388 // anyway (see isAutoSelectDestinationInProgress() logic). 388 // anyway (see isAutoSelectDestinationInProgress() logic).
389 if (this.autoSelectTimeout_) { 389 if (this.autoSelectTimeout_) {
390 clearTimeout(this.autoSelectTimeout_); 390 clearTimeout(this.autoSelectTimeout_);
391 this.autoSelectTimeout_ = null; 391 this.autoSelectTimeout_ = null;
392 } else if (destination == this.selectedDestination_) { 392 } else if (destination == this.selectedDestination_) {
393 return; 393 return;
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 * @private 816 * @private
817 */ 817 */
818 onCloudPrintPrinterDone_: function(event) { 818 onCloudPrintPrinterDone_: function(event) {
819 this.updateDestination_(event.printer); 819 this.updateDestination_(event.printer);
820 }, 820 },
821 821
822 /** 822 /**
823 * Called when the Google Cloud Print interface fails to lookup a 823 * Called when the Google Cloud Print interface fails to lookup a
824 * destination. Selects another destination if the failed destination was 824 * destination. Selects another destination if the failed destination was
825 * the initial destination. 825 * the initial destination.
826 * @param {object} event Contains the ID of the destination that was failed 826 * @param {Object} event Contains the ID of the destination that was failed
827 * to be looked up. 827 * to be looked up.
828 * @private 828 * @private
829 */ 829 */
830 onCloudPrintPrinterFailed_: function(event) { 830 onCloudPrintPrinterFailed_: function(event) {
831 if (this.isInAutoSelectMode_ && 831 if (this.isInAutoSelectMode_ &&
832 this.sameAsPersistedDestination_(event.destinationId, 832 this.sameAsPersistedDestination_(event.destinationId,
833 event.destinationOrigin)) { 833 event.destinationOrigin)) {
834 console.error( 834 console.error(
835 'Failed to fetch last used printer caps: ' + event.destinationId); 835 'Failed to fetch last used printer caps: ' + event.destinationId);
836 this.selectDefaultDestination_(); 836 this.selectDefaultDestination_();
837 } 837 }
838 }, 838 },
839 839
840 /** 840 /**
841 * Called when a Privet printer is added to the local network. 841 * Called when a Privet printer is added to the local network.
842 * @param {object} event Contains information about the added printer. 842 * @param {Object} event Contains information about the added printer.
843 * @private 843 * @private
844 */ 844 */
845 onPrivetPrinterAdded_: function(event) { 845 onPrivetPrinterAdded_: function(event) {
846 if (event.printer.serviceName == this.waitForRegisterDestination_ && 846 if (event.printer.serviceName == this.waitForRegisterDestination_ &&
847 !event.printer.isUnregistered) { 847 !event.printer.isUnregistered) {
848 this.waitForRegisterDestination_ = null; 848 this.waitForRegisterDestination_ = null;
849 this.onDestinationsReload_(); 849 this.onDestinationsReload_();
850 } else { 850 } else {
851 this.insertDestinations_( 851 this.insertDestinations_(
852 print_preview.PrivetDestinationParser.parse(event.printer)); 852 print_preview.PrivetDestinationParser.parse(event.printer));
853 } 853 }
854 }, 854 },
855 855
856 /** 856 /**
857 * Called when capabilities for a privet printer are set. 857 * Called when capabilities for a privet printer are set.
858 * @param {object} event Contains the capabilities and printer ID. 858 * @param {Object} event Contains the capabilities and printer ID.
859 * @private 859 * @private
860 */ 860 */
861 onPrivetCapabilitiesSet_: function(event) { 861 onPrivetCapabilitiesSet_: function(event) {
862 var destinationId = event.printerId; 862 var destinationId = event.printerId;
863 var destinations = 863 var destinations =
864 print_preview.PrivetDestinationParser.parse(event.printer); 864 print_preview.PrivetDestinationParser.parse(event.printer);
865 destinations.forEach(function(dest) { 865 destinations.forEach(function(dest) {
866 dest.capabilities = event.capabilities; 866 dest.capabilities = event.capabilities;
867 this.updateDestination_(dest); 867 this.updateDestination_(dest);
868 }, this); 868 }, this);
(...skipping 11 matching lines...) Expand all
880 this.startLoadLocalDestinations(); 880 this.startLoadLocalDestinations();
881 this.startLoadCloudDestinations(); 881 this.startLoadCloudDestinations();
882 this.startLoadPrivetDestinations(); 882 this.startLoadPrivetDestinations();
883 }, 883 },
884 884
885 // TODO(vitalybuka): Remove three next functions replacing Destination.id 885 // TODO(vitalybuka): Remove three next functions replacing Destination.id
886 // and Destination.origin by complex ID. 886 // and Destination.origin by complex ID.
887 /** 887 /**
888 * Returns key to be used with {@code destinationMap_}. 888 * Returns key to be used with {@code destinationMap_}.
889 * @param {!print_preview.Destination.Origin} origin Destination origin. 889 * @param {!print_preview.Destination.Origin} origin Destination origin.
890 * @return {string} id Destination id. 890 * @param {string} id Destination id.
891 * @return {string} account User account destination is registered for. 891 * @param {string} account User account destination is registered for.
892 * @private 892 * @private
893 */ 893 */
894 getDestinationKey_: function(origin, id, account) { 894 getDestinationKey_: function(origin, id, account) {
895 return origin + '/' + id + '/' + account; 895 return origin + '/' + id + '/' + account;
896 }, 896 },
897 897
898 /** 898 /**
899 * Returns key to be used with {@code destinationMap_}. 899 * Returns key to be used with {@code destinationMap_}.
900 * @param {!print_preview.Destination} destination Destination. 900 * @param {!print_preview.Destination} destination Destination.
901 * @private 901 * @private
(...skipping 26 matching lines...) Expand all
928 return id == this.appState_.selectedDestinationId && 928 return id == this.appState_.selectedDestinationId &&
929 origin == this.appState_.selectedDestinationOrigin; 929 origin == this.appState_.selectedDestinationOrigin;
930 } 930 }
931 }; 931 };
932 932
933 // Export 933 // Export
934 return { 934 return {
935 DestinationStore: DestinationStore 935 DestinationStore: DestinationStore
936 }; 936 };
937 }); 937 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698