| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 latest_result_.Validate(); | 758 latest_result_.Validate(); |
| 759 #endif | 759 #endif |
| 760 | 760 |
| 761 if (is_synchronous_pass) { | 761 if (is_synchronous_pass) { |
| 762 if (!max_delay_timer_.IsRunning()) { | 762 if (!max_delay_timer_.IsRunning()) { |
| 763 max_delay_timer_.Start( | 763 max_delay_timer_.Start( |
| 764 TimeDelta::FromMilliseconds(kResultUpdateMaxDelayMs), | 764 TimeDelta::FromMilliseconds(kResultUpdateMaxDelayMs), |
| 765 this, &AutocompleteController::CommitResult); | 765 this, &AutocompleteController::CommitResult); |
| 766 } | 766 } |
| 767 | 767 |
| 768 result_.CopyFrom(latest_result_); | |
| 769 NotificationService::current()->Notify( | 768 NotificationService::current()->Notify( |
| 770 NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE, | 769 NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE, |
| 771 Source<AutocompleteController>(this), NotificationService::NoDetails()); | 770 Source<AutocompleteController>(this), |
| 771 Details<const AutocompleteResult>(&latest_result_)); |
| 772 } | 772 } |
| 773 | 773 |
| 774 if (done_) { | 774 if (done_) { |
| 775 CommitResult(); | 775 CommitResult(); |
| 776 } else if (!update_pending_) { | 776 } else if (!update_pending_) { |
| 777 // Coalesce the results for the next kPopupCoalesceMs milliseconds. | 777 // Coalesce the results for the next kPopupCoalesceMs milliseconds. |
| 778 update_pending_ = true; | 778 update_pending_ = true; |
| 779 coalesce_timer_.Stop(); | 779 coalesce_timer_.Stop(); |
| 780 coalesce_timer_.Start(TimeDelta::FromMilliseconds(kResultCoalesceMs), this, | 780 coalesce_timer_.Start(TimeDelta::FromMilliseconds(kResultCoalesceMs), this, |
| 781 &AutocompleteController::CommitResult); | 781 &AutocompleteController::CommitResult); |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 | 784 |
| 785 void AutocompleteController::CommitResult() { | 785 void AutocompleteController::CommitResult() { |
| 786 // The max update interval timer either needs to be reset (if more updates | 786 // The max update interval timer either needs to be reset (if more updates |
| 787 // are to come) or stopped (when we're done with the query). The coalesce | 787 // are to come) or stopped (when we're done with the query). The coalesce |
| 788 // timer should always just be stopped. | 788 // timer should always just be stopped. |
| 789 update_pending_ = false; | 789 update_pending_ = false; |
| 790 coalesce_timer_.Stop(); | 790 coalesce_timer_.Stop(); |
| 791 if (done_) | 791 if (done_) |
| 792 max_delay_timer_.Stop(); | 792 max_delay_timer_.Stop(); |
| 793 else | 793 else |
| 794 max_delay_timer_.Reset(); | 794 max_delay_timer_.Reset(); |
| 795 | 795 |
| 796 result_.CopyFrom(latest_result_); | 796 result_.CopyFrom(latest_result_); |
| 797 NotificationService::current()->Notify( | 797 NotificationService::current()->Notify( |
| 798 NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, | 798 NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, |
| 799 Source<AutocompleteController>(this), NotificationService::NoDetails()); | 799 Source<AutocompleteController>(this), |
| 800 Details<const AutocompleteResult>(&result_)); |
| 800 } | 801 } |
| 801 | 802 |
| 802 ACMatches AutocompleteController::GetMatchesNotInLatestResult( | 803 ACMatches AutocompleteController::GetMatchesNotInLatestResult( |
| 803 const AutocompleteProvider* provider) const { | 804 const AutocompleteProvider* provider) const { |
| 804 DCHECK(provider); | 805 DCHECK(provider); |
| 805 | 806 |
| 806 // Determine the set of destination URLs. | 807 // Determine the set of destination URLs. |
| 807 std::set<GURL> destination_urls; | 808 std::set<GURL> destination_urls; |
| 808 for (AutocompleteResult::const_iterator i(latest_result_.begin()); | 809 for (AutocompleteResult::const_iterator i(latest_result_.begin()); |
| 809 i != latest_result_.end(); ++i) | 810 i != latest_result_.end(); ++i) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 match.contents_class.push_back( | 890 match.contents_class.push_back( |
| 890 ACMatchClassification(keyword_offset + input_.text().size(), | 891 ACMatchClassification(keyword_offset + input_.text().size(), |
| 891 ACMatchClassification::NONE)); | 892 ACMatchClassification::NONE)); |
| 892 } | 893 } |
| 893 match.destination_url = | 894 match.destination_url = |
| 894 HistoryUI::GetHistoryURLWithSearchText(input_.text()); | 895 HistoryUI::GetHistoryURLWithSearchText(input_.text()); |
| 895 match.transition = PageTransition::AUTO_BOOKMARK; | 896 match.transition = PageTransition::AUTO_BOOKMARK; |
| 896 match.provider = history_contents_provider_; | 897 match.provider = history_contents_provider_; |
| 897 latest_result_.AddMatch(match); | 898 latest_result_.AddMatch(match); |
| 898 } | 899 } |
| OLD | NEW |