Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3020)

Unified Diff: chrome/browser/instant/instant_loader.cc

Issue 6990015: Preload Instant search when omnibox is focused. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/instant/instant_loader.cc
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index f686ecb88928eca1229c996078012340a2a1c702..26365a3a69adf3f4a6425df52579a99056eacf91 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -709,32 +709,8 @@ bool InstantLoader::Update(TabContentsWrapper* tab_contents,
complete_suggested_text_.substr(user_text_.size());
}
} else {
- preview_tab_contents_delegate_->PrepareForNewLoad();
-
- // Load the instant URL. We don't reflect the url we load in url() as
- // callers expect that we're loading the URL they tell us to.
- //
- // This uses an empty string for the replacement text as the url doesn't
- // really have the search params, but we need to use the replace
- // functionality so that embeded tags (like {google:baseURL}) are escaped
- // correctly.
- // TODO(sky): having to use a replaceable url is a bit of a hack here.
- GURL instant_url(
- template_url->instant_url()->ReplaceSearchTerms(
- *template_url, string16(), -1, string16()));
- CommandLine* cl = CommandLine::ForCurrentProcess();
- if (cl->HasSwitch(switches::kInstantURL))
- instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL));
- preview_contents_->controller().LoadURL(
- instant_url, GURL(), transition_type);
- RenderViewHost* host = preview_contents_->render_view_host();
- host->Send(new ViewMsg_SearchBoxChange(
- host->routing_id(), user_text_, verbatim, 0, 0));
- frame_load_observer_.reset(
- new FrameLoadObserver(this,
- preview_contents()->tab_contents(),
- user_text_,
- verbatim));
+ LoadInstantURL(tab_contents, template_url, transition_type, user_text_,
+ verbatim);
}
} else {
DCHECK(template_url_id_ == 0);
@@ -1034,3 +1010,50 @@ void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) {
preview_contents_->tab_contents()->ShowContents();
}
+
+void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents,
sky 2011/05/20 20:52:18 Position should match header (and next method).
sreeram 2011/05/21 03:18:27 Done.
+ const TemplateURL* template_url,
+ PageTransition::Type transition_type,
+ const string16& user_text,
+ bool verbatim) {
+ preview_tab_contents_delegate_->PrepareForNewLoad();
+
+ // Load the instant URL. We don't reflect the url we load in url() as
+ // callers expect that we're loading the URL they tell us to.
+ //
+ // This uses an empty string for the replacement text as the url doesn't
+ // really have the search params, but we need to use the replace
+ // functionality so that embeded tags (like {google:baseURL}) are escaped
+ // correctly.
+ // TODO(sky): having to use a replaceable url is a bit of a hack here.
+ GURL instant_url(template_url->instant_url()->ReplaceSearchTerms(
+ *template_url, string16(), -1, string16()));
+ CommandLine* cl = CommandLine::ForCurrentProcess();
+ if (cl->HasSwitch(switches::kInstantURL))
+ instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL));
+ preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type);
+ RenderViewHost* host = preview_contents_->render_view_host();
+ host->Send(new ViewMsg_SearchBoxChange(
+ host->routing_id(), user_text, verbatim, 0, 0));
+ frame_load_observer_.reset(new FrameLoadObserver(
+ this, preview_contents()->tab_contents(), user_text, verbatim));
+}
+
+void InstantLoader::MaybeLoadInstantURL(TabContentsWrapper* tab_contents,
+ const TemplateURL* template_url) {
+ DCHECK(template_url_id_ == template_url->id());
+
+ // If we already have a |preview_contents_|, future search queries will be
+ // issued into it (see the "if (!created_preview_contents)" block in |Update|
+ // above), so there is no need to load the |template_url|'s instant URL.
+ if (preview_contents_.get())
+ return;
+
+ CommandLine* cl = CommandLine::ForCurrentProcess();
sky 2011/05/20 20:52:18 Put this check in InstantController, not here.
sreeram 2011/05/21 03:18:27 Done.
+ if (!cl->HasSwitch(switches::kPreloadInstantSearch))
+ return;
+
+ CreatePreviewContents(tab_contents);
+ LoadInstantURL(tab_contents, template_url, PageTransition::GENERATED,
+ string16(), true);
sky 2011/05/20 20:52:18 Won't this ultimately result in calls back to Page
sreeram 2011/05/21 03:18:27 No. Several reasons why PageFinishedLoading won't
+}

Powered by Google App Engine
This is Rietveld 408576698