Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/autocomplete/zero_suggest_provider.h

Issue 158053002: Part 4 of search provider refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 bool ShouldAppendExtraParams(
77 const SuggestResult& result) const OVERRIDE;
78
75 // The 4 functions below (that take classes defined in SearchProvider as 79 // The 4 functions below (that take classes defined in SearchProvider as
76 // arguments) were copied and trimmed from SearchProvider. 80 // arguments) were copied and trimmed from SearchProvider.
77 // TODO(hfung): Refactor them into a new base class common to both 81 // TODO(hfung): Refactor them into a new base class common to both
78 // ZeroSuggestProvider and SearchProvider. 82 // ZeroSuggestProvider and SearchProvider.
79 83
80 // From the OpenSearch formatted response |root_val|, populate query 84 // From the OpenSearch formatted response |root_val|, populate query
81 // suggestions into |suggest_results|, navigation suggestions into 85 // suggestions into |suggest_results|, navigation suggestions into
82 // |navigation_results|, and the verbatim relevance score into 86 // |navigation_results|, and the verbatim relevance score into
83 // |verbatim_relevance|. 87 // |verbatim_relevance|.
84 void FillResults(const base::Value& root_val, 88 void FillResults(const base::Value& root_val,
85 int* verbatim_relevance, 89 int* verbatim_relevance,
86 SuggestResults* suggest_results, 90 SuggestResults* suggest_results,
87 NavigationResults* navigation_results); 91 NavigationResults* navigation_results);
88 92
89 // Creates AutocompleteMatches to search |template_url| for "<suggestion>" for 93 // Creates AutocompleteMatches to search |template_url| for "<suggestion>" for
90 // all suggestions in |results|, and adds them to |map|. 94 // all suggestions in |results|, and adds them to |map|.
91 void AddSuggestResultsToMap(const SuggestResults& results, 95 void AddSuggestResultsToMap(const SuggestResults& results,
92 const TemplateURL* template_url, 96 const TemplateURL* template_url,
93 MatchMap* map); 97 MatchMap* map);
94 98
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|. 99 // Returns an AutocompleteMatch for a navigational suggestion |navigation|.
109 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 100 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
110 101
111 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. 102 // Fetches zero-suggest suggestions by sending a request using |suggest_url|.
112 void Run(const GURL& suggest_url); 103 void Run(const GURL& suggest_url);
113 104
114 // Parses results from the zero-suggest server and updates results. 105 // Parses results from the zero-suggest server and updates results.
115 void ParseSuggestResults(const base::Value& root_val); 106 void ParseSuggestResults(const base::Value& root_val);
116 107
117 // Converts the parsed results to a set of AutocompleteMatches and adds them 108 // Converts the parsed results to a set of AutocompleteMatches and adds them
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 149
159 history::MostVisitedURLList most_visited_urls_; 150 history::MostVisitedURLList most_visited_urls_;
160 151
161 // For callbacks that may be run after destruction. 152 // For callbacks that may be run after destruction.
162 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; 153 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_;
163 154
164 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); 155 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider);
165 }; 156 };
166 157
167 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 158 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698