| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 non-keyword autocomplete entries that start with | 6 // responsible for all non-keyword autocomplete entries that start with |
| 7 // "Search <engine> for ...", including searching for the current input string, | 7 // "Search <engine> for ...", including searching for the current input string, |
| 8 // search history, and search suggestions. An instance of it gets created and | 8 // search 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 // |
| 11 // For more information on the autocomplete system in general, including how | 11 // For more information on the autocomplete system in general, including how |
| 12 // the autocomplete controller and autocomplete providers work, see | 12 // the autocomplete controller and autocomplete providers work, see |
| 13 // chrome/browser/autocomplete.h. | 13 // chrome/browser/autocomplete.h. |
| 14 | 14 |
| 15 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 15 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
| 16 #define CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 16 #define CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
| 17 #pragma once | 17 #pragma once |
| 18 | 18 |
| 19 #include <map> | 19 #include <map> |
| 20 #include <string> | 20 #include <string> |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete.h" | 24 #include "chrome/browser/autocomplete/autocomplete.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_match.h" | 25 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 26 #include "chrome/browser/history/history_types.h" | 26 #include "chrome/browser/history/history_types.h" |
| 27 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 28 #include "chrome/browser/search_engines/template_url_id.h" | 28 #include "chrome/browser/search_engines/template_url_id.h" |
| 29 #include "content/common/net/url_fetcher.h" | 29 #include "content/public/common/url_fetcher_delegate.h" |
| 30 | 30 |
| 31 class Profile; | 31 class Profile; |
| 32 | 32 |
| 33 namespace base { | 33 namespace base { |
| 34 class Value; | 34 class Value; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Autocomplete provider for searches and suggestions from a search engine. | 37 // Autocomplete provider for searches and suggestions from a search engine. |
| 38 // | 38 // |
| 39 // After construction, the autocomplete controller repeatedly calls Start() | 39 // After construction, the autocomplete controller repeatedly calls Start() |
| 40 // with some user input, each time expecting to receive a small set of the best | 40 // with some user input, each time expecting to receive a small set of the best |
| 41 // matches (either synchronously or asynchronously). | 41 // matches (either synchronously or asynchronously). |
| 42 // | 42 // |
| 43 // Initially the provider creates a match that searches for the current input | 43 // Initially the provider creates a match that searches for the current input |
| 44 // text. It also starts a task to query the Suggest servers. When that data | 44 // text. It also starts a task to query the Suggest servers. When that data |
| 45 // comes back, the provider creates and returns matches for the best | 45 // comes back, the provider creates and returns matches for the best |
| 46 // suggestions. | 46 // suggestions. |
| 47 class SearchProvider : public AutocompleteProvider, | 47 class SearchProvider : public AutocompleteProvider, |
| 48 public URLFetcher::Delegate { | 48 public content::URLFetcherDelegate { |
| 49 public: | 49 public: |
| 50 SearchProvider(ACProviderListener* listener, Profile* profile); | 50 SearchProvider(ACProviderListener* listener, Profile* profile); |
| 51 | 51 |
| 52 #if defined(UNIT_TEST) | 52 #if defined(UNIT_TEST) |
| 53 static void set_query_suggest_immediately(bool value) { | 53 static void set_query_suggest_immediately(bool value) { |
| 54 query_suggest_immediately_ = value; | 54 query_suggest_immediately_ = value; |
| 55 } | 55 } |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 // Marks the instant query as done. If |input_text| is non-empty this changes | 58 // Marks the instant query as done. If |input_text| is non-empty this changes |
| 59 // the 'search what you typed' results text to |input_text| + |suggest_text|. | 59 // the 'search what you typed' results text to |input_text| + |suggest_text|. |
| 60 // |input_text| is the text the user input into the edit. |input_text| differs | 60 // |input_text| is the text the user input into the edit. |input_text| differs |
| 61 // from |input_.text()| if the input contained whitespace. | 61 // from |input_.text()| if the input contained whitespace. |
| 62 // | 62 // |
| 63 // This method also marks the search provider as no longer needing to wait for | 63 // This method also marks the search provider as no longer needing to wait for |
| 64 // the instant result. | 64 // the instant result. |
| 65 void FinalizeInstantQuery(const string16& input_text, | 65 void FinalizeInstantQuery(const string16& input_text, |
| 66 const string16& suggest_text); | 66 const string16& suggest_text); |
| 67 | 67 |
| 68 // AutocompleteProvider | 68 // AutocompleteProvider |
| 69 virtual void Start(const AutocompleteInput& input, | 69 virtual void Start(const AutocompleteInput& input, |
| 70 bool minimal_changes) OVERRIDE; | 70 bool minimal_changes) OVERRIDE; |
| 71 virtual void Stop() OVERRIDE; | 71 virtual void Stop() OVERRIDE; |
| 72 | 72 |
| 73 // URLFetcher::Delegate | 73 // content::URLFetcherDelegate |
| 74 virtual void OnURLFetchComplete(const URLFetcher* source, | 74 virtual void OnURLFetchComplete(const URLFetcher* source); |
| 75 const GURL& url, | |
| 76 const net::URLRequestStatus& status, | |
| 77 int response_code, | |
| 78 const net::ResponseCookies& cookies, | |
| 79 const std::string& data); | |
| 80 | 75 |
| 81 // ID used in creating URLFetcher for default provider's suggest results. | 76 // ID used in creating URLFetcher for default provider's suggest results. |
| 82 static const int kDefaultProviderURLFetcherID; | 77 static const int kDefaultProviderURLFetcherID; |
| 83 | 78 |
| 84 // ID used in creating URLFetcher for keyword provider's suggest results. | 79 // ID used in creating URLFetcher for keyword provider's suggest results. |
| 85 static const int kKeywordProviderURLFetcherID; | 80 static const int kKeywordProviderURLFetcherID; |
| 86 | 81 |
| 87 private: | 82 private: |
| 88 virtual ~SearchProvider(); | 83 virtual ~SearchProvider(); |
| 89 | 84 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // Has FinalizeInstantQuery been invoked since the last |Start|? | 326 // Has FinalizeInstantQuery been invoked since the last |Start|? |
| 332 bool instant_finalized_; | 327 bool instant_finalized_; |
| 333 | 328 |
| 334 // The |suggest_text| parameter passed to FinalizeInstantQuery. | 329 // The |suggest_text| parameter passed to FinalizeInstantQuery. |
| 335 string16 default_provider_suggest_text_; | 330 string16 default_provider_suggest_text_; |
| 336 | 331 |
| 337 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 332 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
| 338 }; | 333 }; |
| 339 | 334 |
| 340 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 335 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
| OLD | NEW |