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

Side by Side Diff: chrome/browser/resources/md_history/query_manager.js

Issue 2590093002: MD History: Move queryState to be managed by history-router (Closed)
Patch Set: Fix test 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 2017 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 Polymer({
6 is: 'history-query-manager',
7
8 properties: {
9 /** @type {QueryState} */
10 queryState: {
11 type: Object,
12 notify: true,
13 },
14
15 groupedRange: {
16 type: Number,
17 // This needs to be a top-level property so the observer fires with the
18 // old and new values.
19 observer: 'groupedRangeChanged_',
20 },
calamity 2017/01/17 06:22:10 A private computed property, perhaps?
tsergeant 2017/01/18 03:36:00 Done.
21
22 /** @type {QueryResult} */
23 queryResult: Object,
24 },
25
26 observers: [
27 'searchTermChanged_(queryState.searchTerm)',
28 'groupedOffsetChanged_(queryState.groupedOffset)',
29 ],
30
31 /** @private {?function(!Event)} */
32 boundOnQueryHistory_: null,
33
34 /** @override */
35 attached: function() {
36 this.boundOnQueryHistory_ = this.onQueryHistory_.bind(this);
37 document.addEventListener('query-history', this.boundOnQueryHistory_);
38 },
39
40 /** @override */
41 detached: function() {
42 document.removeEventListener('query-history', this.boundOnQueryHistory_);
43 },
44
45 /**
46 * @param {boolean} incremental
47 * @private
48 */
49 queryHistory_: function(incremental) {
50 var queryState = this.queryState;
51 // Disable querying until the first set of results have been returned. If
52 // there is a search, query immediately to support search query params from
53 // the URL.
54 var noResults = !this.queryResult || this.queryResult.results == null;
55 if (queryState.queryingDisabled ||
56 (!this.queryState.searchTerm && noResults)) {
57 return;
58 }
59
60 this.set('queryState.querying', true);
61 this.set('queryState.incremental', incremental);
62
63 var lastVisitTime = 0;
64 if (incremental) {
65 var lastVisit = this.queryResult.results.slice(-1)[0];
66 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0;
67 }
68
69 var maxResults =
70 this.queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
71
72 chrome.send('queryHistory', [
73 queryState.searchTerm, queryState.groupedOffset, queryState.range,
74 lastVisitTime, maxResults
calamity 2017/01/17 06:22:10 nit: This is pretty hard to read. What happens if
tsergeant 2017/01/18 03:36:00 ~~magic~~
75 ]);
76 },
77
78 /**
79 * @param {!Event} e
80 * @private
81 */
82 onQueryHistory_: function(e) {
83 this.queryHistory_(/** @type {boolean} */ e.detail);
84 return false;
85 },
86
87 /** @private */
88 groupedOffsetChanged_: function() {
89 this.queryHistory_(false);
90 },
91
92 /**
93 * @param {HistoryRange} range
94 * @param {HistoryRange} oldRange
95 * @private
96 */
97 groupedRangeChanged_: function(range, oldRange) {
98 if (oldRange == undefined)
99 return;
100
101 this.set('queryState.groupedOffset', 0);
102
103 this.queryHistory_(false);
104 this.fire('history-view-changed');
105 },
106
107 /** @private */
108 searchTermChanged_: function() {
109 this.queryHistory_(false);
110 // TODO(tsergeant): Ignore incremental searches in this metric.
111 if (this.queryState.searchTerm)
112 md_history.BrowserService.getInstance().recordAction('Search');
113 },
114 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698