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

Unified Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 15041004: Replace PruneAllButActive with PruneAllButVisible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change to CHECK. Created 7 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
« no previous file with comments | « chrome/browser/ui/browser_commands.cc ('k') | chrome/browser/ui/search/instant_controller.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser_instant_controller.cc
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 34e1ee717c995cf64155a0d39972e9467d70396b..72a74c9002795e0b66ebe529d9d0c28f921975a9 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -100,13 +100,32 @@ bool BrowserInstantController::MaybeSwapInInstantNTPContents(
*target_contents = instant_ntp.get();
if (source_contents) {
- instant_ntp->GetController().CopyStateFromAndPrune(
- &source_contents->GetController());
- ReplaceWebContentsAt(
- browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
- instant_ntp.Pass());
+ // If the Instant NTP hasn't yet committed an entry, we can't call
+ // CopyStateFromAndPrune. Instead, load the Local NTP URL directly in the
+ // source contents.
+ // TODO(sreeram): Always using the local URL is wrong in the case of the
+ // first tab in a window where we might want to use the remote URL. Fix.
+ if (!instant_ntp->GetController().CanPruneAllButVisible()) {
+ source_contents->GetController().LoadURL(chrome::GetLocalInstantURL(
+ profile()), content::Referrer(), content::PAGE_TRANSITION_GENERATED,
+ std::string());
+ *target_contents = source_contents;
+ } else {
+ instant_ntp->GetController().CopyStateFromAndPrune(
+ &source_contents->GetController());
+ ReplaceWebContentsAt(
+ browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
+ instant_ntp.Pass());
+ }
} else {
- instant_ntp->GetController().PruneAllButActive();
+ // If the Instant NTP hasn't yet committed an entry, we can't call
+ // PruneAllButVisible. In that case, there shouldn't be any entries to
+ // prune anyway.
+ if (instant_ntp->GetController().CanPruneAllButVisible())
+ instant_ntp->GetController().PruneAllButVisible();
+ else
+ CHECK(!instant_ntp->GetController().GetLastCommittedEntry());
+
// If |source_contents| is NULL, then the caller is responsible for
// inserting instant_ntp into the tabstrip and will take ownership.
ignore_result(instant_ntp.release());
« no previous file with comments | « chrome/browser/ui/browser_commands.cc ('k') | chrome/browser/ui/search/instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698