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_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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/timer.h" | 17 #include "base/timer.h" |
17 #include "chrome/browser/instant/instant_commit_type.h" | 18 #include "chrome/browser/instant/instant_commit_type.h" |
18 #include "chrome/browser/instant/instant_loader_delegate.h" | 19 #include "chrome/browser/instant/instant_loader_delegate.h" |
19 #include "chrome/common/instant_types.h" | 20 #include "chrome/common/instant_types.h" |
20 #include "content/public/common/page_transition_types.h" | 21 #include "content/public/common/page_transition_types.h" |
21 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
22 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE; | 139 virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE; |
139 virtual void InstantLoaderContentsFocused(InstantLoader* loader) OVERRIDE; | 140 virtual void InstantLoaderContentsFocused(InstantLoader* loader) OVERRIDE; |
140 | 141 |
141 #if defined(UNIT_TEST) | 142 #if defined(UNIT_TEST) |
142 // Accessors used only in tests. | 143 // Accessors used only in tests. |
143 bool is_showing() const { return is_showing_; } | 144 bool is_showing() const { return is_showing_; } |
144 InstantLoader* loader() const { return loader_.get(); } | 145 InstantLoader* loader() const { return loader_.get(); } |
145 #endif | 146 #endif |
146 | 147 |
147 private: | 148 private: |
149 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | |
150 | |
151 // Creates a new loader with the provided |instant_url| on the |active_tab|. | |
152 // Will also start the |loader_refresh_timer_|. The |loader_| should have been | |
153 // deleted before making this call. | |
154 void CreateLoader(const std::string& instant_url, | |
155 const TabContents* active_tab); | |
156 | |
148 // Creates a new loader if necessary (for example, if the |instant_url| has | 157 // Creates a new loader if necessary (for example, if the |instant_url| has |
149 // changed since the last time we created the loader). | 158 // changed since the last time we created the loader). |
150 void ResetLoader(const std::string& instant_url, | 159 void ResetLoader(const std::string& instant_url, |
151 const TabContents* active_tab); | 160 const TabContents* active_tab); |
152 | 161 |
162 // Ensures that the |loader_| uses the default instant url, recreating it if | |
sreeram
2012/08/22 17:39:35
instant url -> Instant URL
Shishir
2012/08/23 18:26:33
Done.
| |
163 // necessary. Uses the current tab if the |loader_| needs to be recreated. | |
sreeram
2012/08/22 17:39:35
You can lose this part ("Uses the current tab ...
Shishir
2012/08/23 18:26:33
Done.
| |
164 // Will not do anything if the instant url could not be determined or the | |
sreeram
2012/08/22 17:39:35
instant url -> Instant URL
Shishir
2012/08/23 18:26:33
Done.
| |
165 // active tab is NULL (browser is shutting down). | |
166 void ResetLoaderWithDefaultUrlAndCurrentTab(); | |
sreeram
2012/08/22 17:39:35
Rename this to CreateDefaultLoader().
Shishir
2012/08/23 18:26:33
Done, but note that this need not create the loade
| |
167 | |
168 // Starts / restarts the |loader_refresh_timer_| to refresh interval from now. | |
169 void ScheduleLoaderRefresh(); | |
sreeram
2012/08/22 17:39:35
Rename to ResetStaleLoaderTimer?
Shishir
2012/08/23 18:26:33
Done.
| |
170 | |
171 // If the |loader_| is not showing, it is deleted and recreated. Else the | |
172 // refresh is skipped and the next refresh is scheduled. | |
173 void RefreshLoader(); | |
sreeram
2012/08/22 17:39:35
Call this OnStaleLoader?
Shishir
2012/08/23 18:26:33
Done.
| |
174 | |
153 // Destroys the |loader_| and its preview contents. | 175 // Destroys the |loader_| and its preview contents. |
154 void DeleteLoader(); | 176 void DeleteLoader(); |
155 | 177 |
156 // Counterpart to Hide(). Asks the |delegate_| to display the preview. | 178 // Counterpart to Hide(). Asks the |delegate_| to display the preview. |
157 void Show(); | 179 void Show(); |
158 | 180 |
159 // Send the omnibox dropdown bounds to the page. | 181 // Send the omnibox dropdown bounds to the page. |
160 void SendBoundsToPage(); | 182 void SendBoundsToPage(); |
161 | 183 |
162 // If |template_url| is a valid TemplateURL for use with Instant, fills in | 184 // If |template_url| is a valid TemplateURL for use with Instant, fills in |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 233 |
212 // Current omnibox bounds. | 234 // Current omnibox bounds. |
213 gfx::Rect omnibox_bounds_; | 235 gfx::Rect omnibox_bounds_; |
214 | 236 |
215 // Last bounds passed to the page. | 237 // Last bounds passed to the page. |
216 gfx::Rect last_omnibox_bounds_; | 238 gfx::Rect last_omnibox_bounds_; |
217 | 239 |
218 // Timer used to update the bounds of the omnibox. | 240 // Timer used to update the bounds of the omnibox. |
219 base::OneShotTimer<InstantController> update_bounds_timer_; | 241 base::OneShotTimer<InstantController> update_bounds_timer_; |
220 | 242 |
243 // Timer used to ensure that the Instant page does not get too stale. | |
244 base::OneShotTimer<InstantController> loader_refresh_timer_; | |
sreeram
2012/08/22 17:39:35
Call this stale_loader_timer_?
Shishir
2012/08/23 18:26:33
Done.
| |
245 | |
221 // For each key K => value N, the map says that we found that the search | 246 // For each key K => value N, the map says that we found that the search |
222 // engine identified by Instant URL K didn't support the Instant API in each | 247 // engine identified by Instant URL K didn't support the Instant API in each |
223 // of the last N times that we loaded it. If an Instant URL isn't present in | 248 // of the last N times that we loaded it. If an Instant URL isn't present in |
224 // the map at all or has a value 0, it means that search engine supports the | 249 // the map at all or has a value 0, it means that search engine supports the |
225 // Instant API (or we assume it does, since we haven't determined it doesn't). | 250 // Instant API (or we assume it does, since we haven't determined it doesn't). |
226 std::map<std::string, int> blacklisted_urls_; | 251 std::map<std::string, int> blacklisted_urls_; |
227 | 252 |
228 // Search terms extraction (for autocomplete history matches) doesn't work | 253 // Search terms extraction (for autocomplete history matches) doesn't work |
229 // on Instant URLs. So, whenever the user commits an Instant search, we add | 254 // on Instant URLs. So, whenever the user commits an Instant search, we add |
230 // an equivalent non-Instant search URL to history, so that the search shows | 255 // an equivalent non-Instant search URL to history, so that the search shows |
231 // up in autocomplete history matches. | 256 // up in autocomplete history matches. |
232 GURL url_for_history_; | 257 GURL url_for_history_; |
233 | 258 |
234 DISALLOW_COPY_AND_ASSIGN(InstantController); | 259 DISALLOW_COPY_AND_ASSIGN(InstantController); |
235 }; | 260 }; |
236 | 261 |
237 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 262 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
OLD | NEW |