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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE; | 147 virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE; |
147 virtual void InstantLoaderContentsFocused(InstantLoader* loader) OVERRIDE; | 148 virtual void InstantLoaderContentsFocused(InstantLoader* loader) OVERRIDE; |
148 | 149 |
149 #if defined(UNIT_TEST) | 150 #if defined(UNIT_TEST) |
150 // Accessors used only in tests. | 151 // Accessors used only in tests. |
151 bool is_showing() const { return is_showing_; } | 152 bool is_showing() const { return is_showing_; } |
152 InstantLoader* loader() const { return loader_.get(); } | 153 InstantLoader* loader() const { return loader_.get(); } |
153 #endif | 154 #endif |
154 | 155 |
155 private: | 156 private: |
| 157 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
| 158 |
156 // Creates a new loader if necessary (for example, if the |instant_url| has | 159 // Creates a new loader if necessary (for example, if the |instant_url| has |
157 // changed since the last time we created the loader). | 160 // changed since the last time we created the loader). |
158 void ResetLoader(const std::string& instant_url, | 161 void ResetLoader(const std::string& instant_url, |
159 const TabContents* active_tab); | 162 const TabContents* active_tab); |
160 | 163 |
| 164 // Ensures that the |loader_| uses the default Instant URL, recreating it if |
| 165 // necessary. Will not do anything if the Instant URL could not be determined |
| 166 // or the active tab is NULL (browser is shutting down). |
| 167 void CreateDefaultLoader(); |
| 168 |
| 169 // If the |loader_| is not showing, it is deleted and recreated. Else the |
| 170 // refresh is skipped and the next refresh is scheduled. |
| 171 void OnStaleLoader(); |
| 172 |
| 173 // Calls OnStaleLoader if |stale_loader_timer_| is not running. |
| 174 void MaybeOnStaleLoader(); |
| 175 |
161 // Destroys the |loader_| and its preview contents. | 176 // Destroys the |loader_| and its preview contents. |
162 void DeleteLoader(); | 177 void DeleteLoader(); |
163 | 178 |
164 // Counterpart to Hide(). Asks the |delegate_| to display the preview. | 179 // Counterpart to Hide(). Asks the |delegate_| to display the preview. |
165 void Show(); | 180 void Show(); |
166 | 181 |
167 // Send the omnibox dropdown bounds to the page. | 182 // Send the omnibox dropdown bounds to the page. |
168 void SendBoundsToPage(); | 183 void SendBoundsToPage(); |
169 | 184 |
170 // If |template_url| is a valid TemplateURL for use with Instant, fills in | 185 // 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... |
219 | 234 |
220 // Current omnibox bounds. | 235 // Current omnibox bounds. |
221 gfx::Rect omnibox_bounds_; | 236 gfx::Rect omnibox_bounds_; |
222 | 237 |
223 // Last bounds passed to the page. | 238 // Last bounds passed to the page. |
224 gfx::Rect last_omnibox_bounds_; | 239 gfx::Rect last_omnibox_bounds_; |
225 | 240 |
226 // Timer used to update the bounds of the omnibox. | 241 // Timer used to update the bounds of the omnibox. |
227 base::OneShotTimer<InstantController> update_bounds_timer_; | 242 base::OneShotTimer<InstantController> update_bounds_timer_; |
228 | 243 |
| 244 // Timer used to ensure that the Instant page does not get too stale. |
| 245 base::OneShotTimer<InstantController> stale_loader_timer_; |
| 246 |
229 // For each key K => value N, the map says that we found that the search | 247 // For each key K => value N, the map says that we found that the search |
230 // engine identified by Instant URL K didn't support the Instant API in each | 248 // engine identified by Instant URL K didn't support the Instant API in each |
231 // of the last N times that we loaded it. If an Instant URL isn't present in | 249 // of the last N times that we loaded it. If an Instant URL isn't present in |
232 // the map at all or has a value 0, it means that search engine supports the | 250 // the map at all or has a value 0, it means that search engine supports the |
233 // Instant API (or we assume it does, since we haven't determined it doesn't). | 251 // Instant API (or we assume it does, since we haven't determined it doesn't). |
234 std::map<std::string, int> blacklisted_urls_; | 252 std::map<std::string, int> blacklisted_urls_; |
235 | 253 |
236 // Search terms extraction (for autocomplete history matches) doesn't work | 254 // Search terms extraction (for autocomplete history matches) doesn't work |
237 // on Instant URLs. So, whenever the user commits an Instant search, we add | 255 // on Instant URLs. So, whenever the user commits an Instant search, we add |
238 // an equivalent non-Instant search URL to history, so that the search shows | 256 // an equivalent non-Instant search URL to history, so that the search shows |
239 // up in autocomplete history matches. | 257 // up in autocomplete history matches. |
240 GURL url_for_history_; | 258 GURL url_for_history_; |
241 | 259 |
242 DISALLOW_COPY_AND_ASSIGN(InstantController); | 260 DISALLOW_COPY_AND_ASSIGN(InstantController); |
243 }; | 261 }; |
244 | 262 |
245 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 263 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
OLD | NEW |