| 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // *~: Partial matches get a score on a sliding scale from about 575-1125 based | 166 // *~: Partial matches get a score on a sliding scale from about 575-1125 based |
| 167 // on how many times the URL for the Extension App has been typed and how | 167 // on how many times the URL for the Extension App has been typed and how |
| 168 // many of the letters match. | 168 // many of the letters match. |
| 169 // | 169 // |
| 170 // A single result provider for the autocomplete system. Given user input, the | 170 // A single result provider for the autocomplete system. Given user input, the |
| 171 // provider decides what (if any) matches to return, their relevance, and their | 171 // provider decides what (if any) matches to return, their relevance, and their |
| 172 // classifications. | 172 // classifications. |
| 173 class AutocompleteProvider | 173 class AutocompleteProvider |
| 174 : public base::RefCountedThreadSafe<AutocompleteProvider> { | 174 : public base::RefCountedThreadSafe<AutocompleteProvider> { |
| 175 public: | 175 public: |
| 176 // Different AutocompleteProvider implementations. |
| 177 enum Type { |
| 178 TYPE_BUILTIN = 1 << 0, |
| 179 TYPE_EXTENSION_APP = 1 << 1, |
| 180 TYPE_HISTORY_CONTENTS = 1 << 2, |
| 181 TYPE_HISTORY_QUICK = 1 << 3, |
| 182 TYPE_HISTORY_URL = 1 << 4, |
| 183 TYPE_KEYWORD = 1 << 5, |
| 184 TYPE_SEARCH = 1 << 6, |
| 185 TYPE_SHORTCUTS = 1 << 7, |
| 186 TYPE_ZERO_SUGGEST = 1 << 8, |
| 187 }; |
| 176 | 188 |
| 177 AutocompleteProvider(AutocompleteProviderListener* listener, | 189 AutocompleteProvider(AutocompleteProviderListener* listener, |
| 178 Profile* profile, | 190 Profile* profile, |
| 179 const char* name); | 191 Type type); |
| 192 |
| 193 // Returns a string describing a particular AutocompleteProvider type. |
| 194 static const char* TypeToString(Type type); |
| 180 | 195 |
| 181 // Called to start an autocomplete query. The provider is responsible for | 196 // Called to start an autocomplete query. The provider is responsible for |
| 182 // tracking its matches for this query and whether it is done processing the | 197 // tracking its matches for this query and whether it is done processing the |
| 183 // query. When new matches are available or the provider finishes, it | 198 // query. When new matches are available or the provider finishes, it |
| 184 // calls the controller's OnProviderUpdate() method. The controller can then | 199 // calls the controller's OnProviderUpdate() method. The controller can then |
| 185 // get the new matches using the provider's accessors. | 200 // get the new matches using the provider's accessors. |
| 186 // Exception: Matches available immediately after starting the query (that | 201 // Exception: Matches available immediately after starting the query (that |
| 187 // is, synchronously) do not cause any notifications to be sent. The | 202 // is, synchronously) do not cause any notifications to be sent. The |
| 188 // controller is expected to check for these without prompting (since | 203 // controller is expected to check for these without prompting (since |
| 189 // otherwise, starting each provider running would result in a flurry of | 204 // otherwise, starting each provider running would result in a flurry of |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 // done. If the provider caches any results, it should clear the cache based | 216 // done. If the provider caches any results, it should clear the cache based |
| 202 // on the value of |clear_cached_results|. | 217 // on the value of |clear_cached_results|. |
| 203 virtual void Stop(bool clear_cached_results); | 218 virtual void Stop(bool clear_cached_results); |
| 204 | 219 |
| 205 // Returns the set of matches for the current query. | 220 // Returns the set of matches for the current query. |
| 206 const ACMatches& matches() const { return matches_; } | 221 const ACMatches& matches() const { return matches_; } |
| 207 | 222 |
| 208 // Returns whether the provider is done processing the query. | 223 // Returns whether the provider is done processing the query. |
| 209 bool done() const { return done_; } | 224 bool done() const { return done_; } |
| 210 | 225 |
| 211 // Returns the name of this provider. | 226 // Returns this provider's type. |
| 212 const std::string& name() const { return name_; } | 227 Type type() const { return type_; } |
| 228 |
| 229 // Returns a string describing this provider's type. |
| 230 const char* GetName() const; |
| 213 | 231 |
| 214 // Returns the enum equivalent to the name of this provider. | 232 // Returns the enum equivalent to the name of this provider. |
| 233 // TODO(derat): Make metrics use AutocompleteProvider::Type directly, or at |
| 234 // least move this method to the metrics directory. |
| 215 metrics::OmniboxEventProto_ProviderType AsOmniboxEventProviderType() const; | 235 metrics::OmniboxEventProto_ProviderType AsOmniboxEventProviderType() const; |
| 216 | 236 |
| 217 // Called to delete a match and the backing data that produced it. This | 237 // Called to delete a match and the backing data that produced it. This |
| 218 // match should not appear again in this or future queries. This can only be | 238 // match should not appear again in this or future queries. This can only be |
| 219 // called for matches the provider marks as deletable. This should only be | 239 // called for matches the provider marks as deletable. This should only be |
| 220 // called when no query is running. | 240 // called when no query is running. |
| 221 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. | 241 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. |
| 222 virtual void DeleteMatch(const AutocompleteMatch& match); | 242 virtual void DeleteMatch(const AutocompleteMatch& match); |
| 223 | 243 |
| 224 // Called when an omnibox event log entry is generated. This gives | 244 // Called when an omnibox event log entry is generated. This gives |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 void UpdateStarredStateOfMatches(); | 278 void UpdateStarredStateOfMatches(); |
| 259 | 279 |
| 260 // The profile associated with the AutocompleteProvider. Reference is not | 280 // The profile associated with the AutocompleteProvider. Reference is not |
| 261 // owned by us. | 281 // owned by us. |
| 262 Profile* profile_; | 282 Profile* profile_; |
| 263 | 283 |
| 264 AutocompleteProviderListener* listener_; | 284 AutocompleteProviderListener* listener_; |
| 265 ACMatches matches_; | 285 ACMatches matches_; |
| 266 bool done_; | 286 bool done_; |
| 267 | 287 |
| 268 // The name of this provider. Used for logging. | 288 Type type_; |
| 269 std::string name_; | |
| 270 | 289 |
| 271 private: | 290 private: |
| 272 DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider); | 291 DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider); |
| 273 }; | 292 }; |
| 274 | 293 |
| 275 typedef std::vector<AutocompleteProvider*> ACProviders; | 294 typedef std::vector<AutocompleteProvider*> ACProviders; |
| 276 | 295 |
| 277 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ | 296 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_PROVIDER_H_ |
| OLD | NEW |