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

Unified Diff: chrome/browser/resources/md_history/query_manager.js

Issue 2590093002: MD History: Move queryState to be managed by history-router (Closed)
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_history/query_manager.js
diff --git a/chrome/browser/resources/md_history/query_manager.js b/chrome/browser/resources/md_history/query_manager.js
new file mode 100644
index 0000000000000000000000000000000000000000..8ef65a278ace8efc30bb8aa2feabbe3f9bf3c532
--- /dev/null
+++ b/chrome/browser/resources/md_history/query_manager.js
@@ -0,0 +1,117 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+Polymer({
+ is: 'history-query-manager',
+
+ properties: {
+ /** @type {QueryState} */
+ queryState: {
+ type: Object,
+ notify: true,
+ },
+
+ groupedRange_: {
+ type: Number,
+ // Use a computed property to be able to compare old and new values.
+ computed: 'computeGroupedRange_(queryState.range)',
+ },
+
+ /** @type {QueryResult} */
+ queryResult: Object,
+ },
+
+ observers: [
+ 'searchTermChanged_(queryState.searchTerm)',
+ 'groupedOffsetChanged_(queryState.groupedOffset)',
+ ],
+
+ /** @private {?function(!Event)} */
+ boundOnQueryHistory_: null,
+
+ /** @override */
+ attached: function() {
+ this.boundOnQueryHistory_ = this.onQueryHistory_.bind(this);
+ document.addEventListener('query-history', this.boundOnQueryHistory_);
+ },
+
+ /** @override */
+ detached: function() {
+ document.removeEventListener('query-history', this.boundOnQueryHistory_);
+ },
+
+ /**
+ * @param {boolean} incremental
+ * @private
+ */
+ queryHistory_: function(incremental) {
+ var queryState = this.queryState;
+ // Disable querying until the first set of results have been returned. If
+ // there is a search, query immediately to support search query params from
+ // the URL.
+ var noResults = !this.queryResult || this.queryResult.results == null;
+ if (queryState.queryingDisabled ||
+ (!this.queryState.searchTerm && noResults)) {
+ return;
+ }
+
+ this.set('queryState.querying', true);
+ this.set('queryState.incremental', incremental);
+
+ var lastVisitTime = 0;
+ if (incremental) {
+ var lastVisit = this.queryResult.results.slice(-1)[0];
+ lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0;
+ }
+
+ var maxResults =
+ this.queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
+
+ chrome.send('queryHistory', [
+ queryState.searchTerm,
+ queryState.groupedOffset,
+ queryState.range,
+ lastVisitTime,
+ maxResults,
+ ]);
+ },
+
+ /**
+ * @param {!Event} e
+ * @private
+ */
+ onQueryHistory_: function(e) {
+ this.queryHistory_(/** @type {boolean} */ e.detail);
+ return false;
+ },
+
+ /** @private */
+ groupedOffsetChanged_: function() {
+ this.queryHistory_(false);
+ },
+
+ /**
+ * @param {HistoryRange} range
+ * @return {HistoryRange}
+ * @private
+ */
+ computeGroupedRange_: function(range) {
+ if (this.groupedRange_ != undefined) {
+ this.set('queryState.groupedOffset', 0);
+
+ this.queryHistory_(false);
+ this.fire('history-view-changed');
+ }
+
+ return range;
+ },
+
+ /** @private */
+ searchTermChanged_: function() {
+ this.queryHistory_(false);
+ // TODO(tsergeant): Ignore incremental searches in this metric.
+ if (this.queryState.searchTerm)
+ md_history.BrowserService.getInstance().recordAction('Search');
+ },
+});
« no previous file with comments | « chrome/browser/resources/md_history/query_manager.html ('k') | chrome/browser/resources/md_history/router.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698