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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/gtest_prod_util.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/timer.h" | 17 #include "base/timer.h" |
17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "googleurl/src/url_parse.h" | 20 #include "googleurl/src/url_parse.h" |
20 | 21 |
21 // The AutocompleteController is the center of the autocomplete system. A | 22 // The AutocompleteController is the center of the autocomplete system. A |
22 // class creates an instance of the controller, which in turn creates a set of | 23 // class creates an instance of the controller, which in turn creates a set of |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 void DeleteMatch(const AutocompleteMatch& match); | 670 void DeleteMatch(const AutocompleteMatch& match); |
670 | 671 |
671 // Removes any entries that were copied from the last result. This is used by | 672 // Removes any entries that were copied from the last result. This is used by |
672 // the popup to ensure it's not showing an out-of-date query. | 673 // the popup to ensure it's not showing an out-of-date query. |
673 void ExpireCopiedEntries(); | 674 void ExpireCopiedEntries(); |
674 | 675 |
675 #ifdef UNIT_TEST | 676 #ifdef UNIT_TEST |
676 void set_search_provider(SearchProvider* provider) { | 677 void set_search_provider(SearchProvider* provider) { |
677 search_provider_ = provider; | 678 search_provider_ = provider; |
678 } | 679 } |
| 680 void set_keyword_provider(KeywordProvider* provider) { |
| 681 keyword_provider_ = provider; |
| 682 } |
679 #endif | 683 #endif |
680 SearchProvider* search_provider() const { return search_provider_; } | 684 SearchProvider* search_provider() const { return search_provider_; } |
| 685 KeywordProvider* keyword_provider() const { return keyword_provider_; } |
681 | 686 |
682 // Getters | 687 // Getters |
683 const AutocompleteInput& input() const { return input_; } | 688 const AutocompleteInput& input() const { return input_; } |
684 const AutocompleteResult& result() const { return result_; } | 689 const AutocompleteResult& result() const { return result_; } |
685 bool done() const { return done_; } | 690 bool done() const { return done_; } |
686 | 691 |
687 // From AutocompleteProvider::Listener | 692 // From AutocompleteProvider::Listener |
688 virtual void OnProviderUpdate(bool updated_matches); | 693 virtual void OnProviderUpdate(bool updated_matches); |
689 | 694 |
690 private: | 695 private: |
| 696 friend class AutocompleteProviderTest; |
| 697 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, |
| 698 RedundantKeywordsIgnoredInResult); |
| 699 |
691 // Updates |result_| to reflect the current provider state. Resets timers and | 700 // Updates |result_| to reflect the current provider state. Resets timers and |
692 // fires notifications as necessary. |is_synchronous_pass| is true only when | 701 // fires notifications as necessary. |is_synchronous_pass| is true only when |
693 // Start() is calling this to get the synchronous result. | 702 // Start() is calling this to get the synchronous result. |
694 void UpdateResult(bool is_synchronous_pass); | 703 void UpdateResult(bool is_synchronous_pass); |
695 | 704 |
| 705 // Updates |result| to populate each match's |associated_keyword| if that |
| 706 // match can show a keyword hint. |result| should be sorted by |
| 707 // relevance before this is called. |
| 708 void UpdateAssociatedKeywords(AutocompleteResult* result); |
| 709 |
696 // For each group of contiguous matches from the same TemplateURL, show the | 710 // For each group of contiguous matches from the same TemplateURL, show the |
697 // provider name as a description on the first match in the group. | 711 // provider name as a description on the first match in the group. |
698 void UpdateKeywordDescriptions(AutocompleteResult* result); | 712 void UpdateKeywordDescriptions(AutocompleteResult* result); |
699 | 713 |
700 // Calls AutocompleteControllerDelegate::OnResultChanged() and if done sends | 714 // Calls AutocompleteControllerDelegate::OnResultChanged() and if done sends |
701 // AUTOCOMPLETE_CONTROLLER_RESULT_READY. | 715 // AUTOCOMPLETE_CONTROLLER_RESULT_READY. |
702 void NotifyChanged(bool notify_default_match); | 716 void NotifyChanged(bool notify_default_match); |
703 | 717 |
704 // Updates |done_| to be accurate with respect to current providers' statuses. | 718 // Updates |done_| to be accurate with respect to current providers' statuses. |
705 void CheckIfDone(); | 719 void CheckIfDone(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 // ID of the tab the selected autocomplete suggestion was opened in. | 779 // ID of the tab the selected autocomplete suggestion was opened in. |
766 // Set to -1 if we haven't yet determined the destination tab. | 780 // Set to -1 if we haven't yet determined the destination tab. |
767 SessionID::id_type tab_id; | 781 SessionID::id_type tab_id; |
768 // Inline autocompleted length (if displayed). | 782 // Inline autocompleted length (if displayed). |
769 size_t inline_autocompleted_length; | 783 size_t inline_autocompleted_length; |
770 // Result set. | 784 // Result set. |
771 const AutocompleteResult& result; | 785 const AutocompleteResult& result; |
772 }; | 786 }; |
773 | 787 |
774 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 788 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
OLD | NEW |