| 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 // This file contains the zero-suggest autocomplete provider. This experimental | 5 // This file contains the zero-suggest autocomplete provider. This experimental |
| 6 // provider is invoked when the user focuses in the omnibox prior to editing, | 6 // provider is invoked when the user focuses in the omnibox prior to editing, |
| 7 // and generates search query suggestions based on the current URL. To enable | 7 // and generates search query suggestions based on the current URL. To enable |
| 8 // this provider, point --experimental-zero-suggest-url-prefix at an | 8 // this provider, point --experimental-zero-suggest-url-prefix at an |
| 9 // appropriate suggestion service. | 9 // appropriate suggestion service. |
| 10 // | 10 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const GURL& curent_page_url, | 65 const GURL& curent_page_url, |
| 66 AutocompleteInput::PageClassification page_classification, | 66 AutocompleteInput::PageClassification page_classification, |
| 67 const base::string16& permanent_text); | 67 const base::string16& permanent_text); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 70 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
| 71 Profile* profile); | 71 Profile* profile); |
| 72 | 72 |
| 73 virtual ~ZeroSuggestProvider(); | 73 virtual ~ZeroSuggestProvider(); |
| 74 | 74 |
| 75 // BaseSearchProvider: |
| 76 virtual const TemplateURL* GetTemplateURL( |
| 77 const SuggestResult& result) const OVERRIDE; |
| 78 virtual const AutocompleteInput GetInput( |
| 79 const SuggestResult& result) const OVERRIDE; |
| 80 virtual bool ShouldAppendExtraParams( |
| 81 const SuggestResult& result) const OVERRIDE; |
| 82 |
| 75 // The 4 functions below (that take classes defined in SearchProvider as | 83 // The 4 functions below (that take classes defined in SearchProvider as |
| 76 // arguments) were copied and trimmed from SearchProvider. | 84 // arguments) were copied and trimmed from SearchProvider. |
| 77 // TODO(hfung): Refactor them into a new base class common to both | 85 // TODO(hfung): Refactor them into a new base class common to both |
| 78 // ZeroSuggestProvider and SearchProvider. | 86 // ZeroSuggestProvider and SearchProvider. |
| 79 | 87 |
| 80 // From the OpenSearch formatted response |root_val|, populate query | 88 // From the OpenSearch formatted response |root_val|, populate query |
| 81 // suggestions into |suggest_results|, navigation suggestions into | 89 // suggestions into |suggest_results|, navigation suggestions into |
| 82 // |navigation_results|, and the verbatim relevance score into | 90 // |navigation_results|, and the verbatim relevance score into |
| 83 // |verbatim_relevance|. | 91 // |verbatim_relevance|. |
| 84 void FillResults(const base::Value& root_val, | 92 void FillResults(const base::Value& root_val, |
| 85 int* verbatim_relevance, | 93 int* verbatim_relevance, |
| 86 SuggestResults* suggest_results, | 94 SuggestResults* suggest_results, |
| 87 NavigationResults* navigation_results); | 95 NavigationResults* navigation_results); |
| 88 | 96 |
| 89 // Creates AutocompleteMatches to search |template_url| for "<suggestion>" for | 97 // Adds AutocompleteMatches for each of the suggestions in |results| to |
| 90 // all suggestions in |results|, and adds them to |map|. | 98 // |map|. |
| 91 void AddSuggestResultsToMap(const SuggestResults& results, | 99 void AddSuggestResultsToMap(const SuggestResults& results, |
| 92 const TemplateURL* template_url, | |
| 93 MatchMap* map); | 100 MatchMap* map); |
| 94 | 101 |
| 95 // Creates an AutocompleteMatch with the provided |relevance| and |type| to | |
| 96 // search |template_url| for |query_string|. |accepted_suggestion| will be | |
| 97 // used to generate Assisted Query Stats. | |
| 98 // | |
| 99 // Adds this match to |map|; if such a match already exists, whichever one | |
| 100 // has lower relevance is eliminated. | |
| 101 void AddMatchToMap(int relevance, | |
| 102 AutocompleteMatch::Type type, | |
| 103 const TemplateURL* template_url, | |
| 104 const base::string16& query_string, | |
| 105 int accepted_suggestion, | |
| 106 MatchMap* map); | |
| 107 | |
| 108 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. | 102 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. |
| 109 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); | 103 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); |
| 110 | 104 |
| 111 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. | 105 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. |
| 112 void Run(const GURL& suggest_url); | 106 void Run(const GURL& suggest_url); |
| 113 | 107 |
| 114 // Parses results from the zero-suggest server and updates results. | 108 // Parses results from the zero-suggest server and updates results. |
| 115 void ParseSuggestResults(const base::Value& root_val); | 109 void ParseSuggestResults(const base::Value& root_val); |
| 116 | 110 |
| 117 // Converts the parsed results to a set of AutocompleteMatches and adds them | 111 // Converts the parsed results to a set of AutocompleteMatches and adds them |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 152 |
| 159 history::MostVisitedURLList most_visited_urls_; | 153 history::MostVisitedURLList most_visited_urls_; |
| 160 | 154 |
| 161 // For callbacks that may be run after destruction. | 155 // For callbacks that may be run after destruction. |
| 162 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 156 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
| 163 | 157 |
| 164 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 158 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
| 165 }; | 159 }; |
| 166 | 160 |
| 167 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 161 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| OLD | NEW |