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

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

Issue 9565045: Ensure that CopyStateFromAndPrune doesn't exceed kMaxSessionHistoryEntries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial CL. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tab_contents/navigation_controller_impl.h" 5 #include "content/browser/tab_contents/navigation_controller_impl.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" // Temporary 9 #include "base/string_number_conversions.h" // Temporary
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 NavigationEntry* active_entry = GetActiveEntry(); 405 NavigationEntry* active_entry = GetActiveEntry();
406 return active_entry && !active_entry->IsViewSourceMode() && 406 return active_entry && !active_entry->IsViewSourceMode() &&
407 is_supported_mime_type && !tab_contents_->GetInterstitialPage(); 407 is_supported_mime_type && !tab_contents_->GetInterstitialPage();
408 } 408 }
409 409
410 int NavigationControllerImpl::GetLastCommittedEntryIndex() const { 410 int NavigationControllerImpl::GetLastCommittedEntryIndex() const {
411 return last_committed_entry_index_; 411 return last_committed_entry_index_;
412 } 412 }
413 413
414 int NavigationControllerImpl::GetEntryCount() const { 414 int NavigationControllerImpl::GetEntryCount() const {
415 DCHECK(entries_.size() <= max_entry_count());
Charlie Reis 2012/03/02 02:37:12 This would have caught the bug in the first place,
415 return static_cast<int>(entries_.size()); 416 return static_cast<int>(entries_.size());
416 } 417 }
417 418
418 NavigationEntry* NavigationControllerImpl::GetEntryAtIndex( 419 NavigationEntry* NavigationControllerImpl::GetEntryAtIndex(
419 int index) const { 420 int index) const {
420 return entries_.at(index).get(); 421 return entries_.at(index).get();
421 } 422 }
422 423
423 NavigationEntry* NavigationControllerImpl::GetEntryAtOffset( 424 NavigationEntry* NavigationControllerImpl::GetEntryAtOffset(
424 int offset) const { 425 int offset) const {
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 DCHECK( 1071 DCHECK(
1071 (transient_entry_index_ != -1 && 1072 (transient_entry_index_ != -1 &&
1072 transient_entry_index_ == GetEntryCount() - 1) || 1073 transient_entry_index_ == GetEntryCount() - 1) ||
1073 (pending_entry_ && (pending_entry_index_ == -1 || 1074 (pending_entry_ && (pending_entry_index_ == -1 ||
1074 pending_entry_index_ == GetEntryCount() - 1)) || 1075 pending_entry_index_ == GetEntryCount() - 1)) ||
1075 (!pending_entry_ && last_committed_entry_index_ == GetEntryCount() - 1)); 1076 (!pending_entry_ && last_committed_entry_index_ == GetEntryCount() - 1));
1076 1077
1077 // Remove all the entries leaving the active entry. 1078 // Remove all the entries leaving the active entry.
1078 PruneAllButActive(); 1079 PruneAllButActive();
1079 1080
1081 // Ensure that adding the entries from source won't put us over the limit,
1082 // if we have an entry to keep.
1083 if (GetEntryCount() > 0)
cbentzel 2012/03/02 16:47:36 You should DCHECK that GetEntryCount is only 0 or
Charlie Reis 2012/03/02 17:48:24 Done.
1084 source->PruneFirstEntryIfFull();
1085
1080 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as 1086 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as
1081 // we don't want to copy over the transient entry. 1087 // we don't want to copy over the transient entry.
1082 int max_source_index = source->pending_entry_index_ != -1 ? 1088 int max_source_index = source->pending_entry_index_ != -1 ?
1083 source->pending_entry_index_ : source->last_committed_entry_index_; 1089 source->pending_entry_index_ : source->last_committed_entry_index_;
1084 if (max_source_index == -1) 1090 if (max_source_index == -1)
1085 max_source_index = source->GetEntryCount(); 1091 max_source_index = source->GetEntryCount();
1086 else 1092 else
1087 max_source_index++; 1093 max_source_index++;
1088 InsertEntriesFrom(*source, max_source_index); 1094 InsertEntriesFrom(*source, max_source_index);
1089 1095
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 int num_pruned = 0; 1236 int num_pruned = 0;
1231 while (last_committed_entry_index_ < (current_size - 1)) { 1237 while (last_committed_entry_index_ < (current_size - 1)) {
1232 num_pruned++; 1238 num_pruned++;
1233 entries_.pop_back(); 1239 entries_.pop_back();
1234 current_size--; 1240 current_size--;
1235 } 1241 }
1236 if (num_pruned > 0) // Only notify if we did prune something. 1242 if (num_pruned > 0) // Only notify if we did prune something.
1237 NotifyPrunedEntries(this, false, num_pruned); 1243 NotifyPrunedEntries(this, false, num_pruned);
1238 } 1244 }
1239 1245
1240 if (entries_.size() >= max_entry_count()) { 1246 PruneFirstEntryIfFull();
1241 DCHECK(last_committed_entry_index_ > 0);
1242 RemoveEntryAtIndex(0);
1243 NotifyPrunedEntries(this, true, 1);
1244 }
1245 1247
1246 entries_.push_back(linked_ptr<NavigationEntryImpl>(entry)); 1248 entries_.push_back(linked_ptr<NavigationEntryImpl>(entry));
1247 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; 1249 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1;
1248 1250
1249 // This is a new page ID, so we need everybody to know about it. 1251 // This is a new page ID, so we need everybody to know about it.
1250 tab_contents_->UpdateMaxPageID(entry->GetPageID()); 1252 tab_contents_->UpdateMaxPageID(entry->GetPageID());
1251 } 1253 }
1252 1254
1255 void NavigationControllerImpl::PruneFirstEntryIfFull() {
1256 if (entries_.size() >= max_entry_count()) {
1257 DCHECK_EQ(max_entry_count(), entries_.size());
1258 DCHECK(last_committed_entry_index_ > 0);
1259 RemoveEntryAtIndex(0);
1260 NotifyPrunedEntries(this, true, 1);
1261 }
1262 }
1263
1253 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { 1264 void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) {
1254 needs_reload_ = false; 1265 needs_reload_ = false;
1255 1266
1256 // If we were navigating to a slow-to-commit page, and the user performs 1267 // If we were navigating to a slow-to-commit page, and the user performs
1257 // a session history navigation to the last committed page, RenderViewHost 1268 // a session history navigation to the last committed page, RenderViewHost
1258 // will force the throbber to start, but WebKit will essentially ignore the 1269 // will force the throbber to start, but WebKit will essentially ignore the
1259 // navigation, and won't send a message to stop the throbber. To prevent this 1270 // navigation, and won't send a message to stop the throbber. To prevent this
1260 // from happening, we drop the navigation here and stop the slow-to-commit 1271 // from happening, we drop the navigation here and stop the slow-to-commit
1261 // page from loading (which would normally happen during the navigation). 1272 // page from loading (which would normally happen during the navigation).
1262 if (pending_entry_index_ != -1 && 1273 if (pending_entry_index_ != -1 &&
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 for (int i = 0; i < max_index; i++) { 1425 for (int i = 0; i < max_index; i++) {
1415 // When cloning a tab, copy all entries except interstitial pages 1426 // When cloning a tab, copy all entries except interstitial pages
1416 if (source.entries_[i].get()->GetPageType() != 1427 if (source.entries_[i].get()->GetPageType() !=
1417 content::PAGE_TYPE_INTERSTITIAL) { 1428 content::PAGE_TYPE_INTERSTITIAL) {
1418 entries_.insert(entries_.begin() + insert_index++, 1429 entries_.insert(entries_.begin() + insert_index++,
1419 linked_ptr<NavigationEntryImpl>( 1430 linked_ptr<NavigationEntryImpl>(
1420 new NavigationEntryImpl(*source.entries_[i]))); 1431 new NavigationEntryImpl(*source.entries_[i])));
1421 } 1432 }
1422 } 1433 }
1423 } 1434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698