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 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // omnibox text and suggestions. | 43 // omnibox text and suggestions. |
44 class ZeroSuggestProvider : public BaseSearchProvider { | 44 class ZeroSuggestProvider : public BaseSearchProvider { |
45 public: | 45 public: |
46 // Creates and returns an instance of this provider. | 46 // Creates and returns an instance of this provider. |
47 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, | 47 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, |
48 Profile* profile); | 48 Profile* profile); |
49 | 49 |
50 // AutocompleteProvider: | 50 // AutocompleteProvider: |
51 virtual void Start(const AutocompleteInput& input, | 51 virtual void Start(const AutocompleteInput& input, |
52 bool /*minimal_changes*/) OVERRIDE; | 52 bool /*minimal_changes*/) OVERRIDE; |
53 virtual void Stop(bool clear_cached_results) OVERRIDE; | |
54 | 53 |
55 // Sets |field_trial_triggered_| to false. | 54 // Sets |field_trial_triggered_| to false. |
56 virtual void ResetSession() OVERRIDE; | 55 virtual void ResetSession() OVERRIDE; |
57 | 56 |
58 // net::URLFetcherDelegate | 57 // net::URLFetcherDelegate |
59 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
60 | 59 |
61 // Initiates a new fetch for the given |url| of classification | 60 // Initiates a new fetch for the given |url| of classification |
62 // |page_classification|. |permanent_text| is the omnibox text | 61 // |page_classification|. |permanent_text| is the omnibox text |
63 // for the current page. | 62 // for the current page. |
64 void StartZeroSuggest( | 63 void StartZeroSuggest( |
65 const GURL& curent_page_url, | 64 const GURL& curent_page_url, |
66 AutocompleteInput::PageClassification page_classification, | 65 AutocompleteInput::PageClassification page_classification, |
67 const base::string16& permanent_text); | 66 const base::string16& permanent_text); |
68 | 67 |
69 private: | 68 private: |
70 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 69 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
71 Profile* profile); | 70 Profile* profile); |
72 | 71 |
73 virtual ~ZeroSuggestProvider(); | 72 virtual ~ZeroSuggestProvider(); |
74 | 73 |
75 // BaseSearchProvider: | 74 // BaseSearchProvider: |
76 virtual const TemplateURL* GetTemplateURL( | 75 virtual const TemplateURL* GetTemplateURL( |
77 const SuggestResult& result) const OVERRIDE; | 76 const SuggestResult& result) const OVERRIDE; |
78 virtual const AutocompleteInput GetInput( | 77 virtual const AutocompleteInput GetInput( |
79 const SuggestResult& result) const OVERRIDE; | 78 const SuggestResult& result) const OVERRIDE; |
80 virtual bool ShouldAppendExtraParams( | 79 virtual bool ShouldAppendExtraParams( |
81 const SuggestResult& result) const OVERRIDE; | 80 const SuggestResult& result) const OVERRIDE; |
| 81 virtual void StopSuggest() OVERRIDE; |
| 82 virtual void ClearAllResults() OVERRIDE; |
82 | 83 |
83 // The 4 functions below (that take classes defined in SearchProvider as | 84 // The 4 functions below (that take classes defined in SearchProvider as |
84 // arguments) were copied and trimmed from SearchProvider. | 85 // arguments) were copied and trimmed from SearchProvider. |
85 // TODO(hfung): Refactor them into a new base class common to both | 86 // TODO(hfung): Refactor them into a new base class common to both |
86 // ZeroSuggestProvider and SearchProvider. | 87 // ZeroSuggestProvider and SearchProvider. |
87 | 88 |
88 // From the OpenSearch formatted response |root_val|, populate query | 89 // From the OpenSearch formatted response |root_val|, populate query |
89 // suggestions into |suggest_results|, navigation suggestions into | 90 // suggestions into |suggest_results|, navigation suggestions into |
90 // |navigation_results|, and the verbatim relevance score into | 91 // |navigation_results|, and the verbatim relevance score into |
91 // |verbatim_relevance|. | 92 // |verbatim_relevance|. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 153 |
153 history::MostVisitedURLList most_visited_urls_; | 154 history::MostVisitedURLList most_visited_urls_; |
154 | 155 |
155 // For callbacks that may be run after destruction. | 156 // For callbacks that may be run after destruction. |
156 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 157 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
157 | 158 |
158 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 159 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
159 }; | 160 }; |
160 | 161 |
161 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 162 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
OLD | NEW |