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

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

Issue 500023002: Introduce AutocompleteProviderDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 class contains common functionality for search-based autocomplete 5 // This class contains common functionality for search-based autocomplete
6 // providers. Search provider and zero suggest provider both use it for common 6 // providers. Search provider and zero suggest provider both use it for common
7 // functionality. 7 // functionality.
8 8
9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_
10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_
11 11
12 #include <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "components/metrics/proto/omnibox_event.pb.h" 19 #include "components/metrics/proto/omnibox_event.pb.h"
20 #include "components/omnibox/autocomplete_input.h" 20 #include "components/omnibox/autocomplete_input.h"
21 #include "components/omnibox/autocomplete_match.h" 21 #include "components/omnibox/autocomplete_match.h"
22 #include "components/omnibox/autocomplete_provider.h" 22 #include "components/omnibox/autocomplete_provider.h"
23 #include "components/omnibox/search_suggestion_parser.h" 23 #include "components/omnibox/search_suggestion_parser.h"
24 24
25 class AutocompleteProviderDelegate;
25 class GURL; 26 class GURL;
26 class Profile;
27 class SearchTermsData; 27 class SearchTermsData;
28 class SuggestionDeletionHandler; 28 class SuggestionDeletionHandler;
29 class TemplateURL; 29 class TemplateURL;
30 class TemplateURLService; 30 class TemplateURLService;
31 31
32 namespace base { 32 namespace base {
33 class DictionaryValue; 33 class DictionaryValue;
34 class ListValue; 34 class ListValue;
35 class Value; 35 class Value;
36 } 36 }
37 37
38 // Base functionality for receiving suggestions from a search engine. 38 // Base functionality for receiving suggestions from a search engine.
39 // This class is abstract and should only be used as a base for other 39 // This class is abstract and should only be used as a base for other
40 // autocomplete providers utilizing its functionality. 40 // autocomplete providers utilizing its functionality.
41 class BaseSearchProvider : public AutocompleteProvider { 41 class BaseSearchProvider : public AutocompleteProvider {
42 public: 42 public:
43 // ID used in creating URLFetcher for default provider's suggest results. 43 // ID used in creating URLFetcher for default provider's suggest results.
44 static const int kDefaultProviderURLFetcherID; 44 static const int kDefaultProviderURLFetcherID;
45 45
46 // ID used in creating URLFetcher for keyword provider's suggest results. 46 // ID used in creating URLFetcher for keyword provider's suggest results.
47 static const int kKeywordProviderURLFetcherID; 47 static const int kKeywordProviderURLFetcherID;
48 48
49 // ID used in creating URLFetcher for deleting suggestion results. 49 // ID used in creating URLFetcher for deleting suggestion results.
50 static const int kDeletionURLFetcherID; 50 static const int kDeletionURLFetcherID;
51 51
52 BaseSearchProvider(TemplateURLService* template_url_service, 52 BaseSearchProvider(TemplateURLService* template_url_service,
53 Profile* profile, 53 scoped_ptr<AutocompleteProviderDelegate> delegate,
54 AutocompleteProvider::Type type); 54 AutocompleteProvider::Type type);
55 55
56 // Returns whether |match| is flagged as a query that should be prefetched. 56 // Returns whether |match| is flagged as a query that should be prefetched.
57 static bool ShouldPrefetch(const AutocompleteMatch& match); 57 static bool ShouldPrefetch(const AutocompleteMatch& match);
58 58
59 // Returns a simpler AutocompleteMatch suitable for persistence like in 59 // Returns a simpler AutocompleteMatch suitable for persistence like in
60 // ShortcutsDatabase. This wrapper function uses a number of default values 60 // ShortcutsDatabase. This wrapper function uses a number of default values
61 // that may or may not be appropriate for your needs. 61 // that may or may not be appropriate for your needs.
62 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion 62 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion
63 // with protected access. 63 // with protected access.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // * The user has suggest enabled in their settings and is not in incognito 138 // * The user has suggest enabled in their settings and is not in incognito
139 // mode. (Incognito disables suggest entirely.) 139 // mode. (Incognito disables suggest entirely.)
140 // * The user's suggest provider is Google. We might want to allow other 140 // * The user's suggest provider is Google. We might want to allow other
141 // providers to see this data someday, but for now this has only been 141 // providers to see this data someday, but for now this has only been
142 // implemented for Google. 142 // implemented for Google.
143 static bool ZeroSuggestEnabled( 143 static bool ZeroSuggestEnabled(
144 const GURL& suggest_url, 144 const GURL& suggest_url,
145 const TemplateURL* template_url, 145 const TemplateURL* template_url,
146 metrics::OmniboxEventProto::PageClassification page_classification, 146 metrics::OmniboxEventProto::PageClassification page_classification,
147 const SearchTermsData& search_terms_data, 147 const SearchTermsData& search_terms_data,
148 Profile* profile); 148 AutocompleteProviderDelegate* delegate);
149 149
150 // Returns whether we can send the URL of the current page in any suggest 150 // Returns whether we can send the URL of the current page in any suggest
151 // requests. Doing this requires that all the following hold: 151 // requests. Doing this requires that all the following hold:
152 // * ZeroSuggestEnabled() is true, so we meet the requirements above. 152 // * ZeroSuggestEnabled() is true, so we meet the requirements above.
153 // * The current URL is HTTP, or HTTPS with the same domain as the suggest 153 // * The current URL is HTTP, or HTTPS with the same domain as the suggest
154 // server. Non-HTTP[S] URLs (e.g. FTP/file URLs) may contain sensitive 154 // server. Non-HTTP[S] URLs (e.g. FTP/file URLs) may contain sensitive
155 // information. HTTPS URLs may also contain sensitive information, but if 155 // information. HTTPS URLs may also contain sensitive information, but if
156 // they're on the same domain as the suggest server, then the relevant 156 // they're on the same domain as the suggest server, then the relevant
157 // entity could have already seen/logged this data. 157 // entity could have already seen/logged this data.
158 // * The user is OK in principle with sending URLs of current pages to their 158 // * The user is OK in principle with sending URLs of current pages to their
159 // provider. Today, there is no explicit setting that controls this, but if 159 // provider. Today, there is no explicit setting that controls this, but if
160 // the user has tab sync enabled and tab sync is unencrypted, then they're 160 // the user has tab sync enabled and tab sync is unencrypted, then they're
161 // already sending this data to Google for sync purposes. Thus we use this 161 // already sending this data to Google for sync purposes. Thus we use this
162 // setting as a proxy for "it's OK to send such data". In the future, 162 // setting as a proxy for "it's OK to send such data". In the future,
163 // especially if we want to support suggest providers other than Google, we 163 // especially if we want to support suggest providers other than Google, we
164 // may change this to be a standalone setting or part of some explicit 164 // may change this to be a standalone setting or part of some explicit
165 // general opt-in. 165 // general opt-in.
166 static bool CanSendURL( 166 static bool CanSendURL(
167 const GURL& current_page_url, 167 const GURL& current_page_url,
168 const GURL& suggest_url, 168 const GURL& suggest_url,
169 const TemplateURL* template_url, 169 const TemplateURL* template_url,
170 metrics::OmniboxEventProto::PageClassification page_classification, 170 metrics::OmniboxEventProto::PageClassification page_classification,
171 const SearchTermsData& search_terms_data, 171 const SearchTermsData& search_terms_data,
172 Profile* profile); 172 AutocompleteProviderDelegate* delegate);
173 173
174 // If the |deletion_url| is valid, then set |match.deletable| to true and 174 // If the |deletion_url| is valid, then set |match.deletable| to true and
175 // save the |deletion_url| into the |match|'s additional info under 175 // save the |deletion_url| into the |match|'s additional info under
176 // the key |kDeletionUrlKey|. 176 // the key |kDeletionUrlKey|.
177 void SetDeletionURL(const std::string& deletion_url, 177 void SetDeletionURL(const std::string& deletion_url,
178 AutocompleteMatch* match); 178 AutocompleteMatch* match);
179 179
180 // Creates an AutocompleteMatch from |result| to search for the query in 180 // Creates an AutocompleteMatch from |result| to search for the query in
181 // |result|. Adds the created match to |map|; if such a match 181 // |result|. Adds the created match to |map|; if such a match
182 // already exists, whichever one has lower relevance is eliminated. 182 // already exists, whichever one has lower relevance is eliminated.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 // Returns whether the destination URL corresponding to the given |result| 215 // Returns whether the destination URL corresponding to the given |result|
216 // should contain command-line-specified query params. 216 // should contain command-line-specified query params.
217 virtual bool ShouldAppendExtraParams( 217 virtual bool ShouldAppendExtraParams(
218 const SearchSuggestionParser::SuggestResult& result) const = 0; 218 const SearchSuggestionParser::SuggestResult& result) const = 0;
219 219
220 // Records in UMA whether the deletion request resulted in success. 220 // Records in UMA whether the deletion request resulted in success.
221 virtual void RecordDeletionResult(bool success) = 0; 221 virtual void RecordDeletionResult(bool success) = 0;
222 222
223 TemplateURLService* template_url_service_; 223 TemplateURLService* template_url_service_;
224 Profile* profile_; 224 scoped_ptr<AutocompleteProviderDelegate> delegate_;
225 225
226 // Whether a field trial, if any, has triggered in the most recent 226 // Whether a field trial, if any, has triggered in the most recent
227 // autocomplete query. This field is set to true only if the suggestion 227 // autocomplete query. This field is set to true only if the suggestion
228 // provider has completed and the response contained 228 // provider has completed and the response contained
229 // '"google:fieldtrialtriggered":true'. 229 // '"google:fieldtrialtriggered":true'.
230 bool field_trial_triggered_; 230 bool field_trial_triggered_;
231 231
232 // Same as above except that it is maintained across the current Omnibox 232 // Same as above except that it is maintained across the current Omnibox
233 // session. 233 // session.
234 bool field_trial_triggered_in_session_; 234 bool field_trial_triggered_in_session_;
(...skipping 13 matching lines...) Expand all
248 248
249 // Each deletion handler in this vector corresponds to an outstanding request 249 // Each deletion handler in this vector corresponds to an outstanding request
250 // that a server delete a personalized suggestion. Making this a ScopedVector 250 // that a server delete a personalized suggestion. Making this a ScopedVector
251 // causes us to auto-cancel all such requests on shutdown. 251 // causes us to auto-cancel all such requests on shutdown.
252 SuggestionDeletionHandlers deletion_handlers_; 252 SuggestionDeletionHandlers deletion_handlers_;
253 253
254 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); 254 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider);
255 }; 255 };
256 256
257 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ 257 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698