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

Side by Side Diff: chrome/browser/instant/instant_controller.h

Issue 10879043: Centralize logic around Instant modes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a few more style nits 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_INSTANT_INSTANT_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_
6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // invoked on the delegate. 43 // invoked on the delegate.
44 class InstantController : public InstantLoaderDelegate { 44 class InstantController : public InstantLoaderDelegate {
45 public: 45 public:
46 // Amount of time to wait before starting the animation for suggested text. 46 // Amount of time to wait before starting the animation for suggested text.
47 static const int kInlineAutocompletePauseTimeMS = 1000; 47 static const int kInlineAutocompletePauseTimeMS = 1000;
48 48
49 // Duration of the suggested text animation in which the colors change. 49 // Duration of the suggested text animation in which the colors change.
50 static const int kInlineAutocompleteFadeInTimeMS = 300; 50 static const int kInlineAutocompleteFadeInTimeMS = 300;
51 51
52 // InstantController may operate in one of these modes: 52 // InstantController may operate in one of these modes:
53 // INSTANT: The default search engine is preloaded when the omnibox gets 53 // EXTENDED: The default search engine is preloaded when the omnibox gets
54 // focus. Queries are issued as the user types. Predicted queries are 54 // focus. Queries are issued as the user types. Predicted queries are
55 // inline autocompleted into the omnibox. Result previews are shown. 55 // inline autocompleted into the omnibox. Previews of search results
56 // as well as predicted URLs are shown. Search suggestions are rendered
57 // within the search results preview.
58 // INSTANT: Same as EXTENDED, without URL previews. Search suggestions are
59 // rendered by the omnibox drop down, and not by the preview page.
56 // SUGGEST: Same as INSTANT, without visible previews. 60 // SUGGEST: Same as INSTANT, without visible previews.
57 // HIDDEN: Same as SUGGEST, without the inline autocompletion. 61 // HIDDEN: Same as SUGGEST, without the inline autocompletion.
58 // SILENT: Same as HIDDEN, without issuing queries as the user types. The 62 // SILENT: Same as HIDDEN, without issuing queries as the user types. The
59 // query is sent only after the user presses <Enter>. 63 // query is sent only after the user presses <Enter>.
60 // EXTENDED: Similar to INSTANT, but with extended functionality, such as 64 // DISABLED: Instant is disabled.
61 // rendering suggestions within the preview and previews of URLs.
62 enum Mode { 65 enum Mode {
66 EXTENDED,
63 INSTANT, 67 INSTANT,
64 SUGGEST, 68 SUGGEST,
65 HIDDEN, 69 HIDDEN,
66 SILENT, 70 SILENT,
67 EXTENDED, 71 DISABLED,
68 }; 72 };
69 73
70 InstantController(InstantControllerDelegate* delegate, Mode mode);
71 virtual ~InstantController(); 74 virtual ~InstantController();
72 75
76 // Creates a new InstantController. Caller owns the returned object. The
77 // |profile| pointer is not cached, so the underlying profile object need not
78 // live beyond this call. ***NOTE***: May return NULL, which means that
79 // Instant is disabled in this profile.
80 static InstantController* CreateInstant(Profile* profile,
81 InstantControllerDelegate* delegate);
82
83 // Returns true if Instant is enabled and supports the extended API.
84 static bool IsExtendedAPIEnabled(Profile* profile);
85
86 // Returns true if Instant is enabled in a visible, preview-showing mode.
87 static bool IsInstantEnabled(Profile* profile);
88
89 // Returns true if Instant will provide autocomplete suggestions.
90 static bool IsSuggestEnabled(Profile* profile);
91
73 // Registers Instant related preferences. 92 // Registers Instant related preferences.
74 static void RegisterUserPrefs(PrefService* prefs); 93 static void RegisterUserPrefs(PrefService* prefs);
75 94
76 // Returns true if Instant is enabled for the given |profile|.
77 static bool IsEnabled(Profile* profile);
78
79 // Invoked as the user types into the omnibox. |user_text| is what the user 95 // Invoked as the user types into the omnibox. |user_text| is what the user
80 // has typed. |full_text| is what the omnibox is showing. These may differ if 96 // has typed. |full_text| is what the omnibox is showing. These may differ if
81 // the user typed only some text, and the rest was inline autocompleted. If 97 // the user typed only some text, and the rest was inline autocompleted. If
82 // |verbatim| is true, search results are shown for the exact omnibox text, 98 // |verbatim| is true, search results are shown for the exact omnibox text,
83 // rather than the best guess as to what the user means. Returns true if the 99 // rather than the best guess as to what the user means. Returns true if the
84 // update is accepted (i.e., if |match| is a search rather than a URL). 100 // update is accepted (i.e., if |match| is a search rather than a URL).
85 bool Update(const AutocompleteMatch& match, 101 bool Update(const AutocompleteMatch& match,
86 const string16& user_text, 102 const string16& user_text,
87 const string16& full_text, 103 const string16& full_text,
88 bool verbatim); 104 bool verbatim);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 164
149 #if defined(UNIT_TEST) 165 #if defined(UNIT_TEST)
150 // Accessors used only in tests. 166 // Accessors used only in tests.
151 bool is_showing() const { return is_showing_; } 167 bool is_showing() const { return is_showing_; }
152 InstantLoader* loader() const { return loader_.get(); } 168 InstantLoader* loader() const { return loader_.get(); }
153 #endif 169 #endif
154 170
155 private: 171 private:
156 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); 172 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh);
157 173
174 InstantController(InstantControllerDelegate* delegate, Mode mode);
175
158 // Creates a new loader if necessary (for example, if the |instant_url| has 176 // Creates a new loader if necessary (for example, if the |instant_url| has
159 // changed since the last time we created the loader). 177 // changed since the last time we created the loader).
160 void ResetLoader(const std::string& instant_url, 178 void ResetLoader(const std::string& instant_url,
161 const TabContents* active_tab); 179 const TabContents* active_tab);
162 180
163 // Ensures that the |loader_| uses the default Instant URL, recreating it if 181 // Ensures that the |loader_| uses the default Instant URL, recreating it if
164 // necessary. Will not do anything if the Instant URL could not be determined 182 // necessary. Will not do anything if the Instant URL could not be determined
165 // or the active tab is NULL (browser is shutting down). 183 // or the active tab is NULL (browser is shutting down).
166 void CreateDefaultLoader(); 184 void CreateDefaultLoader();
167 185
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // Search terms extraction (for autocomplete history matches) doesn't work 269 // Search terms extraction (for autocomplete history matches) doesn't work
252 // on Instant URLs. So, whenever the user commits an Instant search, we add 270 // on Instant URLs. So, whenever the user commits an Instant search, we add
253 // an equivalent non-Instant search URL to history, so that the search shows 271 // an equivalent non-Instant search URL to history, so that the search shows
254 // up in autocomplete history matches. 272 // up in autocomplete history matches.
255 GURL url_for_history_; 273 GURL url_for_history_;
256 274
257 DISALLOW_COPY_AND_ASSIGN(InstantController); 275 DISALLOW_COPY_AND_ASSIGN(InstantController);
258 }; 276 };
259 277
260 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ 278 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | chrome/browser/instant/instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698