OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 void DeleteMatch(const AutocompleteMatch& match); | 662 void DeleteMatch(const AutocompleteMatch& match); |
662 | 663 |
663 // Removes any entries that were copied from the last result. This is used by | 664 // Removes any entries that were copied from the last result. This is used by |
664 // the popup to ensure it's not showing an out-of-date query. | 665 // the popup to ensure it's not showing an out-of-date query. |
665 void ExpireCopiedEntries(); | 666 void ExpireCopiedEntries(); |
666 | 667 |
667 #ifdef UNIT_TEST | 668 #ifdef UNIT_TEST |
668 void set_search_provider(SearchProvider* provider) { | 669 void set_search_provider(SearchProvider* provider) { |
669 search_provider_ = provider; | 670 search_provider_ = provider; |
670 } | 671 } |
| 672 void set_keyword_provider(KeywordProvider* provider) { |
| 673 keyword_provider_ = provider; |
| 674 } |
671 #endif | 675 #endif |
672 SearchProvider* search_provider() const { return search_provider_; } | 676 SearchProvider* search_provider() const { return search_provider_; } |
| 677 KeywordProvider* keyword_provider() const { return keyword_provider_; } |
673 | 678 |
674 // Getters | 679 // Getters |
675 const AutocompleteInput& input() const { return input_; } | 680 const AutocompleteInput& input() const { return input_; } |
676 const AutocompleteResult& result() const { return result_; } | 681 const AutocompleteResult& result() const { return result_; } |
677 bool done() const { return done_; } | 682 bool done() const { return done_; } |
678 | 683 |
679 // From AutocompleteProvider::Listener | 684 // From AutocompleteProvider::Listener |
680 virtual void OnProviderUpdate(bool updated_matches); | 685 virtual void OnProviderUpdate(bool updated_matches); |
681 | 686 |
682 private: | 687 private: |
| 688 friend class AutocompleteProviderTest; |
| 689 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, |
| 690 RedundantKeywordsIgnoredInResult); |
| 691 |
683 // Updates |result_| to reflect the current provider state. Resets timers and | 692 // Updates |result_| to reflect the current provider state. Resets timers and |
684 // fires notifications as necessary. |is_synchronous_pass| is true only when | 693 // fires notifications as necessary. |is_synchronous_pass| is true only when |
685 // Start() is calling this to get the synchronous result. | 694 // Start() is calling this to get the synchronous result. |
686 void UpdateResult(bool is_synchronous_pass); | 695 void UpdateResult(bool is_synchronous_pass); |
687 | 696 |
| 697 // Updates |result| to populate each match's |associated_keyword| if that |
| 698 // match can show a keyword hint. |result| should be sorted by |
| 699 // relevance before this is called. |
| 700 void UpdateAssociatedKeywords(AutocompleteResult* result); |
| 701 |
688 // For each group of contiguous matches from the same TemplateURL, show the | 702 // For each group of contiguous matches from the same TemplateURL, show the |
689 // provider name as a description on the first match in the group. | 703 // provider name as a description on the first match in the group. |
690 void UpdateKeywordDescriptions(AutocompleteResult* result); | 704 void UpdateKeywordDescriptions(AutocompleteResult* result); |
691 | 705 |
692 // Calls AutocompleteControllerDelegate::OnResultChanged() and if done sends | 706 // Calls AutocompleteControllerDelegate::OnResultChanged() and if done sends |
693 // AUTOCOMPLETE_CONTROLLER_RESULT_READY. | 707 // AUTOCOMPLETE_CONTROLLER_RESULT_READY. |
694 void NotifyChanged(bool notify_default_match); | 708 void NotifyChanged(bool notify_default_match); |
695 | 709 |
696 // Updates |done_| to be accurate with respect to current providers' statuses. | 710 // Updates |done_| to be accurate with respect to current providers' statuses. |
697 void CheckIfDone(); | 711 void CheckIfDone(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 // ID of the tab the selected autocomplete suggestion was opened in. | 771 // ID of the tab the selected autocomplete suggestion was opened in. |
758 // Set to -1 if we haven't yet determined the destination tab. | 772 // Set to -1 if we haven't yet determined the destination tab. |
759 SessionID::id_type tab_id; | 773 SessionID::id_type tab_id; |
760 // Inline autocompleted length (if displayed). | 774 // Inline autocompleted length (if displayed). |
761 size_t inline_autocompleted_length; | 775 size_t inline_autocompleted_length; |
762 // Result set. | 776 // Result set. |
763 const AutocompleteResult& result; | 777 const AutocompleteResult& result; |
764 }; | 778 }; |
765 | 779 |
766 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 780 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
OLD | NEW |