| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/scoped_vector.h" | 14 #include "base/scoped_vector.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/timer.h" | 17 #include "base/timer.h" |
| 18 #include "chrome/browser/instant/instant_commit_type.h" | 18 #include "chrome/browser/instant/instant_commit_type.h" |
| 19 #include "chrome/browser/instant/instant_loader_delegate.h" | 19 #include "chrome/browser/instant/instant_loader_delegate.h" |
| 20 #include "chrome/browser/search_engines/template_url_id.h" | 20 #include "chrome/browser/search_engines/template_url_id.h" |
| 21 #include "chrome/common/page_transition_types.h" | 21 #include "chrome/common/page_transition_types.h" |
| 22 #include "gfx/native_widget_types.h" | 22 #include "gfx/native_widget_types.h" |
| 23 #include "gfx/rect.h" | 23 #include "gfx/rect.h" |
| 24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 25 | 25 |
| 26 struct AutocompleteMatch; | 26 struct AutocompleteMatch; |
| 27 class InstantDelegate; | 27 class InstantDelegate; |
| 28 class InstantLoader; | 28 class InstantLoader; |
| 29 class InstantLoaderManager; | 29 class InstantLoaderManager; |
| 30 class InstantTest; |
| 30 class PrefService; | 31 class PrefService; |
| 31 class Profile; | 32 class Profile; |
| 32 class TabContents; | 33 class TabContents; |
| 33 class TabContentsWrapper; | 34 class TabContentsWrapper; |
| 34 class TemplateURL; | 35 class TemplateURL; |
| 35 | 36 |
| 36 // InstantController maintains a TabContents that is intended to give a preview | 37 // InstantController maintains a TabContents that is intended to give a preview |
| 37 // of a URL. InstantController is owned by Browser. | 38 // of a URL. InstantController is owned by Browser. |
| 38 // | 39 // |
| 39 // At any time the TabContents maintained by InstantController may be destroyed | 40 // At any time the TabContents maintained by InstantController may be destroyed |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Does cleanup after the preview contents has been added to the tabstrip. | 147 // Does cleanup after the preview contents has been added to the tabstrip. |
| 147 // Invoke this if you explicitly invoke ReleasePreviewContents. | 148 // Invoke this if you explicitly invoke ReleasePreviewContents. |
| 148 void CompleteRelease(TabContents* tab); | 149 void CompleteRelease(TabContents* tab); |
| 149 | 150 |
| 150 // TabContents the match is being shown for. | 151 // TabContents the match is being shown for. |
| 151 TabContentsWrapper* tab_contents() const { return tab_contents_; } | 152 TabContentsWrapper* tab_contents() const { return tab_contents_; } |
| 152 | 153 |
| 153 // The preview TabContents; may be null. | 154 // The preview TabContents; may be null. |
| 154 TabContentsWrapper* GetPreviewContents(); | 155 TabContentsWrapper* GetPreviewContents(); |
| 155 | 156 |
| 156 // Returns true if the preview TabContents is active. In some situations this | 157 // Returns true if |Update| has been invoked without a corresponding call to |
| 157 // may return false yet preview_contents() returns non-NULL. | 158 // |DestroyPreviewContents| or |CommitCurrentPreview|. |
| 158 bool is_active() const { return is_active_; } | 159 bool is_active() const { return is_active_; } |
| 159 | 160 |
| 161 // Returns true if the preview TabContents is ready to be displayed. In some |
| 162 // situations this may return false yet GetPreviewContents() returns non-NULL. |
| 163 bool is_displayable() const { return is_displayable_; } |
| 164 |
| 160 // Returns the transition type of the last AutocompleteMatch passed to Update. | 165 // Returns the transition type of the last AutocompleteMatch passed to Update. |
| 161 PageTransition::Type last_transition_type() const { | 166 PageTransition::Type last_transition_type() const { |
| 162 return last_transition_type_; | 167 return last_transition_type_; |
| 163 } | 168 } |
| 164 | 169 |
| 165 // Returns true if we're showing results from a provider that supports the | 170 // Returns true if we're showing results from a provider that supports the |
| 166 // instant API. See description of |MightSupportInstant| for how this | 171 // instant API. See description of |MightSupportInstant| for how this |
| 167 // differs from actual loading state. | 172 // differs from actual loading state. |
| 168 bool IsShowingInstant(); | 173 bool IsShowingInstant(); |
| 169 | 174 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 184 virtual void SetSuggestedTextFor(InstantLoader* loader, | 189 virtual void SetSuggestedTextFor(InstantLoader* loader, |
| 185 const string16& text); | 190 const string16& text); |
| 186 virtual gfx::Rect GetInstantBounds(); | 191 virtual gfx::Rect GetInstantBounds(); |
| 187 virtual bool ShouldCommitInstantOnMouseUp(); | 192 virtual bool ShouldCommitInstantOnMouseUp(); |
| 188 virtual void CommitInstantLoader(InstantLoader* loader); | 193 virtual void CommitInstantLoader(InstantLoader* loader); |
| 189 virtual void InstantLoaderDoesntSupportInstant(InstantLoader* loader); | 194 virtual void InstantLoaderDoesntSupportInstant(InstantLoader* loader); |
| 190 virtual void AddToBlacklist(InstantLoader* loader, const GURL& url); | 195 virtual void AddToBlacklist(InstantLoader* loader, const GURL& url); |
| 191 | 196 |
| 192 | 197 |
| 193 private: | 198 private: |
| 199 friend class InstantTest; |
| 200 |
| 194 typedef std::set<std::string> HostBlacklist; | 201 typedef std::set<std::string> HostBlacklist; |
| 195 | 202 |
| 203 // Destroys the current loaders but remains actives. |
| 204 void DestroyAndLeaveActive(); |
| 205 |
| 206 // Returns the TabContents of the pending loader (or NULL). This is only used |
| 207 // for testing. |
| 208 TabContentsWrapper* GetPendingPreviewContents(); |
| 209 |
| 196 // Returns true if we should update immediately. | 210 // Returns true if we should update immediately. |
| 197 bool ShouldUpdateNow(TemplateURLID instant_id, const GURL& url); | 211 bool ShouldUpdateNow(TemplateURLID instant_id, const GURL& url); |
| 198 | 212 |
| 199 // Schedules a delayed update to load the specified url. | 213 // Schedules a delayed update to load the specified url. |
| 200 void ScheduleUpdate(const GURL& url); | 214 void ScheduleUpdate(const GURL& url); |
| 201 | 215 |
| 202 // Invoked from the timer to process the last scheduled url. | 216 // Invoked from the timer to process the last scheduled url. |
| 203 void ProcessScheduledUpdate(); | 217 void ProcessScheduledUpdate(); |
| 204 | 218 |
| 205 // Updates InstantLoaderManager and its current InstantLoader. This is invoked | 219 // Updates InstantLoaderManager and its current InstantLoader. This is invoked |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 260 |
| 247 // Returns a string description for the currently enabled type. This is used | 261 // Returns a string description for the currently enabled type. This is used |
| 248 // for histograms. | 262 // for histograms. |
| 249 static std::string GetTypeString(Profile* profile); | 263 static std::string GetTypeString(Profile* profile); |
| 250 | 264 |
| 251 InstantDelegate* delegate_; | 265 InstantDelegate* delegate_; |
| 252 | 266 |
| 253 // The TabContents last passed to |Update|. | 267 // The TabContents last passed to |Update|. |
| 254 TabContentsWrapper* tab_contents_; | 268 TabContentsWrapper* tab_contents_; |
| 255 | 269 |
| 270 // See description above getter for details. |
| 271 bool is_active_; |
| 272 |
| 256 // Has notification been sent out that the preview TabContents is ready to be | 273 // Has notification been sent out that the preview TabContents is ready to be |
| 257 // shown? | 274 // shown? |
| 258 bool is_active_; | 275 bool is_displayable_; |
| 259 | 276 |
| 260 // See description above setter. | 277 // See description above setter. |
| 261 gfx::Rect omnibox_bounds_; | 278 gfx::Rect omnibox_bounds_; |
| 262 | 279 |
| 263 // See description above CommitOnMouseUp. | 280 // See description above CommitOnMouseUp. |
| 264 bool commit_on_mouse_up_; | 281 bool commit_on_mouse_up_; |
| 265 | 282 |
| 266 // See description above getter. | 283 // See description above getter. |
| 267 PageTransition::Type last_transition_type_; | 284 PageTransition::Type last_transition_type_; |
| 268 | 285 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 288 ScopedVector<InstantLoader> loaders_to_destroy_; | 305 ScopedVector<InstantLoader> loaders_to_destroy_; |
| 289 | 306 |
| 290 // The set of hosts that we don't use instant with. This is shared across all | 307 // The set of hosts that we don't use instant with. This is shared across all |
| 291 // instances and only maintained for the current session. | 308 // instances and only maintained for the current session. |
| 292 static HostBlacklist* host_blacklist_; | 309 static HostBlacklist* host_blacklist_; |
| 293 | 310 |
| 294 DISALLOW_COPY_AND_ASSIGN(InstantController); | 311 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 295 }; | 312 }; |
| 296 | 313 |
| 297 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 314 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |