| 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; |
| 29 class TemplateURLService; | 30 class TemplateURLService; |
| 30 | 31 |
| 31 namespace base { | 32 namespace base { |
| 32 class Value; | 33 class Value; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace net { | 36 namespace net { |
| 36 class URLFetcher; | 37 class URLFetcher; |
| 37 } | 38 } |
| 38 | 39 |
| 39 // Autocomplete provider for searches based on the current URL. | 40 // Autocomplete provider for searches based on the current URL. |
| 40 // | 41 // |
| 41 // The controller will call StartZeroSuggest when the user focuses in the | 42 // The controller will call StartZeroSuggest when the user focuses in the |
| 42 // omnibox. After construction, the autocomplete controller repeatedly calls | 43 // omnibox. After construction, the autocomplete controller repeatedly calls |
| 43 // Start() with some user input, each time expecting to receive an updated | 44 // Start() with some user input, each time expecting to receive an updated |
| 44 // set of matches. | 45 // set of matches. |
| 45 // | 46 // |
| 46 // TODO(jered): Consider deleting this class and building this functionality | 47 // TODO(jered): Consider deleting this class and building this functionality |
| 47 // into SearchProvider after dogfood and after we break the association between | 48 // into SearchProvider after dogfood and after we break the association between |
| 48 // omnibox text and suggestions. | 49 // omnibox text and suggestions. |
| 49 class ZeroSuggestProvider : public AutocompleteProvider, | 50 class ZeroSuggestProvider : public AutocompleteProvider, |
| 50 public net::URLFetcherDelegate { | 51 public net::URLFetcherDelegate { |
| 51 public: | 52 public: |
| 52 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 53 // Creates and returns an instance of this provider if the feature is enabled. |
| 53 Profile* profile, | 54 // Returns NULL if not enabled. |
| 54 const std::string& url_prefix); | 55 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, |
| 56 Profile* profile); |
| 57 |
| 58 static void RegisterUserPrefs(PrefService* user_prefs); |
| 55 | 59 |
| 56 // AutocompleteProvider: | 60 // AutocompleteProvider: |
| 57 virtual void Start(const AutocompleteInput& input, | 61 virtual void Start(const AutocompleteInput& input, |
| 58 bool /*minimal_changes*/) OVERRIDE; | 62 bool /*minimal_changes*/) OVERRIDE; |
| 59 virtual void Stop(bool clear_cached_results) OVERRIDE; | 63 virtual void Stop(bool clear_cached_results) OVERRIDE; |
| 60 | 64 |
| 61 // net::URLFetcherDelegate | 65 // net::URLFetcherDelegate |
| 62 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 63 | 67 |
| 64 // Initiates a new fetch for the given |url|, limiting suggestions to those | 68 // Initiates a new fetch for the given |url|, limiting suggestions to those |
| 65 // matching |user_text|. |user_text| may be non-empty if the user previously | 69 // matching |user_text|. |user_text| may be non-empty if the user previously |
| 66 // interacted with zero-suggest suggestions and then unfocused the omnibox. | 70 // interacted with zero-suggest suggestions and then unfocused the omnibox. |
| 67 // TODO(jered): Rip out |user_text| once the first match is decoupled from | 71 // TODO(jered): Rip out |user_text| once the first match is decoupled from |
| 68 // the current typing in the omnibox. | 72 // the current typing in the omnibox. |
| 69 void StartZeroSuggest(const GURL& url, const string16& user_text); | 73 void StartZeroSuggest(const GURL& url, const string16& user_text); |
| 70 | 74 |
| 71 private: | 75 private: |
| 76 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
| 77 Profile* profile, |
| 78 const std::string& url_prefix); |
| 79 |
| 72 virtual ~ZeroSuggestProvider(); | 80 virtual ~ZeroSuggestProvider(); |
| 73 | 81 |
| 74 // Update matches given the user has typed |user_text|. | 82 // Update matches given the user has typed |user_text|. |
| 75 void UpdateMatches(const string16& user_text); | 83 void UpdateMatches(const string16& user_text); |
| 76 | 84 |
| 77 // Fetches zero-suggest suggestions for |current_query_|. | 85 // Fetches zero-suggest suggestions for |current_query_|. |
| 78 void Run(); | 86 void Run(); |
| 79 | 87 |
| 80 // Parses results from the zero-suggest server and updates results. | 88 // Parses results from the zero-suggest server and updates results. |
| 81 // Returns true if results were updated. | 89 // Returns true if results were updated. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 111 // Fetcher used to retrieve results. | 119 // Fetcher used to retrieve results. |
| 112 scoped_ptr<net::URLFetcher> fetcher_; | 120 scoped_ptr<net::URLFetcher> fetcher_; |
| 113 | 121 |
| 114 // Suggestions for the most recent query. | 122 // Suggestions for the most recent query. |
| 115 std::vector<string16> results_; | 123 std::vector<string16> results_; |
| 116 | 124 |
| 117 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 125 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
| 118 }; | 126 }; |
| 119 | 127 |
| 120 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 128 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| OLD | NEW |