Chromium Code Reviews| 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 Search autocomplete provider. This provider is | 5 // This file contains the Search autocomplete provider. This provider is |
| 6 // responsible for all autocomplete entries that start with "Search <engine> | 6 // responsible for all autocomplete entries that start with "Search <engine> |
| 7 // for ...", including searching for the current input string, search | 7 // for ...", including searching for the current input string, search |
| 8 // history, and search suggestions. An instance of it gets created and | 8 // history, and search suggestions. An instance of it gets created and |
| 9 // managed by the autocomplete controller. | 9 // managed by the autocomplete controller. |
| 10 | 10 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 bool IsTopMatchSearchWithURLInput() const; | 241 bool IsTopMatchSearchWithURLInput() const; |
| 242 | 242 |
| 243 // Converts an appropriate number of navigation results in | 243 // Converts an appropriate number of navigation results in |
| 244 // |navigation_results| to matches and adds them to |matches|. | 244 // |navigation_results| to matches and adds them to |matches|. |
| 245 void AddNavigationResultsToMatches( | 245 void AddNavigationResultsToMatches( |
| 246 const SearchSuggestionParser::NavigationResults& navigation_results, | 246 const SearchSuggestionParser::NavigationResults& navigation_results, |
| 247 ACMatches* matches); | 247 ACMatches* matches); |
| 248 | 248 |
| 249 // Adds a match for each result in |results| to |map|. |is_keyword| indicates | 249 // Adds a match for each result in |results| to |map|. |is_keyword| indicates |
| 250 // whether the results correspond to the keyword provider or default provider. | 250 // whether the results correspond to the keyword provider or default provider. |
| 251 void AddHistoryResultsToMap(const HistoryResults& results, | 251 void AddRawHistoryResultsToMap(const HistoryResults& results, |
| 252 bool is_keyword, | 252 bool is_keyword, |
| 253 int did_not_accept_suggestion, | 253 int did_not_accept_suggestion, |
| 254 MatchMap* map); | 254 MatchMap* map); |
| 255 | |
| 256 // Adds a match for each transformed result in |results| to |map|. | |
| 257 void AddTransformedHistoryResultsToMap( | |
| 258 const SearchSuggestionParser::SuggestResults& results, | |
| 259 int did_not_accept_suggestion, | |
| 260 MatchMap* map); | |
| 255 | 261 |
| 256 // Calculates relevance scores for all |results|. | 262 // Calculates relevance scores for all |results|. |
| 257 SearchSuggestionParser::SuggestResults ScoreHistoryResults( | 263 SearchSuggestionParser::SuggestResults ScoreHistoryResultsHelper( |
| 258 const HistoryResults& results, | 264 const HistoryResults& results, |
| 259 bool base_prevent_inline_autocomplete, | 265 bool base_prevent_inline_autocomplete, |
| 260 bool input_multiple_words, | 266 bool input_multiple_words, |
| 261 const base::string16& input_text, | 267 const base::string16& input_text, |
| 262 bool is_keyword); | 268 bool is_keyword); |
| 263 | 269 |
| 270 // Calculates relevance scores for |results|, adjusting for boundary | |
| 271 // conditions around multi-word queries. (See inline comments in function | |
| 272 // definition for more details.) | |
| 273 void ScoreHistoryResults( | |
| 274 const HistoryResults& results, | |
| 275 bool is_keyword, | |
| 276 SearchSuggestionParser::SuggestResults* scored_results); | |
| 277 | |
| 264 // Adds matches for |results| to |map|. | 278 // Adds matches for |results| to |map|. |
| 265 void AddSuggestResultsToMap( | 279 void AddSuggestResultsToMap( |
| 266 const SearchSuggestionParser::SuggestResults& results, | 280 const SearchSuggestionParser::SuggestResults& results, |
| 267 const std::string& metadata, | 281 const std::string& metadata, |
| 268 MatchMap* map); | 282 MatchMap* map); |
| 269 | 283 |
| 270 // Gets the relevance score for the verbatim result. This value may be | 284 // Gets the relevance score for the verbatim result. This value may be |
| 271 // provided by the suggest server or calculated locally; if | 285 // provided by the suggest server or calculated locally; if |
| 272 // |relevance_from_server| is non-NULL, it will be set to indicate which of | 286 // |relevance_from_server| is non-NULL, it will be set to indicate which of |
| 273 // those is true. | 287 // those is true. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 // Returns an AutocompleteMatch for a navigational suggestion. | 320 // Returns an AutocompleteMatch for a navigational suggestion. |
| 307 AutocompleteMatch NavigationToMatch( | 321 AutocompleteMatch NavigationToMatch( |
| 308 const SearchSuggestionParser::NavigationResult& navigation); | 322 const SearchSuggestionParser::NavigationResult& navigation); |
| 309 | 323 |
| 310 // Updates the value of |done_| from the internal state. | 324 // Updates the value of |done_| from the internal state. |
| 311 void UpdateDone(); | 325 void UpdateDone(); |
| 312 | 326 |
| 313 // Obtains a session token, regenerating if necessary. | 327 // Obtains a session token, regenerating if necessary. |
| 314 std::string GetSessionToken(); | 328 std::string GetSessionToken(); |
| 315 | 329 |
| 316 // Answers prefetch handling - finds previously displayed answer matching the | 330 // Answers prefetch handling - finds previously displayed answer matching the |
|
Mark P
2014/09/22 20:23:49
nit: finds -> find the
groby-ooo-7-16
2014/09/24 20:30:35
Done.
| |
| 317 // current |input| and sets |prefetch_data_|. | 331 // current top-scoring history result. If there is a previous answer, returns |
| 318 void DoAnswersQuery(const AutocompleteInput& input); | 332 // the query data associated with it. Otherwise, returns empty |
|
Mark P
2014/09/22 20:23:49
nit: returns empty -> returns an empty AnswersQuer
groby-ooo-7-16
2014/09/24 20:30:35
Done.
| |
| 333 // AnswersQueryData. | |
| 334 AnswersQueryData FindAnswersPrefetchData(); | |
| 319 | 335 |
| 320 // The amount of time to wait before sending a new suggest request after the | 336 // The amount of time to wait before sending a new suggest request after the |
| 321 // previous one. Non-const because some unittests modify this value. | 337 // previous one. Non-const because some unittests modify this value. |
| 322 static int kMinimumTimeBetweenSuggestQueriesMs; | 338 static int kMinimumTimeBetweenSuggestQueriesMs; |
| 323 | 339 |
| 324 AutocompleteProviderListener* listener_; | 340 AutocompleteProviderListener* listener_; |
| 325 | 341 |
| 326 // The number of suggest results that haven't yet arrived. If it's greater | 342 // The number of suggest results that haven't yet arrived. If it's greater |
| 327 // than 0, it indicates that one of the URLFetchers is still running. | 343 // than 0, it indicates that one of the URLFetchers is still running. |
| 328 int suggest_results_pending_; | 344 int suggest_results_pending_; |
| 329 | 345 |
| 330 // Maintains the TemplateURLs used. | 346 // Maintains the TemplateURLs used. |
| 331 Providers providers_; | 347 Providers providers_; |
| 332 | 348 |
| 333 // The user's input. | 349 // The user's input. |
| 334 AutocompleteInput input_; | 350 AutocompleteInput input_; |
| 335 | 351 |
| 336 // Input when searching against the keyword provider. | 352 // Input when searching against the keyword provider. |
| 337 AutocompleteInput keyword_input_; | 353 AutocompleteInput keyword_input_; |
| 338 | 354 |
| 339 // Searches in the user's history that begin with the input text. | 355 // Searches in the user's history that begin with the input text. |
| 340 HistoryResults keyword_history_results_; | 356 HistoryResults raw_keyword_history_results_; |
| 341 HistoryResults default_history_results_; | 357 HistoryResults raw_default_history_results_; |
| 358 | |
| 359 // Scored searches in the user's history - based on |keyword_history_results_| | |
| 360 // or |default_history_results_| as appropriate. | |
| 361 SearchSuggestionParser::SuggestResults transformed_keyword_history_results_; | |
| 362 SearchSuggestionParser::SuggestResults transformed_default_history_results_; | |
| 342 | 363 |
| 343 // A timer to start a query to the suggest server after the user has stopped | 364 // A timer to start a query to the suggest server after the user has stopped |
| 344 // typing for long enough. | 365 // typing for long enough. |
| 345 base::OneShotTimer<SearchProvider> timer_; | 366 base::OneShotTimer<SearchProvider> timer_; |
| 346 | 367 |
| 347 // The time at which we sent a query to the suggest server. | 368 // The time at which we sent a query to the suggest server. |
| 348 base::TimeTicks time_suggest_request_sent_; | 369 base::TimeTicks time_suggest_request_sent_; |
| 349 | 370 |
| 350 // Fetchers used to retrieve results for the keyword and default providers. | 371 // Fetchers used to retrieve results for the keyword and default providers. |
| 351 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 372 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 367 base::TimeTicks token_expiration_time_; | 388 base::TimeTicks token_expiration_time_; |
| 368 | 389 |
| 369 // Answers prefetch management. | 390 // Answers prefetch management. |
| 370 AnswersCache answers_cache_; // Cache for last answers seen. | 391 AnswersCache answers_cache_; // Cache for last answers seen. |
| 371 AnswersQueryData prefetch_data_; // Data to use for query prefetching. | 392 AnswersQueryData prefetch_data_; // Data to use for query prefetching. |
| 372 | 393 |
| 373 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 394 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
| 374 }; | 395 }; |
| 375 | 396 |
| 376 #endif // COMPONENTS_OMNIBOX_SEARCH_PROVIDER_H_ | 397 #endif // COMPONENTS_OMNIBOX_SEARCH_PROVIDER_H_ |
| OLD | NEW |