| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // Returns the name of this provider. | 531 // Returns the name of this provider. |
| 532 const char* name() const { return name_; } | 532 const char* name() const { return name_; } |
| 533 | 533 |
| 534 // Called to delete a match and the backing data that produced it. This | 534 // Called to delete a match and the backing data that produced it. This |
| 535 // match should not appear again in this or future queries. This can only be | 535 // match should not appear again in this or future queries. This can only be |
| 536 // called for matches the provider marks as deletable. This should only be | 536 // called for matches the provider marks as deletable. This should only be |
| 537 // called when no query is running. | 537 // called when no query is running. |
| 538 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. | 538 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. |
| 539 virtual void DeleteMatch(const AutocompleteMatch& match) {} | 539 virtual void DeleteMatch(const AutocompleteMatch& match) {} |
| 540 | 540 |
| 541 static void set_max_matches(size_t max_matches) { | 541 // A suggested upper bound for how many matches a provider should return. |
| 542 max_matches_ = max_matches; | 542 // TODO(pkasting): http://b/1111299 , http://b/933133 This should go away once |
| 543 } | 543 // we have good relevance heuristics; the controller should handle all |
| 544 | 544 // culling. |
| 545 static size_t max_matches() { return max_matches_; } | 545 static const size_t kMaxMatches; |
| 546 | 546 |
| 547 protected: | 547 protected: |
| 548 friend class base::RefCountedThreadSafe<AutocompleteProvider>; | 548 friend class base::RefCountedThreadSafe<AutocompleteProvider>; |
| 549 | 549 |
| 550 virtual ~AutocompleteProvider(); | 550 virtual ~AutocompleteProvider(); |
| 551 | 551 |
| 552 // Trims "http:" and up to two subsequent slashes from |url|. Returns the | 552 // Trims "http:" and up to two subsequent slashes from |url|. Returns the |
| 553 // number of characters that were trimmed. | 553 // number of characters that were trimmed. |
| 554 static size_t TrimHttpPrefix(std::wstring* url); | 554 static size_t TrimHttpPrefix(std::wstring* url); |
| 555 | 555 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 569 Profile* profile_; | 569 Profile* profile_; |
| 570 | 570 |
| 571 ACProviderListener* listener_; | 571 ACProviderListener* listener_; |
| 572 ACMatches matches_; | 572 ACMatches matches_; |
| 573 bool done_; | 573 bool done_; |
| 574 | 574 |
| 575 // The name of this provider. Used for logging. | 575 // The name of this provider. Used for logging. |
| 576 const char* name_; | 576 const char* name_; |
| 577 | 577 |
| 578 private: | 578 private: |
| 579 // A suggested upper bound for how many matches a provider should return. | 579 DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider); |
| 580 // TODO(pkasting): http://b/1111299 , http://b/933133 This should go away once | |
| 581 // we have good relevance heuristics; the controller should handle all | |
| 582 // culling. | |
| 583 static size_t max_matches_; | |
| 584 | |
| 585 DISALLOW_EVIL_CONSTRUCTORS(AutocompleteProvider); | |
| 586 }; | 580 }; |
| 587 | 581 |
| 588 typedef AutocompleteProvider::ACProviderListener ACProviderListener; | 582 typedef AutocompleteProvider::ACProviderListener ACProviderListener; |
| 589 | 583 |
| 590 // AutocompleteResult --------------------------------------------------------- | 584 // AutocompleteResult --------------------------------------------------------- |
| 591 | 585 |
| 592 // All matches from all providers for a particular query. This also tracks | 586 // All matches from all providers for a particular query. This also tracks |
| 593 // what the default match should be if the user doesn't manually select another | 587 // what the default match should be if the user doesn't manually select another |
| 594 // match. | 588 // match. |
| 595 class AutocompleteResult { | 589 class AutocompleteResult { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 621 // |destination_url|, we'll use the best match from this provider. | 615 // |destination_url|, we'll use the best match from this provider. |
| 622 const AutocompleteProvider* provider_affinity; | 616 const AutocompleteProvider* provider_affinity; |
| 623 | 617 |
| 624 // True when this is the HistoryURLProvider's "what you typed" match. This | 618 // True when this is the HistoryURLProvider's "what you typed" match. This |
| 625 // can't be tracked using |destination_url| because its URL changes on every | 619 // can't be tracked using |destination_url| because its URL changes on every |
| 626 // keystroke, so if this is set, we'll preserve the selection by simply | 620 // keystroke, so if this is set, we'll preserve the selection by simply |
| 627 // choosing the new "what you typed" entry and ignoring |destination_url|. | 621 // choosing the new "what you typed" entry and ignoring |destination_url|. |
| 628 bool is_history_what_you_typed_match; | 622 bool is_history_what_you_typed_match; |
| 629 }; | 623 }; |
| 630 | 624 |
| 631 static void set_max_matches(size_t max_matches) { | |
| 632 max_matches_ = max_matches; | |
| 633 } | |
| 634 static size_t max_matches() { return max_matches_; } | |
| 635 | |
| 636 AutocompleteResult(); | 625 AutocompleteResult(); |
| 637 | 626 |
| 638 // operator=() by another name. | 627 // operator=() by another name. |
| 639 void CopyFrom(const AutocompleteResult& rhs); | 628 void CopyFrom(const AutocompleteResult& rhs); |
| 640 | 629 |
| 641 // Adds a single match. The match is inserted at the appropriate position | 630 // Adds a single match. The match is inserted at the appropriate position |
| 642 // based on relevancy and display order. This is ONLY for use after | 631 // based on relevancy and display order. This is ONLY for use after |
| 643 // SortAndCull() has been invoked, and preserves default_match_. | 632 // SortAndCull() has been invoked, and preserves default_match_. |
| 644 void AddMatch(const AutocompleteMatch& match); | 633 void AddMatch(const AutocompleteMatch& match); |
| 645 | 634 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 675 void Reset() { | 664 void Reset() { |
| 676 matches_.clear(); | 665 matches_.clear(); |
| 677 default_match_ = end(); | 666 default_match_ = end(); |
| 678 } | 667 } |
| 679 | 668 |
| 680 #ifndef NDEBUG | 669 #ifndef NDEBUG |
| 681 // Does a data integrity check on this result. | 670 // Does a data integrity check on this result. |
| 682 void Validate() const; | 671 void Validate() const; |
| 683 #endif | 672 #endif |
| 684 | 673 |
| 685 private: | |
| 686 // Max number of matches we'll show from the various providers. We may end | 674 // Max number of matches we'll show from the various providers. We may end |
| 687 // up showing an additional shortcut for Destinations->History, see | 675 // up showing an additional shortcut for Destinations->History, see |
| 688 // AddHistoryContentsShortcut. | 676 // AddHistoryContentsShortcut. |
| 689 static size_t max_matches_; | 677 static const size_t kMaxMatches; |
| 690 | 678 |
| 679 private: |
| 691 ACMatches matches_; | 680 ACMatches matches_; |
| 692 | 681 |
| 693 const_iterator default_match_; | 682 const_iterator default_match_; |
| 694 | 683 |
| 695 // The "alternate navigation URL", if any, for this result set. This is a URL | 684 // The "alternate navigation URL", if any, for this result set. This is a URL |
| 696 // to try offering as a navigational option in case the user navigated to the | 685 // to try offering as a navigational option in case the user navigated to the |
| 697 // URL of the default match but intended something else. For example, if the | 686 // URL of the default match but intended something else. For example, if the |
| 698 // user's local intranet contains site "foo", and the user types "foo", we | 687 // user's local intranet contains site "foo", and the user types "foo", we |
| 699 // default to searching for "foo" when the user may have meant to navigate | 688 // default to searching for "foo" when the user may have meant to navigate |
| 700 // there. In cases like this, the default match will point to the "search for | 689 // there. In cases like this, the default match will point to the "search for |
| 701 // 'foo'" result, and this will contain "http://foo/". | 690 // 'foo'" result, and this will contain "http://foo/". |
| 702 GURL alternate_nav_url_; | 691 GURL alternate_nav_url_; |
| 703 | 692 |
| 704 DISALLOW_EVIL_CONSTRUCTORS(AutocompleteResult); | 693 DISALLOW_COPY_AND_ASSIGN(AutocompleteResult); |
| 705 }; | 694 }; |
| 706 | 695 |
| 707 // AutocompleteController ----------------------------------------------------- | 696 // AutocompleteController ----------------------------------------------------- |
| 708 | 697 |
| 709 // The coordinator for autocomplete queries, responsible for combining the | 698 // The coordinator for autocomplete queries, responsible for combining the |
| 710 // matches from a series of providers into one AutocompleteResult. | 699 // matches from a series of providers into one AutocompleteResult. |
| 711 class AutocompleteController : public ACProviderListener { | 700 class AutocompleteController : public ACProviderListener { |
| 712 public: | 701 public: |
| 713 // Used to indicate an index that is not selected in a call to Update(). | 702 // Used to indicate an index that is not selected in a call to Update(). |
| 714 static const int kNoItemSelected; | 703 static const int kNoItemSelected; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 // True if a query is not currently running. | 847 // True if a query is not currently running. |
| 859 bool done_; | 848 bool done_; |
| 860 | 849 |
| 861 // Timer that tracks how long it's been since the last time we sent our | 850 // Timer that tracks how long it's been since the last time we sent our |
| 862 // observers a new result set. This is used both to enforce a lower bound on | 851 // observers a new result set. This is used both to enforce a lower bound on |
| 863 // the delay between most commits (to reduce flicker), and ensure that updates | 852 // the delay between most commits (to reduce flicker), and ensure that updates |
| 864 // eventually get committed no matter what delays occur between them or how | 853 // eventually get committed no matter what delays occur between them or how |
| 865 // fast or continuously the user is typing. | 854 // fast or continuously the user is typing. |
| 866 base::RepeatingTimer<AutocompleteController> update_delay_timer_; | 855 base::RepeatingTimer<AutocompleteController> update_delay_timer_; |
| 867 | 856 |
| 868 DISALLOW_EVIL_CONSTRUCTORS(AutocompleteController); | 857 DISALLOW_COPY_AND_ASSIGN(AutocompleteController); |
| 869 }; | 858 }; |
| 870 | 859 |
| 871 // AutocompleteLog ------------------------------------------------------------ | 860 // AutocompleteLog ------------------------------------------------------------ |
| 872 | 861 |
| 873 // The data to log (via the metrics service) when the user selects an item | 862 // The data to log (via the metrics service) when the user selects an item |
| 874 // from the omnibox popup. | 863 // from the omnibox popup. |
| 875 struct AutocompleteLog { | 864 struct AutocompleteLog { |
| 876 AutocompleteLog(std::wstring text, | 865 AutocompleteLog(std::wstring text, |
| 877 AutocompleteInput::Type input_type, | 866 AutocompleteInput::Type input_type, |
| 878 size_t selected_index, | 867 size_t selected_index, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 890 AutocompleteInput::Type input_type; | 879 AutocompleteInput::Type input_type; |
| 891 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). | 880 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). |
| 892 size_t selected_index; | 881 size_t selected_index; |
| 893 // Inline autocompleted length (if displayed). | 882 // Inline autocompleted length (if displayed). |
| 894 size_t inline_autocompleted_length; | 883 size_t inline_autocompleted_length; |
| 895 // Result set. | 884 // Result set. |
| 896 const AutocompleteResult& result; | 885 const AutocompleteResult& result; |
| 897 }; | 886 }; |
| 898 | 887 |
| 899 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 888 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
| OLD | NEW |