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_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 14 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
16 #include "chrome/browser/autocomplete/autocomplete_result.h" | 16 #include "chrome/browser/autocomplete/autocomplete_result.h" |
17 #include "components/autocomplete/autocomplete_input.h" | 17 #include "components/autocomplete/autocomplete_input.h" |
18 | 18 |
19 class AutocompleteControllerDelegate; | 19 class AutocompleteControllerDelegate; |
20 class HistoryURLProvider; | 20 class HistoryURLProvider; |
21 class KeywordProvider; | 21 class KeywordProvider; |
22 class Profile; | 22 class Profile; |
23 class SearchProvider; | 23 class SearchProvider; |
24 class TemplateURLService; | |
25 class ZeroSuggestProvider; | 24 class ZeroSuggestProvider; |
26 | 25 |
27 // The AutocompleteController is the center of the autocomplete system. A | 26 // The AutocompleteController is the center of the autocomplete system. A |
28 // class creates an instance of the controller, which in turn creates a set of | 27 // class creates an instance of the controller, which in turn creates a set of |
29 // AutocompleteProviders to serve it. The owning class can ask the controller | 28 // AutocompleteProviders to serve it. The owning class can ask the controller |
30 // to Start() a query; the controller in turn passes this call down to the | 29 // to Start() a query; the controller in turn passes this call down to the |
31 // providers, each of which keeps track of its own matches and whether it has | 30 // providers, each of which keeps track of its own matches and whether it has |
32 // finished processing the query. When a provider gets more matches or finishes | 31 // finished processing the query. When a provider gets more matches or finishes |
33 // processing, it notifies the controller, which merges the combined matches | 32 // processing, it notifies the controller, which merges the combined matches |
34 // together and makes the result available to interested observers. | 33 // together and makes the result available to interested observers. |
35 // | 34 // |
36 // The owner may also cancel the current query by calling Stop(), which the | 35 // The owner may also cancel the current query by calling Stop(), which the |
37 // controller will in turn communicate to all the providers. No callbacks will | 36 // controller will in turn communicate to all the providers. No callbacks will |
38 // happen after a request has been stopped. | 37 // happen after a request has been stopped. |
39 // | 38 // |
40 // IMPORTANT: There is NO THREAD SAFETY built into this portion of the | 39 // IMPORTANT: There is NO THREAD SAFETY built into this portion of the |
41 // autocomplete system. All calls to and from the AutocompleteController should | 40 // autocomplete system. All calls to and from the AutocompleteController should |
42 // happen on the same thread. AutocompleteProviders are responsible for doing | 41 // happen on the same thread. AutocompleteProviders are responsible for doing |
43 // their own thread management when they need to return matches asynchronously. | 42 // their own thread management when they need to return matches asynchronously. |
44 // | 43 // |
45 // The coordinator for autocomplete queries, responsible for combining the | 44 // The coordinator for autocomplete queries, responsible for combining the |
46 // matches from a series of providers into one AutocompleteResult. | 45 // matches from a series of providers into one AutocompleteResult. |
47 class AutocompleteController : public AutocompleteProviderListener { | 46 class AutocompleteController : public AutocompleteProviderListener { |
48 public: | 47 public: |
49 // |provider_types| is a bitmap containing AutocompleteProvider::Type values | 48 // |provider_types| is a bitmap containing AutocompleteProvider::Type values |
50 // that will (potentially, depending on platform, flags, etc.) be | 49 // that will (potentially, depending on platform, flags, etc.) be |
51 // instantiated. |template_url_service| is used to create URLs from the | 50 // instantiated. |
52 // autocomplete results. | |
53 AutocompleteController(Profile* profile, | 51 AutocompleteController(Profile* profile, |
54 TemplateURLService* template_url_service, | |
55 AutocompleteControllerDelegate* delegate, | 52 AutocompleteControllerDelegate* delegate, |
56 int provider_types); | 53 int provider_types); |
57 ~AutocompleteController(); | 54 ~AutocompleteController(); |
58 | 55 |
59 // Starts an autocomplete query, which continues until all providers are | 56 // Starts an autocomplete query, which continues until all providers are |
60 // done or the query is Stop()ed. It is safe to Start() a new query without | 57 // done or the query is Stop()ed. It is safe to Start() a new query without |
61 // Stop()ing the previous one. | 58 // Stop()ing the previous one. |
62 // | 59 // |
63 // See AutocompleteInput::AutocompleteInput(...) for more details regarding | 60 // See AutocompleteInput::AutocompleteInput(...) for more details regarding |
64 // |input| params. | 61 // |input| params. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // and doesn't expect it to change. | 230 // and doesn't expect it to change. |
234 const base::TimeDelta stop_timer_duration_; | 231 const base::TimeDelta stop_timer_duration_; |
235 | 232 |
236 // True if a query is not currently running. | 233 // True if a query is not currently running. |
237 bool done_; | 234 bool done_; |
238 | 235 |
239 // Are we in Start()? This is used to avoid updating |result_| and sending | 236 // Are we in Start()? This is used to avoid updating |result_| and sending |
240 // notifications until Start() has been invoked on all providers. | 237 // notifications until Start() has been invoked on all providers. |
241 bool in_start_; | 238 bool in_start_; |
242 | 239 |
243 TemplateURLService* template_url_service_; | 240 Profile* profile_; |
244 | 241 |
245 DISALLOW_COPY_AND_ASSIGN(AutocompleteController); | 242 DISALLOW_COPY_AND_ASSIGN(AutocompleteController); |
246 }; | 243 }; |
247 | 244 |
248 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ | 245 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ |
OLD | NEW |