OLD | NEW |
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/autocomplete/autocomplete_input.h" | 19 #include "components/autocomplete/autocomplete_input.h" |
20 #include "components/autocomplete/autocomplete_match.h" | 20 #include "components/autocomplete/autocomplete_match.h" |
21 #include "components/autocomplete/autocomplete_provider.h" | 21 #include "components/autocomplete/autocomplete_provider.h" |
22 #include "components/autocomplete/search_suggestion_parser.h" | 22 #include "components/autocomplete/search_suggestion_parser.h" |
23 #include "components/metrics/proto/omnibox_event.pb.h" | 23 #include "components/metrics/proto/omnibox_event.pb.h" |
24 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
25 | 25 |
26 class AutocompleteProviderListener; | 26 class AutocompleteProviderListener; |
27 class GURL; | 27 class GURL; |
28 class Profile; | 28 class Profile; |
| 29 class SearchTermsData; |
29 class SuggestionDeletionHandler; | 30 class SuggestionDeletionHandler; |
30 class TemplateURL; | 31 class TemplateURL; |
| 32 class TemplateURLService; |
31 | 33 |
32 namespace base { | 34 namespace base { |
33 class DictionaryValue; | 35 class DictionaryValue; |
34 class ListValue; | 36 class ListValue; |
35 class Value; | 37 class Value; |
36 } | 38 } |
37 | 39 |
38 // Base functionality for receiving suggestions from a search engine. | 40 // Base functionality for receiving suggestions from a search engine. |
39 // This class is abstract and should only be used as a base for other | 41 // This class is abstract and should only be used as a base for other |
40 // autocomplete providers utilizing its functionality. | 42 // autocomplete providers utilizing its functionality. |
41 class BaseSearchProvider : public AutocompleteProvider, | 43 class BaseSearchProvider : public AutocompleteProvider, |
42 public net::URLFetcherDelegate { | 44 public net::URLFetcherDelegate { |
43 public: | 45 public: |
44 // ID used in creating URLFetcher for default provider's suggest results. | 46 // ID used in creating URLFetcher for default provider's suggest results. |
45 static const int kDefaultProviderURLFetcherID; | 47 static const int kDefaultProviderURLFetcherID; |
46 | 48 |
47 // ID used in creating URLFetcher for keyword provider's suggest results. | 49 // ID used in creating URLFetcher for keyword provider's suggest results. |
48 static const int kKeywordProviderURLFetcherID; | 50 static const int kKeywordProviderURLFetcherID; |
49 | 51 |
50 // ID used in creating URLFetcher for deleting suggestion results. | 52 // ID used in creating URLFetcher for deleting suggestion results. |
51 static const int kDeletionURLFetcherID; | 53 static const int kDeletionURLFetcherID; |
52 | 54 |
53 BaseSearchProvider(AutocompleteProviderListener* listener, | 55 BaseSearchProvider(AutocompleteProviderListener* listener, |
| 56 TemplateURLService* template_url_service, |
54 Profile* profile, | 57 Profile* profile, |
55 AutocompleteProvider::Type type); | 58 AutocompleteProvider::Type type); |
56 | 59 |
57 // Returns whether |match| is flagged as a query that should be prefetched. | 60 // Returns whether |match| is flagged as a query that should be prefetched. |
58 static bool ShouldPrefetch(const AutocompleteMatch& match); | 61 static bool ShouldPrefetch(const AutocompleteMatch& match); |
59 | 62 |
60 // Returns a simpler AutocompleteMatch suitable for persistence like in | 63 // Returns a simpler AutocompleteMatch suitable for persistence like in |
61 // ShortcutsDatabase. | 64 // ShortcutsDatabase. |
62 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion | 65 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion |
63 // with protected access. | 66 // with protected access. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // page URL or personal data in unencrypted network traffic. | 138 // page URL or personal data in unencrypted network traffic. |
136 // * The user has suggest enabled in their settings and is not in incognito | 139 // * The user has suggest enabled in their settings and is not in incognito |
137 // mode. (Incognito disables suggest entirely.) | 140 // mode. (Incognito disables suggest entirely.) |
138 // * The user's suggest provider is Google. We might want to allow other | 141 // * The user's suggest provider is Google. We might want to allow other |
139 // providers to see this data someday, but for now this has only been | 142 // providers to see this data someday, but for now this has only been |
140 // implemented for Google. | 143 // implemented for Google. |
141 static bool ZeroSuggestEnabled( | 144 static bool ZeroSuggestEnabled( |
142 const GURL& suggest_url, | 145 const GURL& suggest_url, |
143 const TemplateURL* template_url, | 146 const TemplateURL* template_url, |
144 metrics::OmniboxEventProto::PageClassification page_classification, | 147 metrics::OmniboxEventProto::PageClassification page_classification, |
| 148 const SearchTermsData& search_terms_data, |
145 Profile* profile); | 149 Profile* profile); |
146 | 150 |
147 // Returns whether we can send the URL of the current page in any suggest | 151 // Returns whether we can send the URL of the current page in any suggest |
148 // requests. Doing this requires that all the following hold: | 152 // requests. Doing this requires that all the following hold: |
149 // * ZeroSuggestEnabled() is true, so we meet the requirements above. | 153 // * ZeroSuggestEnabled() is true, so we meet the requirements above. |
150 // * The current URL is HTTP, or HTTPS with the same domain as the suggest | 154 // * The current URL is HTTP, or HTTPS with the same domain as the suggest |
151 // server. Non-HTTP[S] URLs (e.g. FTP/file URLs) may contain sensitive | 155 // server. Non-HTTP[S] URLs (e.g. FTP/file URLs) may contain sensitive |
152 // information. HTTPS URLs may also contain sensitive information, but if | 156 // information. HTTPS URLs may also contain sensitive information, but if |
153 // they're on the same domain as the suggest server, then the relevant | 157 // they're on the same domain as the suggest server, then the relevant |
154 // entity could have already seen/logged this data. | 158 // entity could have already seen/logged this data. |
155 // * The user is OK in principle with sending URLs of current pages to their | 159 // * The user is OK in principle with sending URLs of current pages to their |
156 // provider. Today, there is no explicit setting that controls this, but if | 160 // provider. Today, there is no explicit setting that controls this, but if |
157 // the user has tab sync enabled and tab sync is unencrypted, then they're | 161 // the user has tab sync enabled and tab sync is unencrypted, then they're |
158 // already sending this data to Google for sync purposes. Thus we use this | 162 // already sending this data to Google for sync purposes. Thus we use this |
159 // setting as a proxy for "it's OK to send such data". In the future, | 163 // setting as a proxy for "it's OK to send such data". In the future, |
160 // especially if we want to support suggest providers other than Google, we | 164 // especially if we want to support suggest providers other than Google, we |
161 // may change this to be a standalone setting or part of some explicit | 165 // may change this to be a standalone setting or part of some explicit |
162 // general opt-in. | 166 // general opt-in. |
163 static bool CanSendURL( | 167 static bool CanSendURL( |
164 const GURL& current_page_url, | 168 const GURL& current_page_url, |
165 const GURL& suggest_url, | 169 const GURL& suggest_url, |
166 const TemplateURL* template_url, | 170 const TemplateURL* template_url, |
167 metrics::OmniboxEventProto::PageClassification page_classification, | 171 metrics::OmniboxEventProto::PageClassification page_classification, |
| 172 const SearchTermsData& search_terms_data, |
168 Profile* profile); | 173 Profile* profile); |
169 | 174 |
170 // net::URLFetcherDelegate: | 175 // net::URLFetcherDelegate: |
171 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 176 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
172 | 177 |
173 // If the |deletion_url| is valid, then set |match.deletable| to true and | 178 // If the |deletion_url| is valid, then set |match.deletable| to true and |
174 // save the |deletion_url| into the |match|'s additional info under | 179 // save the |deletion_url| into the |match|'s additional info under |
175 // the key |kDeletionUrlKey|. | 180 // the key |kDeletionUrlKey|. |
176 void SetDeletionURL(const std::string& deletion_url, | 181 void SetDeletionURL(const std::string& deletion_url, |
177 AutocompleteMatch* match); | 182 AutocompleteMatch* match); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 metrics::OmniboxEventProto_ProviderInfo* provider_info) const; | 250 metrics::OmniboxEventProto_ProviderInfo* provider_info) const; |
246 | 251 |
247 // Returns whether the |fetcher| is for the keyword provider. | 252 // Returns whether the |fetcher| is for the keyword provider. |
248 virtual bool IsKeywordFetcher(const net::URLFetcher* fetcher) const = 0; | 253 virtual bool IsKeywordFetcher(const net::URLFetcher* fetcher) const = 0; |
249 | 254 |
250 // Updates |matches_| from the latest results; applies calculated relevances | 255 // Updates |matches_| from the latest results; applies calculated relevances |
251 // if suggested relevances cause undesriable behavior. Updates |done_|. | 256 // if suggested relevances cause undesriable behavior. Updates |done_|. |
252 virtual void UpdateMatches() = 0; | 257 virtual void UpdateMatches() = 0; |
253 | 258 |
254 AutocompleteProviderListener* listener_; | 259 AutocompleteProviderListener* listener_; |
| 260 TemplateURLService* template_url_service_; |
255 Profile* profile_; | 261 Profile* profile_; |
256 | 262 |
257 // Whether a field trial, if any, has triggered in the most recent | 263 // Whether a field trial, if any, has triggered in the most recent |
258 // autocomplete query. This field is set to true only if the suggestion | 264 // autocomplete query. This field is set to true only if the suggestion |
259 // provider has completed and the response contained | 265 // provider has completed and the response contained |
260 // '"google:fieldtrialtriggered":true'. | 266 // '"google:fieldtrialtriggered":true'. |
261 bool field_trial_triggered_; | 267 bool field_trial_triggered_; |
262 | 268 |
263 // Same as above except that it is maintained across the current Omnibox | 269 // Same as above except that it is maintained across the current Omnibox |
264 // session. | 270 // session. |
(...skipping 18 matching lines...) Expand all Loading... |
283 | 289 |
284 // Each deletion handler in this vector corresponds to an outstanding request | 290 // Each deletion handler in this vector corresponds to an outstanding request |
285 // that a server delete a personalized suggestion. Making this a ScopedVector | 291 // that a server delete a personalized suggestion. Making this a ScopedVector |
286 // causes us to auto-cancel all such requests on shutdown. | 292 // causes us to auto-cancel all such requests on shutdown. |
287 SuggestionDeletionHandlers deletion_handlers_; | 293 SuggestionDeletionHandlers deletion_handlers_; |
288 | 294 |
289 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 295 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
290 }; | 296 }; |
291 | 297 |
292 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 298 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |