OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 504 |
505 // static | 505 // static |
506 size_t AutocompleteProvider::max_matches_ = 3; | 506 size_t AutocompleteProvider::max_matches_ = 3; |
507 | 507 |
508 AutocompleteProvider::~AutocompleteProvider() { | 508 AutocompleteProvider::~AutocompleteProvider() { |
509 Stop(); | 509 Stop(); |
510 } | 510 } |
511 | 511 |
512 void AutocompleteProvider::SetProfile(Profile* profile) { | 512 void AutocompleteProvider::SetProfile(Profile* profile) { |
513 DCHECK(profile); | 513 DCHECK(profile); |
514 Stop(); // It makes no sense to continue running a query from an old profile. | 514 DCHECK(done_); // The controller should have already stopped us. |
515 profile_ = profile; | 515 profile_ = profile; |
516 } | 516 } |
517 | 517 |
518 // static | 518 // static |
519 size_t AutocompleteProvider::TrimHttpPrefix(std::wstring* url) { | 519 size_t AutocompleteProvider::TrimHttpPrefix(std::wstring* url) { |
520 url_parse::Component scheme; | 520 url_parse::Component scheme; |
521 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, | 521 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, |
522 &scheme)) | 522 &scheme)) |
523 return 0; // Not "http". | 523 return 0; // Not "http". |
524 | 524 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 } | 681 } |
682 | 682 |
683 AutocompleteController::~AutocompleteController() { | 683 AutocompleteController::~AutocompleteController() { |
684 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 684 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
685 (*i)->Release(); | 685 (*i)->Release(); |
686 | 686 |
687 providers_.clear(); // Not really necessary. | 687 providers_.clear(); // Not really necessary. |
688 } | 688 } |
689 | 689 |
690 void AutocompleteController::SetProfile(Profile* profile) { | 690 void AutocompleteController::SetProfile(Profile* profile) { |
| 691 Stop(true); |
691 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 692 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
692 (*i)->SetProfile(profile); | 693 (*i)->SetProfile(profile); |
693 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a | 694 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a |
694 // different profile. | 695 // different profile. |
695 } | 696 } |
696 | 697 |
697 void AutocompleteController::Start(const std::wstring& text, | 698 void AutocompleteController::Start(const std::wstring& text, |
698 const std::wstring& desired_tld, | 699 const std::wstring& desired_tld, |
699 bool prevent_inline_autocomplete, | 700 bool prevent_inline_autocomplete, |
700 bool prefer_keyword, | 701 bool prefer_keyword, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 750 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
750 ++i) { | 751 ++i) { |
751 if (!(*i)->done()) | 752 if (!(*i)->done()) |
752 (*i)->Stop(); | 753 (*i)->Stop(); |
753 } | 754 } |
754 | 755 |
755 update_delay_timer_.Stop(); | 756 update_delay_timer_.Stop(); |
756 updated_latest_result_ = false; | 757 updated_latest_result_ = false; |
757 delay_interval_has_passed_ = false; | 758 delay_interval_has_passed_ = false; |
758 done_ = true; | 759 done_ = true; |
759 if (clear_result) { | 760 if (clear_result && !result_.empty()) { |
760 result_.Reset(); | 761 result_.Reset(); |
761 NotificationService::current()->Notify( | 762 NotificationService::current()->Notify( |
762 NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, | 763 NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, |
763 Source<AutocompleteController>(this), | 764 Source<AutocompleteController>(this), |
764 Details<const AutocompleteResult>(&result_)); | 765 Details<const AutocompleteResult>(&result_)); |
765 // NOTE: We don't notify AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED since | 766 // NOTE: We don't notify AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED since |
766 // we're trying to only clear the popup, not touch the edit... this is all | 767 // we're trying to only clear the popup, not touch the edit... this is all |
767 // a mess and should be cleaned up :( | 768 // a mess and should be cleaned up :( |
768 } | 769 } |
769 latest_result_.CopyFrom(result_); | 770 latest_result_.CopyFrom(result_); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 void AutocompleteController::CheckIfDone() { | 963 void AutocompleteController::CheckIfDone() { |
963 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 964 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
964 ++i) { | 965 ++i) { |
965 if (!(*i)->done()) { | 966 if (!(*i)->done()) { |
966 done_ = false; | 967 done_ = false; |
967 return; | 968 return; |
968 } | 969 } |
969 } | 970 } |
970 done_ = true; | 971 done_ = true; |
971 } | 972 } |
OLD | NEW |