Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_controller.h

Issue 10909130: autocomplete: Add AutocompleteProvider::Type enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix inadvertently-change parameter in test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string16.h" 11 #include "base/string16.h"
12 #include "base/timer.h" 12 #include "base/timer.h"
13 #include "chrome/browser/autocomplete/autocomplete_input.h" 13 #include "chrome/browser/autocomplete/autocomplete_input.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 "chrome/browser/autocomplete/keyword_provider.h"
18 #include "chrome/browser/autocomplete/search_provider.h"
17 19
18 class AutocompleteControllerDelegate; 20 class AutocompleteControllerDelegate;
19 class KeywordProvider;
20 class Profile; 21 class Profile;
21 class SearchProvider;
22 class ZeroSuggestProvider; 22 class ZeroSuggestProvider;
23 23
24 // The AutocompleteController is the center of the autocomplete system. A 24 // The AutocompleteController is the center of the autocomplete system. A
25 // class creates an instance of the controller, which in turn creates a set of 25 // class creates an instance of the controller, which in turn creates a set of
26 // AutocompleteProviders to serve it. The owning class can ask the controller 26 // AutocompleteProviders to serve it. The owning class can ask the controller
27 // to Start() a query; the controller in turn passes this call down to the 27 // to Start() a query; the controller in turn passes this call down to the
28 // providers, each of which keeps track of its own matches and whether it has 28 // providers, each of which keeps track of its own matches and whether it has
29 // finished processing the query. When a provider gets more matches or finishes 29 // finished processing the query. When a provider gets more matches or finishes
30 // processing, it notifies the controller, which merges the combined matches 30 // processing, it notifies the controller, which merges the combined matches
31 // together and makes the result available to interested observers. 31 // together and makes the result available to interested observers.
(...skipping 11 matching lines...) Expand all
43 // matches from a series of providers into one AutocompleteResult. 43 // matches from a series of providers into one AutocompleteResult.
44 class AutocompleteController : public AutocompleteProviderListener { 44 class AutocompleteController : public AutocompleteProviderListener {
45 public: 45 public:
46 // Used to indicate an index that is not selected in a call to Update(). 46 // Used to indicate an index that is not selected in a call to Update().
47 static const int kNoItemSelected; 47 static const int kNoItemSelected;
48 48
49 // Normally, you will call the first constructor. Unit tests can use the 49 // Normally, you will call the first constructor. Unit tests can use the
50 // second to set the providers to some known testing providers. The default 50 // second to set the providers to some known testing providers. The default
51 // providers will be overridden and the controller will take ownership of the 51 // providers will be overridden and the controller will take ownership of the
52 // providers, Release()ing them on destruction. 52 // providers, Release()ing them on destruction.
53 //
54 // |provider_types| is a bitmap containing AutocompleteProvider::Type values
55 // that will (potentially, depending on platform, flags, etc.) be
56 // instantiated.
53 AutocompleteController(Profile* profile, 57 AutocompleteController(Profile* profile,
54 AutocompleteControllerDelegate* delegate); 58 AutocompleteControllerDelegate* delegate,
59 int provider_types);
55 #ifdef UNIT_TEST 60 #ifdef UNIT_TEST
56 AutocompleteController(const ACProviders& providers, Profile* profile) 61 AutocompleteController(const ACProviders& providers, Profile* profile)
57 : delegate_(NULL), 62 : delegate_(NULL),
58 providers_(providers), 63 providers_(providers),
59 keyword_provider_(NULL), 64 keyword_provider_(NULL),
60 search_provider_(NULL), 65 search_provider_(NULL),
66 zero_suggest_provider_(NULL),
61 done_(true), 67 done_(true),
62 in_start_(false), 68 in_start_(false),
69 in_zero_suggest_(false),
63 profile_(profile) { 70 profile_(profile) {
71 for (ACProviders::iterator it = providers_.begin();
Daniel Erat 2012/09/11 01:33:08 It looks like I can remove this loop now, too.
Peter Kasting 2012/09/11 01:38:42 Yep, but I think you can kill this constructor ent
Daniel Erat 2012/09/11 02:09:22 Done.
72 it != providers_.end(); ++it) {
73 if ((*it)->type() == AutocompleteProvider::TYPE_SEARCH)
74 search_provider_ = static_cast<SearchProvider*>(*it);
75 else if ((*it)->type() == AutocompleteProvider::TYPE_KEYWORD)
76 keyword_provider_ = static_cast<KeywordProvider*>(*it);
77 }
64 } 78 }
65 #endif 79 #endif
66 ~AutocompleteController(); 80 ~AutocompleteController();
67 81
68 // Starts an autocomplete query, which continues until all providers are 82 // Starts an autocomplete query, which continues until all providers are
69 // done or the query is Stop()ed. It is safe to Start() a new query without 83 // done or the query is Stop()ed. It is safe to Start() a new query without
70 // Stop()ing the previous one. 84 // Stop()ing the previous one.
71 // 85 //
72 // See AutocompleteInput::desired_tld() for meaning of |desired_tld|. 86 // See AutocompleteInput::desired_tld() for meaning of |desired_tld|.
73 // 87 //
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 135
122 // Asks the relevant provider to delete |match|, and ensures observers are 136 // Asks the relevant provider to delete |match|, and ensures observers are
123 // notified of resulting changes immediately. This should only be called when 137 // notified of resulting changes immediately. This should only be called when
124 // no query is running. 138 // no query is running.
125 void DeleteMatch(const AutocompleteMatch& match); 139 void DeleteMatch(const AutocompleteMatch& match);
126 140
127 // Removes any entries that were copied from the last result. This is used by 141 // Removes any entries that were copied from the last result. This is used by
128 // the popup to ensure it's not showing an out-of-date query. 142 // the popup to ensure it's not showing an out-of-date query.
129 void ExpireCopiedEntries(); 143 void ExpireCopiedEntries();
130 144
131 #ifdef UNIT_TEST
132 void set_search_provider(SearchProvider* provider) {
133 search_provider_ = provider;
134 }
135 void set_keyword_provider(KeywordProvider* provider) {
136 keyword_provider_ = provider;
137 }
138 #endif
139 SearchProvider* search_provider() const { return search_provider_; } 145 SearchProvider* search_provider() const { return search_provider_; }
140 KeywordProvider* keyword_provider() const { return keyword_provider_; } 146 KeywordProvider* keyword_provider() const { return keyword_provider_; }
141 147
142 const AutocompleteInput& input() const { return input_; } 148 const AutocompleteInput& input() const { return input_; }
143 const AutocompleteResult& result() const { return result_; } 149 const AutocompleteResult& result() const { return result_; }
144 bool done() const { return done_; } 150 bool done() const { return done_; }
145 const ACProviders* providers() const { return &providers_; } 151 const ACProviders* providers() const { return &providers_; }
146 152
147 // AutocompleteProviderListener: 153 // AutocompleteProviderListener:
148 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; 154 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 226
221 // Has StartZeroSuggest() been called but not Start()? 227 // Has StartZeroSuggest() been called but not Start()?
222 bool in_zero_suggest_; 228 bool in_zero_suggest_;
223 229
224 Profile* profile_; 230 Profile* profile_;
225 231
226 DISALLOW_COPY_AND_ASSIGN(AutocompleteController); 232 DISALLOW_COPY_AND_ASSIGN(AutocompleteController);
227 }; 233 };
228 234
229 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_ 235 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698