Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 return; | 397 return; |
| 398 } | 398 } |
| 399 | 399 |
| 400 input_ = input; | 400 input_ = input; |
| 401 | 401 |
| 402 DoHistoryQuery(minimal_changes); | 402 DoHistoryQuery(minimal_changes); |
| 403 StartOrStopSuggestQuery(minimal_changes); | 403 StartOrStopSuggestQuery(minimal_changes); |
| 404 UpdateMatches(); | 404 UpdateMatches(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void SearchProvider::Stop(bool clear_cached_results) { | |
| 408 StopSuggest(); | |
| 409 done_ = true; | |
| 410 | |
| 411 if (clear_cached_results) | |
| 412 ClearAllResults(); | |
| 413 } | |
| 414 | |
| 415 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 407 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
| 416 DCHECK(!done_); | 408 DCHECK(!done_); |
| 417 suggest_results_pending_--; | 409 suggest_results_pending_--; |
| 418 LogOmniboxSuggestRequest(REPLY_RECEIVED); | 410 LogOmniboxSuggestRequest(REPLY_RECEIVED); |
| 419 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. | 411 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. |
| 420 | 412 |
| 421 const bool is_keyword = (source == keyword_fetcher_.get()); | 413 const bool is_keyword = (source == keyword_fetcher_.get()); |
| 422 // Ensure the request succeeded and that the provider used is still available. | 414 // Ensure the request succeeded and that the provider used is still available. |
| 423 // A verbatim match cannot be generated without this provider, causing errors. | 415 // A verbatim match cannot be generated without this provider, causing errors. |
| 424 const bool request_succeeded = | 416 const bool request_succeeded = |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 const SuggestResult& result) const { | 478 const SuggestResult& result) const { |
| 487 return result.from_keyword_provider() ? keyword_input_ : input_; | 479 return result.from_keyword_provider() ? keyword_input_ : input_; |
| 488 } | 480 } |
| 489 | 481 |
| 490 bool SearchProvider::ShouldAppendExtraParams( | 482 bool SearchProvider::ShouldAppendExtraParams( |
| 491 const SuggestResult& result) const { | 483 const SuggestResult& result) const { |
| 492 return !result.from_keyword_provider() || | 484 return !result.from_keyword_provider() || |
| 493 providers_.default_provider().empty(); | 485 providers_.default_provider().empty(); |
| 494 } | 486 } |
| 495 | 487 |
| 488 void SearchProvider::StopSuggest() { | |
| 489 // Increment the appropriate field in the histogram by the number of | |
| 490 // pending requests that were invalidated. | |
| 491 for (int i = 0; i < suggest_results_pending_; i++) | |
|
H Fung
2014/02/14 00:43:07
++i?
Maria
2014/02/14 02:37:30
Done.
| |
| 492 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); | |
| 493 suggest_results_pending_ = 0; | |
| 494 timer_.Stop(); | |
| 495 // Stop any in-progress URL fetches. | |
| 496 keyword_fetcher_.reset(); | |
| 497 default_fetcher_.reset(); | |
| 498 } | |
| 499 | |
| 500 void SearchProvider::ClearAllResults() { | |
| 501 keyword_results_.Clear(); | |
| 502 default_results_.Clear(); | |
| 503 } | |
| 504 | |
| 496 void SearchProvider::OnDeletionComplete(bool success, | 505 void SearchProvider::OnDeletionComplete(bool success, |
| 497 SuggestionDeletionHandler* handler) { | 506 SuggestionDeletionHandler* handler) { |
| 498 RecordDeletionResult(success); | 507 RecordDeletionResult(success); |
| 499 SuggestionDeletionHandlers::iterator it = std::find( | 508 SuggestionDeletionHandlers::iterator it = std::find( |
| 500 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 509 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 501 DCHECK(it != deletion_handlers_.end()); | 510 DCHECK(it != deletion_handlers_.end()); |
| 502 deletion_handlers_.erase(it); | 511 deletion_handlers_.erase(it); |
| 503 } | 512 } |
| 504 | 513 |
| 505 | 514 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 // Don't send anything for https except the hostname. Hostnames are OK | 713 // Don't send anything for https except the hostname. Hostnames are OK |
| 705 // because they are visible when the TCP connection is established, but the | 714 // because they are visible when the TCP connection is established, but the |
| 706 // specific path may reveal private information. | 715 // specific path may reveal private information. |
| 707 if (LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && | 716 if (LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && |
| 708 parts.path.is_nonempty()) | 717 parts.path.is_nonempty()) |
| 709 return false; | 718 return false; |
| 710 | 719 |
| 711 return true; | 720 return true; |
| 712 } | 721 } |
| 713 | 722 |
| 714 void SearchProvider::StopSuggest() { | |
| 715 // Increment the appropriate field in the histogram by the number of | |
| 716 // pending requests that were invalidated. | |
| 717 for (int i = 0; i < suggest_results_pending_; i++) | |
| 718 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); | |
| 719 suggest_results_pending_ = 0; | |
| 720 timer_.Stop(); | |
| 721 // Stop any in-progress URL fetches. | |
| 722 keyword_fetcher_.reset(); | |
| 723 default_fetcher_.reset(); | |
| 724 } | |
| 725 | |
| 726 void SearchProvider::ClearAllResults() { | |
| 727 keyword_results_.Clear(); | |
| 728 default_results_.Clear(); | |
| 729 } | |
| 730 | |
| 731 void SearchProvider::RemoveAllStaleResults() { | 723 void SearchProvider::RemoveAllStaleResults() { |
| 732 // We only need to remove stale results (which ensures the top-scoring | 724 // We only need to remove stale results (which ensures the top-scoring |
| 733 // match is inlineable) if the user is not in reorder mode. In reorder | 725 // match is inlineable) if the user is not in reorder mode. In reorder |
| 734 // mode, the autocomplete system will reorder results to make sure the | 726 // mode, the autocomplete system will reorder results to make sure the |
| 735 // top result is inlineable. | 727 // top result is inlineable. |
| 736 const bool omnibox_will_reorder_for_legal_default_match = | 728 const bool omnibox_will_reorder_for_legal_default_match = |
| 737 OmniboxFieldTrial::ReorderForLegalDefaultMatch( | 729 OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 738 input_.current_page_classification()); | 730 input_.current_page_classification()); |
| 739 // In theory it would be better to run an algorithm like that in | 731 // In theory it would be better to run an algorithm like that in |
| 740 // RemoveStaleResults(...) below that uses all four results lists | 732 // RemoveStaleResults(...) below that uses all four results lists |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1616 it->set_relevance(max_query_relevance); | 1608 it->set_relevance(max_query_relevance); |
| 1617 it->set_relevance_from_server(relevance_from_server); | 1609 it->set_relevance_from_server(relevance_from_server); |
| 1618 } | 1610 } |
| 1619 } | 1611 } |
| 1620 | 1612 |
| 1621 void SearchProvider::UpdateDone() { | 1613 void SearchProvider::UpdateDone() { |
| 1622 // We're done when the timer isn't running, there are no suggest queries | 1614 // We're done when the timer isn't running, there are no suggest queries |
| 1623 // pending, and we're not waiting on Instant. | 1615 // pending, and we're not waiting on Instant. |
| 1624 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1616 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1625 } | 1617 } |
| OLD | NEW |