OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 // We can't keep running any previous query, so halt it. | 497 // We can't keep running any previous query, so halt it. |
498 StopSuggest(); | 498 StopSuggest(); |
499 | 499 |
500 // Remove existing results that cannot inline autocomplete the new input. | 500 // Remove existing results that cannot inline autocomplete the new input. |
501 RemoveStaleResults(); | 501 RemoveStaleResults(); |
502 | 502 |
503 // We can't start a new query if we're only allowed synchronous results. | 503 // We can't start a new query if we're only allowed synchronous results. |
504 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) | 504 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) |
505 return; | 505 return; |
506 | 506 |
507 // We'll have at least one pending fetch. Set it to 1 now, but the value is | |
508 // correctly set in Run. As Run isn't invoked immediately we need to set this | |
509 // now, else we won't think we're waiting on results from the server when we | |
510 // really are. | |
511 suggest_results_pending_ = 1; | |
512 | |
513 // Kick off a timer that will start the URL fetch if it completes before | 507 // Kick off a timer that will start the URL fetch if it completes before |
514 // the user types another character. Requests may be delayed to avoid | 508 // the user types another character. Requests may be delayed to avoid |
515 // flooding the server with requests that are likely to be thrown away later | 509 // flooding the server with requests that are likely to be thrown away later |
516 // anyway. | 510 // anyway. |
517 timer_.Start(FROM_HERE, GetSuggestQueryDelay(), this, &SearchProvider::Run); | 511 timer_.Start(FROM_HERE, GetSuggestQueryDelay(), this, &SearchProvider::Run); |
518 } | 512 } |
519 | 513 |
520 bool SearchProvider::IsQuerySuitableForSuggest() const { | 514 bool SearchProvider::IsQuerySuitableForSuggest() const { |
521 // Don't run Suggest in incognito mode, if the engine doesn't support it, or | 515 // Don't run Suggest in incognito mode, if the engine doesn't support it, or |
522 // if the user has disabled it. | 516 // if the user has disabled it. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 parts.path.is_nonempty()) | 563 parts.path.is_nonempty()) |
570 return false; | 564 return false; |
571 | 565 |
572 return true; | 566 return true; |
573 } | 567 } |
574 | 568 |
575 void SearchProvider::StopSuggest() { | 569 void SearchProvider::StopSuggest() { |
576 // Increment the appropriate field in the histogram by the number of | 570 // Increment the appropriate field in the histogram by the number of |
577 // pending requests that were invalidated. | 571 // pending requests that were invalidated. |
578 for (int i = 0; i < suggest_results_pending_; i++) | 572 for (int i = 0; i < suggest_results_pending_; i++) |
579 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); | 573 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); |
msw
2012/08/21 19:16:19
FYI, we may see a reduction in REQUEST_INVALIDATED
| |
580 suggest_results_pending_ = 0; | 574 suggest_results_pending_ = 0; |
581 timer_.Stop(); | 575 timer_.Stop(); |
582 // Stop any in-progress URL fetches. | 576 // Stop any in-progress URL fetches. |
583 keyword_fetcher_.reset(); | 577 keyword_fetcher_.reset(); |
584 default_fetcher_.reset(); | 578 default_fetcher_.reset(); |
585 } | 579 } |
586 | 580 |
587 void SearchProvider::ClearResults() { | 581 void SearchProvider::ClearResults() { |
588 keyword_suggest_results_.clear(); | 582 keyword_suggest_results_.clear(); |
589 default_suggest_results_.clear(); | 583 default_suggest_results_.clear(); |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 match.contents.length(), ACMatchClassification::URL, | 1229 match.contents.length(), ACMatchClassification::URL, |
1236 &match.contents_class); | 1230 &match.contents_class); |
1237 | 1231 |
1238 match.description = navigation.description(); | 1232 match.description = navigation.description(); |
1239 AutocompleteMatch::ClassifyMatchInString(input, match.description, | 1233 AutocompleteMatch::ClassifyMatchInString(input, match.description, |
1240 ACMatchClassification::NONE, &match.description_class); | 1234 ACMatchClassification::NONE, &match.description_class); |
1241 return match; | 1235 return match; |
1242 } | 1236 } |
1243 | 1237 |
1244 void SearchProvider::UpdateDone() { | 1238 void SearchProvider::UpdateDone() { |
1245 // We're done when there are no more suggest queries pending (this is set to 1 | 1239 // We're done when the timer isn't running, there are no suggest queries |
1246 // when the timer is started) and we're not waiting on instant. | 1240 // pending, and we're not waiting on instant. |
1247 done_ = ((suggest_results_pending_ == 0) && | 1241 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && |
1248 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 1242 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
1249 } | 1243 } |
OLD | NEW |