| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 37 // InstantController maintains a TabContents that is intended to give a preview | 37 // InstantController maintains a TabContents that is intended to give a preview |
| 38 // of a URL. InstantController is owned by Browser. | 38 // of a URL. InstantController is owned by Browser. |
| 39 // | 39 // |
| 40 // At any time the TabContents maintained by InstantController may be destroyed | 40 // At any time the TabContents maintained by InstantController may be destroyed |
| 41 // by way of |DestroyPreviewContents|, which results in |HideInstant| being | 41 // by way of |DestroyPreviewContents|, which results in |HideInstant| being |
| 42 // invoked on the delegate. Similarly the preview may be committed at any time | 42 // invoked on the delegate. Similarly the preview may be committed at any time |
| 43 // by invoking |CommitCurrentPreview|, which results in |CommitInstant| | 43 // by invoking |CommitCurrentPreview|, which results in |CommitInstant| |
| 44 // being invoked on the delegate. | 44 // being invoked on the delegate. |
| 45 class InstantController : public InstantLoaderDelegate { | 45 class InstantController : public InstantLoaderDelegate { |
| 46 public: | 46 public: |
| 47 // Variations of instant support. | |
| 48 // TODO(sky): nuke these when we decide the default behavior. | |
| 49 enum Type { | |
| 50 // NOTE: these values are persisted to prefs. Don't change them! | |
| 51 | |
| 52 FIRST_TYPE = 0, | |
| 53 | |
| 54 // Search results are shown for the best guess of what we think the user was | |
| 55 // planning on typing. | |
| 56 PREDICTIVE_TYPE = 0, | |
| 57 | |
| 58 // Search results are shown for exactly what was typed. | |
| 59 VERBATIM_TYPE, | |
| 60 | |
| 61 // Variant of predictive that does not auto-complete after a delay. | |
| 62 PREDICTIVE_NO_AUTO_COMPLETE_TYPE, | |
| 63 | |
| 64 LAST_TYPE = PREDICTIVE_NO_AUTO_COMPLETE_TYPE | |
| 65 }; | |
| 66 | |
| 67 | |
| 68 // Amount of time to wait before starting the instant animation. | 47 // Amount of time to wait before starting the instant animation. |
| 69 static const int kAutoCommitPauseTimeMS = 1000; | 48 static const int kAutoCommitPauseTimeMS = 1000; |
| 70 // Duration of the instant animation in which the colors change. | 49 // Duration of the instant animation in which the colors change. |
| 71 static const int kAutoCommitFadeInTimeMS = 300; | 50 static const int kAutoCommitFadeInTimeMS = 300; |
| 72 | 51 |
| 73 InstantController(Profile* profile, InstantDelegate* delegate); | 52 InstantController(Profile* profile, InstantDelegate* delegate); |
| 74 ~InstantController(); | 53 ~InstantController(); |
| 75 | 54 |
| 76 // Registers instant related preferences. | 55 // Registers instant related preferences. |
| 77 static void RegisterUserPrefs(PrefService* prefs); | 56 static void RegisterUserPrefs(PrefService* prefs); |
| 78 | 57 |
| 79 // Records instant metrics. | 58 // Records instant metrics. |
| 80 static void RecordMetrics(Profile* profile); | 59 static void RecordMetrics(Profile* profile); |
| 81 | 60 |
| 82 // Returns true if either type of instant is enabled. | 61 // Returns true if instant is enabled. |
| 83 static bool IsEnabled(Profile* profile); | 62 static bool IsEnabled(Profile* profile); |
| 84 | 63 |
| 85 // Returns true if the specified type of instant is enabled. | |
| 86 static bool IsEnabled(Profile* profile, Type type); | |
| 87 | |
| 88 // Enables instant. | 64 // Enables instant. |
| 89 static void Enable(Profile* profile); | 65 static void Enable(Profile* profile); |
| 90 | 66 |
| 91 // Disables instant. | 67 // Disables instant. |
| 92 static void Disable(Profile* profile); | 68 static void Disable(Profile* profile); |
| 93 | 69 |
| 94 // Accepts the currently showing instant preview, if any, and returns true. | 70 // Accepts the currently showing instant preview, if any, and returns true. |
| 95 // Returns false if there is no instant preview showing. | 71 // Returns false if there is no instant preview showing. |
| 96 static bool CommitIfCurrent(InstantController* controller); | 72 static bool CommitIfCurrent(InstantController* controller); |
| 97 | 73 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // schedule a task. | 226 // schedule a task. |
| 251 void ScheduleDestroy(InstantLoader* loader); | 227 void ScheduleDestroy(InstantLoader* loader); |
| 252 | 228 |
| 253 // Destroys all loaders scheduled for destruction in |ScheduleForDestroy|. | 229 // Destroys all loaders scheduled for destruction in |ScheduleForDestroy|. |
| 254 void DestroyLoaders(); | 230 void DestroyLoaders(); |
| 255 | 231 |
| 256 // Returns the TemplateURL to use for the specified AutocompleteMatch, or | 232 // Returns the TemplateURL to use for the specified AutocompleteMatch, or |
| 257 // NULL if there is no TemplateURL for |match|. | 233 // NULL if there is no TemplateURL for |match|. |
| 258 const TemplateURL* GetTemplateURL(const AutocompleteMatch& match); | 234 const TemplateURL* GetTemplateURL(const AutocompleteMatch& match); |
| 259 | 235 |
| 260 // If instant is enabled for the specified profile the type of instant is set | |
| 261 // in |type| and true is returned. Otherwise returns false. | |
| 262 static bool GetType(Profile* profile, Type* type); | |
| 263 | |
| 264 // Returns a string description for the currently enabled type. This is used | |
| 265 // for histograms. | |
| 266 static std::string GetTypeString(Profile* profile); | |
| 267 | |
| 268 InstantDelegate* delegate_; | 236 InstantDelegate* delegate_; |
| 269 | 237 |
| 270 // The TabContents last passed to |Update|. | 238 // The TabContents last passed to |Update|. |
| 271 TabContentsWrapper* tab_contents_; | 239 TabContentsWrapper* tab_contents_; |
| 272 | 240 |
| 273 // See description above getter for details. | 241 // See description above getter for details. |
| 274 bool is_active_; | 242 bool is_active_; |
| 275 | 243 |
| 276 // Has notification been sent out that the preview TabContents is ready to be | 244 // Has notification been sent out that the preview TabContents is ready to be |
| 277 // shown? | 245 // shown? |
| (...skipping 17 matching lines...) Expand all Loading... |
| 295 std::set<TemplateURLID> blacklisted_ids_; | 263 std::set<TemplateURLID> blacklisted_ids_; |
| 296 | 264 |
| 297 base::OneShotTimer<InstantController> update_timer_; | 265 base::OneShotTimer<InstantController> update_timer_; |
| 298 | 266 |
| 299 // Used by ScheduleForDestroy; see it for details. | 267 // Used by ScheduleForDestroy; see it for details. |
| 300 ScopedRunnableMethodFactory<InstantController> destroy_factory_; | 268 ScopedRunnableMethodFactory<InstantController> destroy_factory_; |
| 301 | 269 |
| 302 // URL last pased to ScheduleUpdate. | 270 // URL last pased to ScheduleUpdate. |
| 303 GURL scheduled_url_; | 271 GURL scheduled_url_; |
| 304 | 272 |
| 305 Type type_; | |
| 306 | |
| 307 // List of InstantLoaders to destroy. See ScheduleForDestroy for details. | 273 // List of InstantLoaders to destroy. See ScheduleForDestroy for details. |
| 308 ScopedVector<InstantLoader> loaders_to_destroy_; | 274 ScopedVector<InstantLoader> loaders_to_destroy_; |
| 309 | 275 |
| 310 // The set of hosts that we don't use instant with. This is shared across all | 276 // The set of hosts that we don't use instant with. This is shared across all |
| 311 // instances and only maintained for the current session. | 277 // instances and only maintained for the current session. |
| 312 static HostBlacklist* host_blacklist_; | 278 static HostBlacklist* host_blacklist_; |
| 313 | 279 |
| 314 DISALLOW_COPY_AND_ASSIGN(InstantController); | 280 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 315 }; | 281 }; |
| 316 | 282 |
| 317 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 283 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |