Description was changed from ========== Print Preview: Finish removing global Javascript functions. Remove remaining global ...
3 years, 5 months ago
(2017-07-07 01:01:26 UTC)
#1
Description was changed from
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
==========
to
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
==========
rbpotter
The CQ bit was checked by rbpotter@chromium.org to run a CQ dry run
3 years, 5 months ago
(2017-07-07 01:01:43 UTC)
#2
Description was changed from ========== Print Preview: Finish removing global Javascript functions. Remove remaining global ...
3 years, 5 months ago
(2017-07-07 01:15:30 UTC)
#5
Description was changed from
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
==========
to
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
==========
Dry run: Try jobs failed on following builders: android_arm64_dbg_recipe on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_arm64_dbg_recipe/builds/303734)
3 years, 5 months ago
(2017-07-07 01:42:49 UTC)
#10
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js File chrome/browser/resources/print_preview/print_preview.js (right): https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js#newcode352 chrome/browser/resources/print_preview/print_preview.js:352: this.destinationStore_.onDestinationsReload_.bind( Two questions: 1) If onDestinationsReload_ has to be ...
3 years, 5 months ago
(2017-07-07 17:28:44 UTC)
#11
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
File chrome/browser/resources/print_preview/print_preview.js (right):
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
chrome/browser/resources/print_preview/print_preview.js:352:
this.destinationStore_.onDestinationsReload_.bind(
Two questions:
1) If onDestinationsReload_ has to be accessed from here, then it shouldn't be
private (and compiler should catch this in theory). Did it not complain?
2) Why are we adding the listener here, instead of within destinationStore_
itself? I see that we are re-using the existing listenerTracker, but this
creates an implicit dependency (in the reverse direction) between
print_preview.js and destination_store.js.
For example: Say there is a destinationStore unit test (meaning there is no
PrintPreview instance, just a DestinationStore instance) that fires
'reload-printer-list' and expects something to happen. It will not happen,
because DestinationStore does not register the listener itself, it relies on its
owning object to register listeners for it.
Same question for PreviewArea and PreviewGenerator.
rbpotter
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js File chrome/browser/resources/print_preview/print_preview.js (right): https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js#newcode352 chrome/browser/resources/print_preview/print_preview.js:352: this.destinationStore_.onDestinationsReload_.bind( On 2017/07/07 17:28:43, dpapad wrote: > Two questions: ...
3 years, 5 months ago
(2017-07-07 17:40:14 UTC)
#12
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
File chrome/browser/resources/print_preview/print_preview.js (right):
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
chrome/browser/resources/print_preview/print_preview.js:352:
this.destinationStore_.onDestinationsReload_.bind(
On 2017/07/07 17:28:43, dpapad wrote:
> Two questions:
> 1) If onDestinationsReload_ has to be accessed from here, then it shouldn't be
> private (and compiler should catch this in theory). Did it not complain?
> 2) Why are we adding the listener here, instead of within destinationStore_
> itself? I see that we are re-using the existing listenerTracker, but this
> creates an implicit dependency (in the reverse direction) between
> print_preview.js and destination_store.js.
>
> For example: Say there is a destinationStore unit test (meaning there is no
> PrintPreview instance, just a DestinationStore instance) that fires
> 'reload-printer-list' and expects something to happen. It will not happen,
> because DestinationStore does not register the listener itself, it relies on
its
> owning object to register listeners for it.
>
> Same question for PreviewArea and PreviewGenerator.
1) No, compiler did not complain. Will make it public, as it is also
accessed in line 1011.
2) Listener is added here for the same reason as privet-printer-added above;
DestinationStore (like PreviewGenerator) is not a component so does not have
a listenerTracker or an "exitDocument" function where the listeners can be
removed. Would it be better to add a "removeListeners" public function for
the DestinationStore and PreviewGenerator that PrintPreview and PreviewArea
respectively could call during exitDocument? I think in this case registering
listeners would no longer be dependent on the owning object, although
removing them still would be.
dpapad
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js File chrome/browser/resources/print_preview/print_preview.js (right): https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resources/print_preview/print_preview.js#newcode352 chrome/browser/resources/print_preview/print_preview.js:352: this.destinationStore_.onDestinationsReload_.bind( > 1) No, compiler did not complain. Will ...
3 years, 5 months ago
(2017-07-07 18:04:29 UTC)
#13
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
File chrome/browser/resources/print_preview/print_preview.js (right):
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
chrome/browser/resources/print_preview/print_preview.js:352:
this.destinationStore_.onDestinationsReload_.bind(
> 1) No, compiler did not complain. Will make it public, as it is also
> accessed in line 1011.
Ok, that's odd. I am wondering if this is related to concatenating files before
sending them to the compiler, since @private does have file-level effect AFAIK.
> 2) Listener is added here for the same reason as privet-printer-added above;
> DestinationStore (like PreviewGenerator) is not a component so does not have
> a listenerTracker or an "exitDocument" function where the listeners can be
> removed. Would it be better to add a "removeListeners" public function for
> the DestinationStore and PreviewGenerator that PrintPreview and PreviewArea
> respectively could call during exitDocument? I think in this case registering
> listeners would no longer be dependent on the owning object, although
> removing them still would be.
Thanks for the explanation, it makes sense now. I think what you are proposing
makes the code cleaner.
Mentioning a similar (maybe shorter) alternative: Keep explicitly adding
listeners from the owning object, but minimize the code residing on the owning
objects, as follows:
- Expose a public addWebUIEventListeners(listenerTracker) from DestinationStore
and PreviewGenerator, passing PrintePreview's and PreviewArea's listenerTracker
respectively.
- Call that method here, like
this.destinationStore_.addWebUIEventListeners(this.listenerTracker_);
- Within DestinationStore/PreviewGenerator, register listeners on the
|listenerTracker| that is passed as a parameter, which belongs to the parent.
- You no longer need to expose a public removeEventListeners(), since they will
be automatically removed on the owning Component's exitDocument().
WDYT?
Also I noticed some potentially existing leaking listeners in
destination_store.js setCloudPrintInterface, see [1] where we basically use an
EventTracker instance, but we never call removeAll(). So, for example if
setCloudPrintInterface() is called twice, we blindly re-register the listeners.
We should either assert that cloudPrintInterface_ is null when the method is
called (if it is only ever called once), or allow multiple calls by adding a
this.tracker_.removeAll() before re-adding the listeners. If that is indeed a
problem, let's leave this for a separate CL.
[1]
https://cs.chromium.org/chromium/src/chrome/browser/resources/print_preview/d...
rbpotter
The CQ bit was checked by rbpotter@chromium.org to run a CQ dry run
3 years, 5 months ago
(2017-07-07 19:14:40 UTC)
#14
3 years, 5 months ago
(2017-07-07 20:45:10 UTC)
#18
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
File chrome/browser/resources/print_preview/print_preview.js (right):
https://codereview.chromium.org/2969383003/diff/20001/chrome/browser/resource...
chrome/browser/resources/print_preview/print_preview.js:352:
this.destinationStore_.onDestinationsReload_.bind(
On 2017/07/07 18:04:29, dpapad wrote:
> > 1) No, compiler did not complain. Will make it public, as it is also
> > accessed in line 1011.
>
> Ok, that's odd. I am wondering if this is related to concatenating files
before
> sending them to the compiler, since @private does have file-level effect
AFAIK.
>
> > 2) Listener is added here for the same reason as privet-printer-added above;
> > DestinationStore (like PreviewGenerator) is not a component so does not have
> > a listenerTracker or an "exitDocument" function where the listeners can be
> > removed. Would it be better to add a "removeListeners" public function for
> > the DestinationStore and PreviewGenerator that PrintPreview and PreviewArea
> > respectively could call during exitDocument? I think in this case
registering
> > listeners would no longer be dependent on the owning object, although
> > removing them still would be.
>
> Thanks for the explanation, it makes sense now. I think what you are proposing
> makes the code cleaner.
>
> Mentioning a similar (maybe shorter) alternative: Keep explicitly adding
> listeners from the owning object, but minimize the code residing on the owning
> objects, as follows:
>
> - Expose a public addWebUIEventListeners(listenerTracker) from
DestinationStore
> and PreviewGenerator, passing PrintePreview's and PreviewArea's
listenerTracker
> respectively.
> - Call that method here, like
> this.destinationStore_.addWebUIEventListeners(this.listenerTracker_);
> - Within DestinationStore/PreviewGenerator, register listeners on the
> |listenerTracker| that is passed as a parameter, which belongs to the parent.
> - You no longer need to expose a public removeEventListeners(), since they
will
> be automatically removed on the owning Component's exitDocument().
>
> WDYT?
>
> Also I noticed some potentially existing leaking listeners in
> destination_store.js setCloudPrintInterface, see [1] where we basically use an
> EventTracker instance, but we never call removeAll(). So, for example if
> setCloudPrintInterface() is called twice, we blindly re-register the
listeners.
> We should either assert that cloudPrintInterface_ is null when the method is
> called (if it is only ever called once), or allow multiple calls by adding a
> this.tracker_.removeAll() before re-adding the listeners. If that is indeed a
> problem, let's leave this for a separate CL.
>
> [1]
>
https://cs.chromium.org/chromium/src/chrome/browser/resources/print_preview/d...
Done. That does seem a bit cleaner than having to remove in the owning
object, and we can pass in a listener if we need to test these objects
separately for some reason.
RE: setCloudPrintInterface, this should only ever be called once. The
use-cloud-print event is triggered by SendCloudPrintEnable [1], which
is only called in response to getInitialSettings, which happens at
initialization. So I think we should be able to assert both in
DestinationStore and InvitationStore, which has a similar issue, that
cloudPrintInterface_ is null before adding the listeners.
[1]
https://cs.chromium.org/chromium/src/chrome/browser/ui/webui/print_preview/pr...
dpapad
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resources/print_preview/data/destination_store.js File chrome/browser/resources/print_preview/data/destination_store.js (right): https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resources/print_preview/data/destination_store.js#newcode548 chrome/browser/resources/print_preview/data/destination_store.js:548: * Registers the destination store for the WebUI events ...
3 years, 5 months ago
(2017-07-07 21:12:41 UTC)
#19
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resources/print_preview/data/destination_store.js File chrome/browser/resources/print_preview/data/destination_store.js (right): https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resources/print_preview/data/destination_store.js#newcode548 chrome/browser/resources/print_preview/data/destination_store.js:548: * Registers the destination store for the WebUI events ...
3 years, 5 months ago
(2017-07-07 23:58:40 UTC)
#22
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
File chrome/browser/resources/print_preview/data/destination_store.js (right):
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
chrome/browser/resources/print_preview/data/destination_store.js:548: *
Registers the destination store for the WebUI events it responds to and
On 2017/07/07 21:12:41, dpapad wrote:
> Nit: Slightly confused by the syntax in this comment. Maybe rephrase/simplify?
Done.
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
File chrome/browser/resources/print_preview/preview_generator.js (right):
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
chrome/browser/resources/print_preview/preview_generator.js:171:
addWebUIEventListeners: function(listenerTracker) {
On 2017/07/07 21:12:41, dpapad wrote:
> Not for this CL: Just wondering, would it make sense if we take this approach
> one step further and
>
> 1) pass the |listenerTracker| in the constructor
> 2) Call addWebUIEventListeners() within the constructor itself
> 3) Make addWebUIEventListeners private.
>
> This is similar to what the previous code was doing with EventTracker, except
> that it was not injected via the constructor. It also eliminates the misuse of
> this API, since calling the public addWebUIEventListeners() could be
> accidentally called twice, whereas the constructor can't be called twice.
I think that would make sense. Will change in follow-up CL.
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/ui/webui...
File chrome/browser/ui/webui/print_preview/print_preview_handler.cc (right):
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/ui/webui...
chrome/browser/ui/webui/print_preview/print_preview_handler.cc:1183: bool
success = args->GetString(0, &callback_id);
On 2017/07/07 21:12:41, dpapad wrote:
> Nit (optional): Do we need the temp |success| variable?
>
> CHECK(args->GetString(0, &callback_id));
> ...
> CHECK(args->GetBoolean(1, &add_account));
Done.
https://codereview.chromium.org/2969383003/diff/40001/chrome/test/data/webui/...
File
chrome/test/data/webui/print_preview/print_preview_destination_search_test.js
(right):
https://codereview.chromium.org/2969383003/diff/40001/chrome/test/data/webui/...
chrome/test/data/webui/print_preview/print_preview_destination_search_test.js:127:
Mock4JS.clearMocksToVerify();
On 2017/07/07 21:12:41, dpapad wrote:
> Can we delete this now? Or is it still used?
Done. Appears there are no other mocks.
Also removed teardown().
https://codereview.chromium.org/2969383003/diff/40001/chrome/test/data/webui/...
chrome/test/data/webui/print_preview/print_preview_destination_search_test.js:146:
if (cr.isChromeOS) {
On 2017/07/07 21:12:41, dpapad wrote:
> Same question here.
This is still used to distinguish ChromeOS (which triggers a
setupPrinter call) vs non CrOS (triggers a
getLocalDestinationCapabilities call).
3 years, 5 months ago
(2017-07-08 00:25:39 UTC)
#23
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
File chrome/browser/resources/print_preview/preview_generator.js (right):
https://codereview.chromium.org/2969383003/diff/40001/chrome/browser/resource...
chrome/browser/resources/print_preview/preview_generator.js:171:
addWebUIEventListeners: function(listenerTracker) {
On 2017/07/07 23:58:39, rbpotter wrote:
> On 2017/07/07 21:12:41, dpapad wrote:
> > Not for this CL: Just wondering, would it make sense if we take this
approach
> > one step further and
> >
> > 1) pass the |listenerTracker| in the constructor
> > 2) Call addWebUIEventListeners() within the constructor itself
> > 3) Make addWebUIEventListeners private.
> >
> > This is similar to what the previous code was doing with EventTracker,
except
> > that it was not injected via the constructor. It also eliminates the misuse
of
> > this API, since calling the public addWebUIEventListeners() could be
> > accidentally called twice, whereas the constructor can't be called twice.
>
> I think that would make sense. Will change in follow-up CL.
Follow up for this and other issues at
https://codereview.chromium.org/2975663003/
dpapad
LGTM with nit. https://codereview.chromium.org/2969383003/diff/60001/chrome/test/data/webui/print_preview/native_layer_stub.js File chrome/test/data/webui/print_preview/native_layer_stub.js (right): https://codereview.chromium.org/2969383003/diff/60001/chrome/test/data/webui/print_preview/native_layer_stub.js#newcode105 chrome/test/data/webui/print_preview/native_layer_stub.js:105: pageRanges.forEach(function(range) { Nit: This logic can ...
3 years, 5 months ago
(2017-07-08 00:40:03 UTC)
#24
CQ is committing da patch. Bot data: {"patchset_id": 80001, "attempt_start_ts": 1499721202179670, "parent_rev": "a6fb014f8fb2ae32d8908a28e1e8b7b57194dde3", "commit_rev": "72f9d23b8d927f2ed78a77b0204f6ba1a6f13c0d"}
3 years, 5 months ago
(2017-07-10 22:41:35 UTC)
#35
CQ is committing da patch.
Bot data: {"patchset_id": 80001, "attempt_start_ts": 1499721202179670,
"parent_rev": "a6fb014f8fb2ae32d8908a28e1e8b7b57194dde3", "commit_rev":
"72f9d23b8d927f2ed78a77b0204f6ba1a6f13c0d"}
commit-bot: I haz the power
CQ is committing da patch. Bot data: {"patchset_id": 80001, "attempt_start_ts": 1499721202179670, "parent_rev": "09ac01b33652a775acb4f1368028c7c825d8f423", "commit_rev": "c1665b3a3c4c1b59c69bca64af65aeb334a76311"}
3 years, 5 months ago
(2017-07-10 22:41:54 UTC)
#36
CQ is committing da patch.
Bot data: {"patchset_id": 80001, "attempt_start_ts": 1499721202179670,
"parent_rev": "09ac01b33652a775acb4f1368028c7c825d8f423", "commit_rev":
"c1665b3a3c4c1b59c69bca64af65aeb334a76311"}
commit-bot: I haz the power
Description was changed from ========== Print Preview: Finish removing global Javascript functions. Remove remaining global ...
3 years, 5 months ago
(2017-07-10 22:42:08 UTC)
#37
Message was sent while issue was closed.
Description was changed from
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
==========
to
==========
Print Preview: Finish removing global Javascript functions.
Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.
BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
Review-Url: https://codereview.chromium.org/2969383003
Cr-Commit-Position: refs/heads/master@{#485430}
Committed:
https://chromium.googlesource.com/chromium/src/+/c1665b3a3c4c1b59c69bca64af65...
==========
commit-bot: I haz the power
Committed patchset #5 (id:80001) as https://chromium.googlesource.com/chromium/src/+/c1665b3a3c4c1b59c69bca64af65aeb334a76311
3 years, 5 months ago
(2017-07-10 22:42:09 UTC)
#38
Issue 2969383003: Print Preview: Finish removing global Javascript functions.
(Closed)
Created 3 years, 5 months ago by rbpotter
Modified 3 years, 5 months ago
Reviewers: dpapad
Base URL:
Comments: 17