OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ | 5 #ifndef COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ |
6 #define COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ | 6 #define COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // tracking its matches for this query and whether it is done processing the | 144 // tracking its matches for this query and whether it is done processing the |
145 // query. When new matches are available or the provider finishes, it | 145 // query. When new matches are available or the provider finishes, it |
146 // calls the controller's OnProviderUpdate() method. The controller can then | 146 // calls the controller's OnProviderUpdate() method. The controller can then |
147 // get the new matches using the provider's accessors. | 147 // get the new matches using the provider's accessors. |
148 // Exception: Matches available immediately after starting the query (that | 148 // Exception: Matches available immediately after starting the query (that |
149 // is, synchronously) do not cause any notifications to be sent. The | 149 // is, synchronously) do not cause any notifications to be sent. The |
150 // controller is expected to check for these without prompting (since | 150 // controller is expected to check for these without prompting (since |
151 // otherwise, starting each provider running would result in a flurry of | 151 // otherwise, starting each provider running would result in a flurry of |
152 // notifications). | 152 // notifications). |
153 // | 153 // |
154 // Once Stop() has been called, no more notifications should be sent. | 154 // Once Stop() has been called, usually no more notifications should be sent. |
| 155 // (See comments on Stop() below.) |
155 // | 156 // |
156 // |minimal_changes| is an optimization that lets the provider do less work | 157 // |minimal_changes| is an optimization that lets the provider do less work |
157 // when the |input|'s text hasn't changed. See the body of | 158 // when the |input|'s text hasn't changed. See the body of |
158 // OmniboxPopupModel::StartAutocomplete(). | 159 // OmniboxPopupModel::StartAutocomplete(). |
159 // | 160 // |
160 // |called_due_to_focus| is true when Start() is being called in response to | 161 // |called_due_to_focus| is true when Start() is being called in response to |
161 // the omnibox being focused, instead of due to e.g. user input changes. Most | 162 // the omnibox being focused, instead of due to e.g. user input changes. Most |
162 // providers should not provide matches in this case. Providers which want to | 163 // providers should not provide matches in this case. Providers which want to |
163 // display matches on focus can use this flag to know when they can do so. | 164 // display matches on focus can use this flag to know when they can do so. |
164 virtual void Start(const AutocompleteInput& input, | 165 virtual void Start(const AutocompleteInput& input, |
165 bool minimal_changes, | 166 bool minimal_changes, |
166 bool called_due_to_focus) = 0; | 167 bool called_due_to_focus) = 0; |
167 | 168 |
168 // Called when a provider must not make any more callbacks for the current | 169 // Advises the provider to stop processing. This may be called even if the |
169 // query. This will be called regardless of whether the provider is already | 170 // provider is already done. If the provider caches any results, it should |
170 // done. If the provider caches any results, it should clear the cache based | 171 // clear the cache based on the value of |clear_cached_results|. Normally, |
171 // on the value of |clear_cached_results|. | 172 // once this is called, the provider should not send more notifications to |
172 virtual void Stop(bool clear_cached_results); | 173 // the controller. |
| 174 // |
| 175 // If |user_inactivity_timer| is true, Stop() is being called because it's |
| 176 // been a long time since the user started the current query, and returning |
| 177 // further asynchronous results would normally just be disruptive. Most |
| 178 // providers should still stop processing in this case, but continuing is |
| 179 // legal if there's a good reason the user is likely to want even long- |
| 180 // delayed asynchronous results, e.g. the user has explicitly invoked a |
| 181 // keyword extension and the extension is still processing the request. |
| 182 virtual void Stop(bool clear_cached_results, |
| 183 bool due_to_user_inactivity); |
173 | 184 |
174 // Returns the enum equivalent to the name of this provider. | 185 // Returns the enum equivalent to the name of this provider. |
175 // TODO(derat): Make metrics use AutocompleteProvider::Type directly, or at | 186 // TODO(derat): Make metrics use AutocompleteProvider::Type directly, or at |
176 // least move this method to the metrics directory. | 187 // least move this method to the metrics directory. |
177 metrics::OmniboxEventProto_ProviderType AsOmniboxEventProviderType() const; | 188 metrics::OmniboxEventProto_ProviderType AsOmniboxEventProviderType() const; |
178 | 189 |
179 // Called to delete a match and the backing data that produced it. This | 190 // Called to delete a match and the backing data that produced it. This |
180 // match should not appear again in this or future queries. This can only be | 191 // match should not appear again in this or future queries. This can only be |
181 // called for matches the provider marks as deletable. This should only be | 192 // called for matches the provider marks as deletable. This should only be |
182 // called when no query is running. | 193 // called when no query is running. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 ACMatches matches_; | 257 ACMatches matches_; |
247 bool done_; | 258 bool done_; |
248 | 259 |
249 Type type_; | 260 Type type_; |
250 | 261 |
251 private: | 262 private: |
252 DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider); | 263 DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider); |
253 }; | 264 }; |
254 | 265 |
255 #endif // COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ | 266 #endif // COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_ |
OLD | NEW |