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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 49003011: Handle should_replace_current_entry in prerender. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: content::kAboutBlankURL Created 7 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" // Temporary 10 #include "base/strings/string_number_conversions.h" // Temporary
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1222
1223 FinishRestore(source.last_committed_entry_index_, RESTORE_CURRENT_SESSION); 1223 FinishRestore(source.last_committed_entry_index_, RESTORE_CURRENT_SESSION);
1224 1224
1225 // Copy the max page id map from the old tab to the new tab. This ensures 1225 // Copy the max page id map from the old tab to the new tab. This ensures
1226 // that new and existing navigations in the tab's current SiteInstances 1226 // that new and existing navigations in the tab's current SiteInstances
1227 // are identified properly. 1227 // are identified properly.
1228 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents()); 1228 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents());
1229 } 1229 }
1230 1230
1231 void NavigationControllerImpl::CopyStateFromAndPrune( 1231 void NavigationControllerImpl::CopyStateFromAndPrune(
1232 NavigationController* temp) { 1232 NavigationController* temp,
1233 bool replace_entry) {
1233 // It is up to callers to check the invariants before calling this. 1234 // It is up to callers to check the invariants before calling this.
1234 CHECK(CanPruneAllButLastCommitted()); 1235 CHECK(CanPruneAllButLastCommitted());
1235 1236
1236 NavigationControllerImpl* source = 1237 NavigationControllerImpl* source =
1237 static_cast<NavigationControllerImpl*>(temp); 1238 static_cast<NavigationControllerImpl*>(temp);
1238 // The SiteInstance and page_id of the last committed entry needs to be 1239 // The SiteInstance and page_id of the last committed entry needs to be
1239 // remembered at this point, in case there is only one committed entry 1240 // remembered at this point, in case there is only one committed entry
1240 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance 1241 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance
1241 // can't be freed during this time period. 1242 // can't be freed during this time period.
1242 NavigationEntryImpl* last_committed = 1243 NavigationEntryImpl* last_committed =
1243 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); 1244 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry());
1244 scoped_refptr<SiteInstance> site_instance( 1245 scoped_refptr<SiteInstance> site_instance(
1245 last_committed->site_instance()); 1246 last_committed->site_instance());
1246 int32 minimum_page_id = last_committed->GetPageID(); 1247 int32 minimum_page_id = last_committed->GetPageID();
1247 int32 max_page_id = 1248 int32 max_page_id =
1248 delegate_->GetMaxPageIDForSiteInstance(site_instance.get()); 1249 delegate_->GetMaxPageIDForSiteInstance(site_instance.get());
1249 1250
1250 // Remove all the entries leaving the active entry. 1251 // Remove all the entries leaving the active entry.
1251 PruneAllButLastCommittedInternal(); 1252 PruneAllButLastCommittedInternal();
1252 1253
1253 // We now have one entry, possibly with a new pending entry. Ensure that 1254 // We now have one entry, possibly with a new pending entry. Ensure that
1254 // adding the entries from source won't put us over the limit. 1255 // adding the entries from source won't put us over the limit.
1255 DCHECK_EQ(1, GetEntryCount()); 1256 DCHECK_EQ(1, GetEntryCount());
1256 source->PruneOldestEntryIfFull(); 1257 if (!replace_entry)
1258 source->PruneOldestEntryIfFull();
1257 1259
1258 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as 1260 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as
1259 // we don't want to copy over the transient entry. Ignore any pending entry, 1261 // we don't want to copy over the transient entry. Ignore any pending entry,
1260 // since it has not committed in source. 1262 // since it has not committed in source.
1261 int max_source_index = source->last_committed_entry_index_; 1263 int max_source_index = source->last_committed_entry_index_;
1262 if (max_source_index == -1) 1264 if (max_source_index == -1)
1263 max_source_index = source->GetEntryCount(); 1265 max_source_index = source->GetEntryCount();
1264 else 1266 else
1265 max_source_index++; 1267 max_source_index++;
1268
1269 // Ignore the source's current entry if merging with replacement.
1270 // TODO(davidben): This should preserve entries forward of the current
1271 // too. http://crbug.com/317872
1272 if (replace_entry && max_source_index > 0)
1273 max_source_index--;
1274
1266 InsertEntriesFrom(*source, max_source_index); 1275 InsertEntriesFrom(*source, max_source_index);
1267 1276
1268 // Adjust indices such that the last entry and pending are at the end now. 1277 // Adjust indices such that the last entry and pending are at the end now.
1269 last_committed_entry_index_ = GetEntryCount() - 1; 1278 last_committed_entry_index_ = GetEntryCount() - 1;
1270 1279
1271 delegate_->SetHistoryLengthAndPrune(site_instance.get(), 1280 delegate_->SetHistoryLengthAndPrune(site_instance.get(),
1272 max_source_index, 1281 max_source_index,
1273 minimum_page_id); 1282 minimum_page_id);
1274 1283
1275 // Copy the max page id map from the old tab to the new tab. This ensures 1284 // Copy the max page id map from the old tab to the new tab. This ensures
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 } 1692 }
1684 } 1693 }
1685 } 1694 }
1686 1695
1687 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1696 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1688 const base::Callback<base::Time()>& get_timestamp_callback) { 1697 const base::Callback<base::Time()>& get_timestamp_callback) {
1689 get_timestamp_callback_ = get_timestamp_callback; 1698 get_timestamp_callback_ = get_timestamp_callback;
1690 } 1699 }
1691 1700
1692 } // namespace content 1701 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698