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

Unified Diff: chrome/browser/resources/print_preview/search/destination_search.js

Issue 2760753002: [CUPS] Implement the local CUPS printer setup waiting UI. (Closed)
Patch Set: nit fix. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/search/destination_search.js
diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js
index cc59b37ebf07538fe18838f8b5858be29346c12e..bd5d9e62a26c19776fc42e2e19f033649550d104 100644
--- a/chrome/browser/resources/print_preview/search/destination_search.js
+++ b/chrome/browser/resources/print_preview/search/destination_search.js
@@ -74,6 +74,12 @@ cr.define('print_preview', function() {
this.provisionalDestinationResolver_ = null;
/**
+ * The destination that is currently in configuration.
+ * @private {?print_preview.Destination}
+ */
+ this.destinationInConfiguring_ = null;
+
+ /**
* Search box used to search through the destination lists.
* @type {!print_preview.SearchBox}
* @private
@@ -223,6 +229,10 @@ cr.define('print_preview', function() {
this.onSearch_.bind(this));
this.tracker.add(
this,
+ print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST,
+ this.onDestinationConfigureRequest_.bind(this));
+ this.tracker.add(
+ this,
print_preview.DestinationListItem.EventType.SELECT,
this.onDestinationSelect_.bind(this));
this.tracker.add(
@@ -558,21 +568,79 @@ cr.define('print_preview', function() {
/**
* Called when a destination search should be executed. Filters the
* destination lists with the given query.
- * @param {Event} evt Contains the search query.
+ * @param {Event} event Contains the search query.
dpapad 2017/03/31 00:37:52 !Event
xdai1 2017/03/31 22:19:29 Done.
* @private
*/
- onSearch_: function(evt) {
- this.filterLists_(evt.queryRegExp);
+ onSearch_: function(event) {
+ this.filterLists_(event.queryRegExp);
+ },
+
+ /**
+ * Handler for {@code print_preview.DestinationListItem.EventType.
+ * CONFIGURE_REQUEST} event, which is called to check a destination list
+ * item needs to be setup on Chrome OS before being selected. Note we do not
+ * allow configuring more than one destination at the same time.
+ * @param {!Event} event Contains the destination needs to be setup.
+ * @private
+ */
+ onDestinationConfigureRequest_: function(event) {
+ var destinationItem = event.destination.isLocal ?
+ this.localList_.getDestinationItem(event.destination.id) :
+ this.cloudList_.getDestinationItem(event.destination.id);
+ assert(destinationItem != null,
+ 'User does not select a valid destination item.');
+
+ // Another printer setup is in process or the printer doesn't need to be
+ // set up. Reject the setup request directly.
+ if (this.destinationInConfiguring_ != null ||
+ event.destination.origin != print_preview.Destination.Origin.CROS ||
+ event.destination.capabilities != null) {
+ destinationItem.onConfigureRequestRejected(
+ this.destinationInConfiguring_ != null);
+ } else {
+ destinationItem.onConfigureRequestAccepted();
+ this.handleConfigureDestination_(event.destination);
+ }
+ },
+
+ /**
+ * Called When a destination needs to be setup.
+ * @param {!print_preview.Destination} destination The destination needs to
+ * be setup.
+ * @private
+ */
+ handleConfigureDestination_: function(destination) {
+ assert(destination.origin == print_preview.Destination.Origin.CROS,
+ 'Only local printer on Chrome OS requires setup.');
+ this.destinationInConfiguring_ = destination;
+ this.destinationStore_.resolveCrosDestination(destination).then(
+ /**
+ * Called when the Promise is fulfilled.
+ * @param {!print_preview.PrinterSetupResponse} response.
+ */
+ function(response) {
+ this.localList_.getDestinationItem(destination.id)
+ .onConfigureResolved(response);
+ this.destinationInConfiguring_ = null;
+ }.bind(this),
+ /**
+ * Called when the Promise is rejected.
+ */
+ function() {
+ this.localList_.getDestinationItem(destination.id)
+ .onConfigureResolved({printerId: destination.id, success: false});
dpapad 2017/03/31 00:37:52 It's generally more robust to update internal stat
xdai1 2017/03/31 22:19:29 Done.
+ this.destinationInConfiguring_ = null;
+ }.bind(this));
},
/**
* Handler for {@code print_preview.DestinationListItem.EventType.SELECT}
- * event, which is called when a destinationi list item is selected.
- * @param {Event} evt Contains the selected destination.
+ * event, which is called when a destination list item is selected.
+ * @param {Event} event Contains the selected destination.
* @private
*/
- onDestinationSelect_: function(evt) {
- this.handleOnDestinationSelect_(evt.destination);
+ onDestinationSelect_: function(event) {
+ this.handleOnDestinationSelect_(event.destination);
},
/**
@@ -583,35 +651,6 @@ cr.define('print_preview', function() {
* @private
*/
handleOnDestinationSelect_: function(destination) {
- if (destination.origin == print_preview.Destination.Origin.CROS &&
- !destination.capabilities) {
- // local printers on CrOS require setup.
- assert(!this.printerConfigurer_);
- this.printerConfigurer_ = new print_preview.CrosDestinationResolver(
- this.destinationStore_, destination);
- this.addChild(this.printerConfigurer_);
- this.printerConfigurer_.run(this.getElement()).
- then(
- /**
- * @param {!print_preview.PrinterSetupResponse} result
- * An object containing the printerId and capabilities.
- */
- function(result) {
- assert(result.printerId == destination.id);
- destination.capabilities = result.capabilities;
- this.handleOnDestinationSelect_(destination);
- }.bind(this),
- function() {
- console.warn(
- 'Failed to setup destination: ' + destination.id);
- }).
- then(function() {
- this.removeChild(this.printerConfigurer_);
- this.printerConfigurer_ = null;
- }.bind(this));
- return;
- }
-
if (destination.isProvisional) {
assert(!this.provisionalDestinationResolver_,
'Provisional destination resolver already exists.');

Powered by Google App Engine
This is Rietveld 408576698