diff options
author | sreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 16:17:20 +0000 |
---|---|---|
committer | sreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 16:17:20 +0000 |
commit | 64f09b8bec7aecb232f863dba062e0627be39871 (patch) | |
tree | 4579aff7456e0e56bc9e1952c1d4832fea28603b /chrome/browser/instant/instant_controller.cc | |
parent | eaa52c56b2ac53bda7ba00c20403266ad7bcaf7e (diff) | |
download | chromium_src-64f09b8bec7aecb232f863dba062e0627be39871.zip chromium_src-64f09b8bec7aecb232f863dba062e0627be39871.tar.gz chromium_src-64f09b8bec7aecb232f863dba062e0627be39871.tar.bz2 |
Introduce a new field trial for Instant.
Enable a new field trial where only the search homepage is preloaded. No
intermediate queries are issued, and no previews are shown, so this is visibly
the same as having Instant disabled. However, it should be a faster user
experience, since when the query is committed by pressing <Enter>, the search
results page will not need to fetch/render static assets such as css, logos,
common markup, etc.
BUG=none
TEST=InstantFieldTrial*
Review URL: http://codereview.chromium.org/7999001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant/instant_controller.cc')
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 86375d5..704f82c 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -45,8 +45,7 @@ InstantController::InstantController(Profile* profile, last_transition_type_(content::PAGE_TRANSITION_LINK), ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) { PrefService* service = profile->GetPrefs(); - if (service && - InstantFieldTrial::GetGroup(profile) == InstantFieldTrial::INACTIVE) { + if (service && !InstantFieldTrial::IsExperimentGroup(profile)) { // kInstantEnabledOnce was added after instant, set it now to make sure it // is correctly set. service->SetBoolean(prefs::kInstantEnabledOnce, true); @@ -159,6 +158,9 @@ bool InstantController::Update(TabContentsWrapper* tab_contents, tab_contents_ = tab_contents; commit_on_mouse_up_ = false; last_transition_type_ = match.transition; + last_url_ = match.destination_url; + last_user_text_ = user_text; + if (!ShouldUseInstant(match)) { DestroyPreviewContentsAndLeaveActive(); return false; @@ -168,9 +170,16 @@ bool InstantController::Update(TabContentsWrapper* tab_contents, DCHECK(template_url); // ShouldUseInstant returns false if no turl. if (!loader_.get()) loader_.reset(new InstantLoader(this, template_url->id())); - - if (!is_active_) - is_active_ = true; + is_active_ = true; + + // In some rare cases (involving group policy), Instant can go from the field + // trial to normal mode, with no intervening call to DestroyPreviewContents() + // This would leave the loader in a weird state, which would manifest if the + // user pressed <Enter> without calling Update(). TODO(sreeram): Handle it. + if (InstantFieldTrial::IsHiddenExperiment(tab_contents->profile())) { + loader_->MaybeLoadInstantURL(tab_contents, template_url); + return true; + } UpdateLoader(template_url, match.destination_url, match.transition, user_text, verbatim, suggested_text); @@ -213,6 +222,7 @@ void InstantController::DestroyPreviewContentsAndLeaveActive() { is_displayable_ = false; delegate_->HideInstant(); } + last_user_text_.clear(); } bool InstantController::IsCurrent() { @@ -222,6 +232,33 @@ bool InstantController::IsCurrent() { !loader_->needs_reload(); } +bool InstantController::PrepareForCommit() { + // If we are not in the HIDDEN field trial, return the status of the preview. + if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) + return IsCurrent(); + + TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( + tab_contents_->profile()); + if (!model) + return false; + + const TemplateURL* template_url = model->GetDefaultSearchProvider(); + if (last_user_text_.empty() || + !IsValidInstantTemplateURL(template_url) || + !loader_.get() || + loader_->template_url_id() != template_url->id() || + loader_->IsNavigationPending() || + loader_->is_determining_if_page_supports_instant()) { + return false; + } + + // Ignore the suggested text, as we are about to commit the verbatim query. + string16 suggested_text; + UpdateLoader(template_url, last_url_, last_transition_type_, last_user_text_, + true, &suggested_text); + return true; +} + TabContentsWrapper* InstantController::CommitCurrentPreview( InstantCommitType type) { DCHECK(loader_.get()); |