| 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 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 // |
| 11 // HUGE DISCLAIMER: This is just here for experimenting and will probably be | 11 // HUGE DISCLAIMER: This is just here for experimenting and will probably be |
| 12 // deleted entirely as we revise how suggestions work with the omnibox. | 12 // deleted entirely as we revise how suggestions work with the omnibox. |
| 13 | 13 |
| 14 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 14 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| 15 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 15 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| 16 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| 22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/string16.h" | 23 #include "base/string16.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 24 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 25 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
| 26 | 26 |
| 27 class AutocompleteInput; | 27 class AutocompleteInput; |
| 28 class GURL; | 28 class GURL; |
| 29 class PrefService; | |
| 30 class TemplateURLService; | 29 class TemplateURLService; |
| 31 | 30 |
| 32 namespace base { | 31 namespace base { |
| 33 class Value; | 32 class Value; |
| 34 } | 33 } |
| 35 | 34 |
| 36 namespace net { | 35 namespace net { |
| 37 class URLFetcher; | 36 class URLFetcher; |
| 38 } | 37 } |
| 39 | 38 |
| 40 // Autocomplete provider for searches based on the current URL. | 39 // Autocomplete provider for searches based on the current URL. |
| 41 // | 40 // |
| 42 // The controller will call StartZeroSuggest when the user focuses in the | 41 // The controller will call StartZeroSuggest when the user focuses in the |
| 43 // omnibox. After construction, the autocomplete controller repeatedly calls | 42 // omnibox. After construction, the autocomplete controller repeatedly calls |
| 44 // Start() with some user input, each time expecting to receive an updated | 43 // Start() with some user input, each time expecting to receive an updated |
| 45 // set of matches. | 44 // set of matches. |
| 46 // | 45 // |
| 47 // TODO(jered): Consider deleting this class and building this functionality | 46 // TODO(jered): Consider deleting this class and building this functionality |
| 48 // into SearchProvider after dogfood and after we break the association between | 47 // into SearchProvider after dogfood and after we break the association between |
| 49 // omnibox text and suggestions. | 48 // omnibox text and suggestions. |
| 50 class ZeroSuggestProvider : public AutocompleteProvider, | 49 class ZeroSuggestProvider : public AutocompleteProvider, |
| 51 public net::URLFetcherDelegate { | 50 public net::URLFetcherDelegate { |
| 52 public: | 51 public: |
| 53 // Creates and returns an instance of this provider if the feature is enabled. | 52 // Creates and returns an instance of this provider if the feature is enabled. |
| 54 // Returns NULL if not enabled. | 53 // Returns NULL if not enabled. |
| 55 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, | 54 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, |
| 56 Profile* profile); | 55 Profile* profile); |
| 57 | 56 |
| 58 static void RegisterUserPrefs(PrefService* user_prefs); | |
| 59 | |
| 60 // AutocompleteProvider: | 57 // AutocompleteProvider: |
| 61 virtual void Start(const AutocompleteInput& input, | 58 virtual void Start(const AutocompleteInput& input, |
| 62 bool /*minimal_changes*/) OVERRIDE; | 59 bool /*minimal_changes*/) OVERRIDE; |
| 63 virtual void Stop(bool clear_cached_results) OVERRIDE; | 60 virtual void Stop(bool clear_cached_results) OVERRIDE; |
| 64 | 61 |
| 65 // net::URLFetcherDelegate | 62 // net::URLFetcherDelegate |
| 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 63 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 67 | 64 |
| 68 // Initiates a new fetch for the given |url|, limiting suggestions to those | 65 // Initiates a new fetch for the given |url|, limiting suggestions to those |
| 69 // matching |user_text|. |user_text| may be non-empty if the user previously | 66 // matching |user_text|. |user_text| may be non-empty if the user previously |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Fetcher used to retrieve results. | 116 // Fetcher used to retrieve results. |
| 120 scoped_ptr<net::URLFetcher> fetcher_; | 117 scoped_ptr<net::URLFetcher> fetcher_; |
| 121 | 118 |
| 122 // Suggestions for the most recent query. | 119 // Suggestions for the most recent query. |
| 123 std::vector<string16> results_; | 120 std::vector<string16> results_; |
| 124 | 121 |
| 125 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 122 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
| 126 }; | 123 }; |
| 127 | 124 |
| 128 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 125 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| OLD | NEW |