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

Side by Side Diff: chrome/browser/resources/print_preview/search/cros_destination_resolver.js

Issue 2606043004: Perform printer setup on Chrome OS before selecting printer. (Closed)
Patch Set: fix nit Created 3 years, 11 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /** @enum {string} */
9 var ResolverState = {
10 INITIAL: 'INITIAL',
11 CONFIGURING_PRINTER: 'CONFIGURING_PRINTER',
12 ERROR: 'ERROR',
13 DONE: 'DONE'
14 };
15
16 /**
17 * Overlay used to notify the user of printer setup steps for Chrome OS
18 * printers. Printer installation can occur before any print job is executed.
19 *
20 * @param {!print_preview.DestinationStore} destinationStore The destination
21 * store containing the destination. Used as a proxy to native layer for
22 * resolving the destination.
23 * @param {!print_preview.Destination} destination The destination that has
24 * to be resolved.
25 * @constructor
26 * @extends {print_preview.Overlay}
27 */
28 function CrosDestinationResolver(destinationStore, destination) {
29 print_preview.Overlay.call(this);
30
31 /** @private {!print_preview.DestinationStore} */
32 this.destinationStore_ = destinationStore;
33 /** @private {!print_preview.Destination} */
34 this.destination_ = destination;
35
36 /** @private {ResolverState} */
dpapad 2017/01/11 20:36:30 !ResolverState
skau 2017/01/12 00:36:16 Done.
37 this.state_ = ResolverState.INITIAL;
38
39 /**
40 * Promise resolver for promise returned by {@code this.run}.
41 * @private {?PromiseResolver<!print_preview.Destination>}
42 */
43 this.promiseResolver_ = null;
44 };
45
46 CrosDestinationResolver.prototype = {
47 __proto__: print_preview.Overlay.prototype,
48
49 /** @override */
50 enterDocument: function() {
51 print_preview.Overlay.prototype.enterDocument.call(this);
52
53 this.tracker.add(
54 this.destinationStore_,
55 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED,
56 this.onDestinationResolved_.bind(this));
57
dpapad 2017/01/11 20:36:30 Unnecessary blank line.
skau 2017/01/12 00:36:16 Done.
58 },
59
60 /** @override */
61 createDom: function() {
62 this.setElementInternal(this.cloneTemplateInternal(
63 'cros-printer-resolver'));
64 },
65
66 /**
67 * Dispatch the request to resolve the destination to the native layer.
68 * @private
69 */
70 startResolveDestination_: function() {
71 assert(this.state_ == ResolverState.INITIAL);
72 assert(!this.promiseResolver_, "Promise resolver already set");
73 this.promiseResolver_ = new PromiseResolver();
74 this.destinationStore_.resolveCrosDestination(this.destination_);
75 this.setState_(ResolverState.CONFIGURING_PRINTER);
76 },
77
78 /**
79 * Handler for PRINTER_SETUP event. It finalizes the
80 * resolver state once the destination associated with the resolver gets
81 * resolved.
82 * @param {Event} event
83 * @private
84 */
85 onDestinationResolved_: function(event) {
86 assert(this.promiseResolver_, "Promise resolver collected while waiting");
dpapad 2017/01/11 20:36:30 What do you mean by "collected"? Garbage collected
skau 2017/01/12 00:36:16 The promise resolver is set to null after it has b
87 if (event.success) {
88 this.setState_(ResolverState.DONE);
89 assert(event.capabilities);
90 // event contains printerId and capabilities.
91 this.promiseResolver_.resolve(event);
92 this.setIsVisible(false);
93 } else {
94 this.setState_(ResolverState.ERROR);
95 this.promiseResolver_.reject();
96 }
97
98 this.promiseResolver_ = null;
99 },
100
101 /**
102 * Sets new resolver state and updates the UI accordingly.
103 * @param {ResolverState} state
104 * @private
105 */
106 setState_: function(state) {
107 if (this.state_ == state)
108 return;
109
110 this.state_ = state;
111 this.updateUI_();
112 },
113
114 /**
115 * Updates the resolver overlay UI to match the resolver state.
116 * @private
117 */
118 updateUI_: function() {
119 // TOOD(crbug.com/677567): Replace with meaningful UI.
dpapad 2017/01/11 20:36:30 s/TOOD/TODO
skau 2017/01/12 00:36:16 Done.
120 },
121
122 /**
123 * Initiates and shows the resolver overlay.
124 * @param {!HTMLElement} parent The element that should parent the resolver
125 * UI.
126 * @return {!Promise<!print_preview.Destination>} Promise that will be
127 * fulfilled when the destination resolving is finished.
dpapad 2017/01/11 20:36:30 Indentation off
skau 2017/01/12 00:36:16 Is there a linter that would catch this?
dpapad 2017/01/12 01:18:10 Not to my knowledge. And to be fair, this is an am
skau 2017/01/12 02:17:17 Good to know. I just tried clang-format and it de
128 */
129 run: function(parent) {
130 this.render(parent);
131 this.setIsVisible(true);
132 this.startResolveDestination_();
133
134 assert(this.promiseResolver_, 'Promise resolver not created.');
135 return this.promiseResolver_.promise;
136 }
137 };
138
139 return {
140 CrosDestinationResolver: CrosDestinationResolver
141 };
142 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698