From d8e73bdf182614e9893e898e6358c262ea50a749 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Wed, 14 Mar 2012 16:30:52 +0000 Subject: Misc. cleanup for InstantController. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9702008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126657 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/instant/instant_controller.cc | 39 ++++++++-------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'chrome/browser/instant/instant_controller.cc') diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 114a724..a4d7ba8 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -39,12 +39,14 @@ InstantController::InstantController(Profile* profile, InstantDelegate* delegate) : delegate_(delegate), + template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)), tab_contents_(NULL), is_displayable_(false), is_out_of_date_(true), commit_on_mouse_up_(false), last_transition_type_(content::PAGE_TRANSITION_LINK), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { + DCHECK(template_url_service_); PrefService* service = profile->GetPrefs(); if (service && !InstantFieldTrial::IsInstantExperiment(profile)) { // kInstantEnabledOnce was added after instant, set it now to make sure it @@ -162,13 +164,15 @@ bool InstantController::Update(TabContentsWrapper* tab_contents, last_url_ = match.destination_url; last_user_text_ = user_text; - if (!ShouldUseInstant(match)) { + const TemplateURL* template_url = match.GetTemplateURL(); + const TemplateURL* default_t_url = + template_url_service_->GetDefaultSearchProvider(); + if (!IsValidInstantTemplateURL(template_url) || !default_t_url || + (template_url->id() != default_t_url->id())) { Hide(); return false; } - const TemplateURL* template_url = match.template_url; - DCHECK(template_url); // ShouldUseInstant returns false if no turl. if (!loader_.get()) { loader_.reset(new InstantLoader(this, template_url->id(), InstantFieldTrial::GetGroupName(tab_contents->profile()))); @@ -247,12 +251,8 @@ bool InstantController::PrepareForCommit() { 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(); + const TemplateURL* template_url = + template_url_service_->GetDefaultSearchProvider(); if (!IsValidInstantTemplateURL(template_url) || loader_->template_url_id() != template_url->id() || loader_->IsNavigationPending() || @@ -386,12 +386,8 @@ void InstantController::OnAutocompleteGotFocus( return; } - TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( - tab_contents->profile()); - if (!model) - return; - - const TemplateURL* template_url = model->GetDefaultSearchProvider(); + const TemplateURL* template_url = + template_url_service_->GetDefaultSearchProvider(); if (!IsValidInstantTemplateURL(template_url)) return; @@ -521,19 +517,6 @@ void InstantController::UpdateLoader(const TemplateURL* template_url, suggested_text->clear(); } -bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) { - TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( - tab_contents_->profile()); - if (!model) - return false; - - const TemplateURL* default_t_url = model->GetDefaultSearchProvider(); - const TemplateURL* match_t_url = match.template_url; - return IsValidInstantTemplateURL(default_t_url) && - IsValidInstantTemplateURL(match_t_url) && - (match_t_url->id() == default_t_url->id()); -} - // Returns true if |template_url| is a valid TemplateURL for use by instant. bool InstantController::IsValidInstantTemplateURL( const TemplateURL* template_url) { -- cgit v1.1