Chromium Code Reviews| 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 | |
| 148 // Creates a new loader if necessary (for example, if the |instant_url| has | 151 // Creates a new loader if necessary (for example, if the |instant_url| has |
| 149 // changed since the last time we created the loader). | 152 // changed since the last time we created the loader). |
| 150 void ResetLoader(const std::string& instant_url, | 153 void ResetLoader(const std::string& instant_url, |
| 151 const TabContents* active_tab); | 154 const TabContents* active_tab); |
| 152 | 155 |
| 156 // Ensures that the |loader_| uses the default Instant Url, recreating it if | |
| 157 // necessary. Will not do anything if the Instant Url could not be determined | |
|
sreeram
2012/08/24 21:06:25
Url -> URL in both lines above.
Shishir
2012/08/24 22:17:39
Done.
| |
| 158 // or the active tab is NULL (browser is shutting down). | |
| 159 void CreateDefaultLoader(); | |
| 160 | |
| 161 // If the |loader_| is not showing, it is deleted and recreated. Else the | |
| 162 // refresh is skipped and the next refresh is scheduled. | |
| 163 void OnStaleLoader(); | |
| 164 | |
| 165 // Calls OnStaleLoader if |stale_loader_timer_| is not running. | |
| 166 void MaybeOnStaleLoader(); | |
| 167 | |
| 153 // Destroys the |loader_| and its preview contents. | 168 // Destroys the |loader_| and its preview contents. |
| 154 void DeleteLoader(); | 169 void DeleteLoader(); |
| 155 | 170 |
| 156 // Counterpart to Hide(). Asks the |delegate_| to display the preview. | 171 // Counterpart to Hide(). Asks the |delegate_| to display the preview. |
| 157 void Show(); | 172 void Show(); |
| 158 | 173 |
| 159 // Send the omnibox dropdown bounds to the page. | 174 // Send the omnibox dropdown bounds to the page. |
| 160 void SendBoundsToPage(); | 175 void SendBoundsToPage(); |
| 161 | 176 |
| 162 // If |template_url| is a valid TemplateURL for use with Instant, fills in | 177 // 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 | 226 |
| 212 // Current omnibox bounds. | 227 // Current omnibox bounds. |
| 213 gfx::Rect omnibox_bounds_; | 228 gfx::Rect omnibox_bounds_; |
| 214 | 229 |
| 215 // Last bounds passed to the page. | 230 // Last bounds passed to the page. |
| 216 gfx::Rect last_omnibox_bounds_; | 231 gfx::Rect last_omnibox_bounds_; |
| 217 | 232 |
| 218 // Timer used to update the bounds of the omnibox. | 233 // Timer used to update the bounds of the omnibox. |
| 219 base::OneShotTimer<InstantController> update_bounds_timer_; | 234 base::OneShotTimer<InstantController> update_bounds_timer_; |
| 220 | 235 |
| 236 // Timer used to ensure that the Instant page does not get too stale. | |
| 237 base::OneShotTimer<InstantController> stale_loader_timer_; | |
| 238 | |
| 221 // For each key K => value N, the map says that we found that the search | 239 // 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 | 240 // 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 | 241 // 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 | 242 // 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). | 243 // Instant API (or we assume it does, since we haven't determined it doesn't). |
| 226 std::map<std::string, int> blacklisted_urls_; | 244 std::map<std::string, int> blacklisted_urls_; |
| 227 | 245 |
| 228 // Search terms extraction (for autocomplete history matches) doesn't work | 246 // Search terms extraction (for autocomplete history matches) doesn't work |
| 229 // on Instant URLs. So, whenever the user commits an Instant search, we add | 247 // 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 | 248 // an equivalent non-Instant search URL to history, so that the search shows |
| 231 // up in autocomplete history matches. | 249 // up in autocomplete history matches. |
| 232 GURL url_for_history_; | 250 GURL url_for_history_; |
| 233 | 251 |
| 234 DISALLOW_COPY_AND_ASSIGN(InstantController); | 252 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 235 }; | 253 }; |
| 236 | 254 |
| 237 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 255 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |