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

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

Issue 10829436: Recreate the loader as soon as it is deleted and ensure that it does not become stale. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding tests. Created 8 years, 4 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_controller.cc
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 6133e45715c52918198fc2d6094e374107683ec0..af356fc6054fb1c47634526524af3ebeccee522c 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -52,6 +52,10 @@ const int kUpdateBoundsDelayMS = 1000;
// before we give up and blacklist it for the rest of the browsing session.
const int kMaxInstantSupportFailures = 10;
+// If an instant page has not been used in this much time, it is reloaded so
+// that the page does not become stale.
sreeram 2012/08/22 17:39:35 // If an Instant page has not been used in these m
Shishir 2012/08/23 18:26:33 Done.
+const int kInstantRefreshIntervalMS = 3 * 3600 * 1000;
sreeram 2012/08/22 17:39:35 Perhaps call this kStaleLoaderTimeoutMS?
Shishir 2012/08/23 18:26:33 Done.
+
std::string ModeToString(InstantController::Mode mode) {
switch (mode) {
case InstantController::INSTANT: return "_Instant";
@@ -168,6 +172,9 @@ bool InstantController::Update(const AutocompleteMatch& match,
return false;
}
+ // Rechedule the instant loader refresh.
+ ScheduleLoaderRefresh();
+
// The presence of any suggested_text implies verbatim.
DCHECK(suggested_text->empty() || verbatim)
<< user_text << "|" << *suggested_text;
@@ -264,6 +271,11 @@ TabContents* InstantController::CommitCurrentPreview(InstantCommitType type) {
preview->web_contents()->GetController().CopyStateFromAndPrune(
&active_tab->web_contents()->GetController());
delegate_->CommitInstant(preview);
+
+ // Try to create another loader immediately so that it is ready for the next
+ // user interaction.
+ ResetLoaderWithDefaultUrlAndCurrentTab();
+
return preview;
}
@@ -398,23 +410,7 @@ void InstantController::OnAutocompleteLostFocus(
}
void InstantController::OnAutocompleteGotFocus() {
- const TabContents* active_tab = delegate_->GetActiveTabContents();
-
- // We could get here with no active tab if the Browser is closing.
- if (!active_tab)
- return;
-
- // Since we don't have any autocomplete match to work with, we'll just use
- // the default search provider's Instant URL.
- const TemplateURL* template_url =
- TemplateURLServiceFactory::GetForProfile(active_tab->profile())->
- GetDefaultSearchProvider();
-
- std::string instant_url;
- if (!GetInstantURL(template_url, &instant_url))
- return;
-
- ResetLoader(instant_url, active_tab);
+ ResetLoaderWithDefaultUrlAndCurrentTab();
}
bool InstantController::commit_on_pointer_release() const {
@@ -506,18 +502,63 @@ void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) {
#endif
}
+void InstantController::CreateLoader(const std::string& instant_url,
+ const TabContents* active_tab) {
+ DCHECK(!loader_.get());
+ loader_.reset(new InstantLoader(this, instant_url, active_tab));
+ loader_->Init();
+ ScheduleLoaderRefresh();
+ AddPreviewUsageForHistogram(mode_, PREVIEW_CREATED);
+}
sreeram 2012/08/22 17:39:35 We don't need this method (CreateLoader) at all. W
Shishir 2012/08/23 18:26:33 Done.
+
void InstantController::ResetLoader(const std::string& instant_url,
const TabContents* active_tab) {
if (GetPreviewContents() && loader_->instant_url() != instant_url)
DeleteLoader();
- if (!GetPreviewContents()) {
- loader_.reset(new InstantLoader(this, instant_url, active_tab));
- loader_->Init();
- AddPreviewUsageForHistogram(mode_, PREVIEW_CREATED);
+ if (!GetPreviewContents())
+ CreateLoader(instant_url, active_tab);
+}
+
+void InstantController::ResetLoaderWithDefaultUrlAndCurrentTab() {
+ const TabContents* active_tab = delegate_->GetActiveTabContents();
+
+ // We could get here with no active tab if the Browser is closing.
+ if (!active_tab)
+ return;
+
+ const TemplateURL* template_url =
+ TemplateURLServiceFactory::GetForProfile(active_tab->profile())->
+ GetDefaultSearchProvider();
+ std::string instant_url;
+ if (!GetInstantURL(template_url, &instant_url))
+ return;
+
+ ResetLoader(instant_url, active_tab);
+}
+
+void InstantController::ScheduleLoaderRefresh() {
+ if (loader_refresh_timer_.IsRunning()) {
+ loader_refresh_timer_.Reset();
+ } else {
+ loader_refresh_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kInstantRefreshIntervalMS), this,
+ &InstantController::RefreshLoader);
}
}
+void InstantController::RefreshLoader() {
+ // If the loader is showing, do not delete it, but reschedule a refresh.
+ if (is_showing_) {
+ ScheduleLoaderRefresh();
+ return;
+ }
+
+ DeleteLoader();
+ ResetLoaderWithDefaultUrlAndCurrentTab();
+}
+
void InstantController::DeleteLoader() {
Hide();
last_full_text_.clear();
@@ -529,6 +570,7 @@ void InstantController::DeleteLoader() {
url_for_history_ = GURL();
if (GetPreviewContents())
AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED);
+ loader_refresh_timer_.Stop();
loader_.reset();
}
« chrome/browser/instant/instant_controller.h ('K') | « chrome/browser/instant/instant_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698