| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.exportPath('settings'); | 5 cr.exportPath('settings'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A data structure used by callers to combine the results of multiple search | 8 * A data structure used by callers to combine the results of multiple search |
| 9 * requests. | 9 * requests. |
| 10 * | 10 * |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 /** @override */ | 298 /** @override */ |
| 299 exec() { | 299 exec() { |
| 300 var routePath = this.node.getAttribute('route-path'); | 300 var routePath = this.node.getAttribute('route-path'); |
| 301 var subpageTemplate = | 301 var subpageTemplate = |
| 302 this.node['_content'].querySelector('settings-subpage'); | 302 this.node['_content'].querySelector('settings-subpage'); |
| 303 subpageTemplate.setAttribute('route-path', routePath); | 303 subpageTemplate.setAttribute('route-path', routePath); |
| 304 assert(!this.node.if); | 304 assert(!this.node.if); |
| 305 this.node.if = true; | 305 this.node.if = true; |
| 306 | 306 |
| 307 return new Promise(function(resolve, reject) { | 307 return new Promise((resolve, reject) => { |
| 308 var parent = this.node.parentNode; | 308 var parent = this.node.parentNode; |
| 309 parent.async(function() { | 309 parent.async(() => { |
| 310 var renderedNode = | 310 var renderedNode = |
| 311 parent.querySelector('[route-path="' + routePath + '"]'); | 311 parent.querySelector('[route-path="' + routePath + '"]'); |
| 312 // Register a SearchAndHighlightTask for the part of the DOM that was | 312 // Register a SearchAndHighlightTask for the part of the DOM that was |
| 313 // just rendered. | 313 // just rendered. |
| 314 this.request.queue_.addSearchAndHighlightTask( | 314 this.request.queue_.addSearchAndHighlightTask( |
| 315 new SearchAndHighlightTask(this.request, assert(renderedNode))); | 315 new SearchAndHighlightTask(this.request, assert(renderedNode))); |
| 316 resolve(); | 316 resolve(); |
| 317 }.bind(this)); | 317 }); |
| 318 }.bind(this)); | 318 }); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 class SearchAndHighlightTask extends Task { | 322 class SearchAndHighlightTask extends Task { |
| 323 /** | 323 /** |
| 324 * @param {!settings.SearchRequest} request | 324 * @param {!settings.SearchRequest} request |
| 325 * @param {!Node} node | 325 * @param {!Node} node |
| 326 */ | 326 */ |
| 327 constructor(request, node) { | 327 constructor(request, node) { |
| 328 super(request, node); | 328 super(request, node); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 while (1) { | 445 while (1) { |
| 446 var task = this.popNextTask_(); | 446 var task = this.popNextTask_(); |
| 447 if (!task) { | 447 if (!task) { |
| 448 this.running_ = false; | 448 this.running_ = false; |
| 449 if (this.onEmptyCallback_) | 449 if (this.onEmptyCallback_) |
| 450 this.onEmptyCallback_(); | 450 this.onEmptyCallback_(); |
| 451 return; | 451 return; |
| 452 } | 452 } |
| 453 | 453 |
| 454 this.running_ = true; | 454 this.running_ = true; |
| 455 window.requestIdleCallback(function() { | 455 window.requestIdleCallback(() => { |
| 456 if (!this.request_.canceled) { | 456 if (!this.request_.canceled) { |
| 457 task.exec().then(function() { | 457 task.exec().then(() => { |
| 458 this.running_ = false; | 458 this.running_ = false; |
| 459 this.consumePending_(); | 459 this.consumePending_(); |
| 460 }.bind(this)); | 460 }); |
| 461 } | 461 } |
| 462 // Nothing to do otherwise. Since the request corresponding to this | 462 // Nothing to do otherwise. Since the request corresponding to this |
| 463 // queue was canceled, the queue is disposed along with the request. | 463 // queue was canceled, the queue is disposed along with the request. |
| 464 }.bind(this)); | 464 }); |
| 465 return; | 465 return; |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 class SearchRequest { | 470 class SearchRequest { |
| 471 /** | 471 /** |
| 472 * @param {string} rawQuery | 472 * @param {string} rawQuery |
| 473 * @param {!HTMLElement} root | 473 * @param {!HTMLElement} root |
| 474 */ | 474 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 489 this.canceled = false; | 489 this.canceled = false; |
| 490 | 490 |
| 491 /** @private {boolean} */ | 491 /** @private {boolean} */ |
| 492 this.foundMatches_ = false; | 492 this.foundMatches_ = false; |
| 493 | 493 |
| 494 /** @type {!PromiseResolver} */ | 494 /** @type {!PromiseResolver} */ |
| 495 this.resolver = new PromiseResolver(); | 495 this.resolver = new PromiseResolver(); |
| 496 | 496 |
| 497 /** @private {!TaskQueue} */ | 497 /** @private {!TaskQueue} */ |
| 498 this.queue_ = new TaskQueue(this); | 498 this.queue_ = new TaskQueue(this); |
| 499 this.queue_.onEmpty(function() { | 499 this.queue_.onEmpty(() => { |
| 500 this.resolver.resolve(this); | 500 this.resolver.resolve(this); |
| 501 }.bind(this)); | 501 }); |
| 502 } | 502 } |
| 503 | 503 |
| 504 /** | 504 /** |
| 505 * Fires this search request. | 505 * Fires this search request. |
| 506 */ | 506 */ |
| 507 start() { | 507 start() { |
| 508 this.queue_.addTopLevelSearchTask( | 508 this.queue_.addTopLevelSearchTask( |
| 509 new TopLevelSearchTask(this, this.root_)); | 509 new TopLevelSearchTask(this, this.root_)); |
| 510 } | 510 } |
| 511 | 511 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 request.canceled = true; | 581 request.canceled = true; |
| 582 request.resolver.resolve(request); | 582 request.resolver.resolve(request); |
| 583 }); | 583 }); |
| 584 this.activeRequests_.clear(); | 584 this.activeRequests_.clear(); |
| 585 } | 585 } |
| 586 | 586 |
| 587 this.lastSearchedText_ = text; | 587 this.lastSearchedText_ = text; |
| 588 var request = new SearchRequest(text, page); | 588 var request = new SearchRequest(text, page); |
| 589 this.activeRequests_.add(request); | 589 this.activeRequests_.add(request); |
| 590 request.start(); | 590 request.start(); |
| 591 return request.resolver.promise.then(function() { | 591 return request.resolver.promise.then(() => { |
| 592 // Stop tracking requests that finished. | 592 // Stop tracking requests that finished. |
| 593 this.activeRequests_.delete(request); | 593 this.activeRequests_.delete(request); |
| 594 return request; | 594 return request; |
| 595 }.bind(this)); | 595 }); |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 cr.addSingletonGetter(SearchManagerImpl); | 598 cr.addSingletonGetter(SearchManagerImpl); |
| 599 | 599 |
| 600 /** @return {!SearchManager} */ | 600 /** @return {!SearchManager} */ |
| 601 function getSearchManager() { | 601 function getSearchManager() { |
| 602 return SearchManagerImpl.getInstance(); | 602 return SearchManagerImpl.getInstance(); |
| 603 } | 603 } |
| 604 | 604 |
| 605 /** | 605 /** |
| 606 * Sets the SearchManager singleton instance, useful for testing. | 606 * Sets the SearchManager singleton instance, useful for testing. |
| 607 * @param {!SearchManager} searchManager | 607 * @param {!SearchManager} searchManager |
| 608 */ | 608 */ |
| 609 function setSearchManagerForTesting(searchManager) { | 609 function setSearchManagerForTesting(searchManager) { |
| 610 SearchManagerImpl.instance_ = searchManager; | 610 SearchManagerImpl.instance_ = searchManager; |
| 611 } | 611 } |
| 612 | 612 |
| 613 return { | 613 return { |
| 614 getSearchManager: getSearchManager, | 614 getSearchManager: getSearchManager, |
| 615 setSearchManagerForTesting: setSearchManagerForTesting, | 615 setSearchManagerForTesting: setSearchManagerForTesting, |
| 616 SearchRequest: SearchRequest, | 616 SearchRequest: SearchRequest, |
| 617 }; | 617 }; |
| 618 }); | 618 }); |
| OLD | NEW |