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

Unified Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 2815753003: Add DCHECKs for invariants on NavigationController indices. (Closed)
Patch Set: Add more invariants. Created 3 years, 8 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 | « no previous file | content/public/browser/navigation_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigation_controller_impl.cc
diff --git a/content/browser/frame_host/navigation_controller_impl.cc b/content/browser/frame_host/navigation_controller_impl.cc
index 768f595fac70a59363483b33f06821983b03fc60..fd0c5f527bdee4ebde7595b34a22e4b85573551c 100644
--- a/content/browser/frame_host/navigation_controller_impl.cc
+++ b/content/browser/frame_host/navigation_controller_impl.cc
@@ -534,11 +534,15 @@ bool NavigationControllerImpl::CanViewSource() const {
}
int NavigationControllerImpl::GetLastCommittedEntryIndex() const {
+ // The last committed entry index must always be less than the number of
+ // entries. It should be -1 iff there are no entries.
+ DCHECK_LT(last_committed_entry_index_, GetEntryCount());
+ DCHECK_EQ(last_committed_entry_index_ == -1, GetEntryCount() == 0);
return last_committed_entry_index_;
}
int NavigationControllerImpl::GetEntryCount() const {
- DCHECK(entries_.size() <= max_entry_count());
+ DCHECK_LE(entries_.size(), max_entry_count());
return static_cast<int>(entries_.size());
}
@@ -1726,10 +1730,22 @@ void NavigationControllerImpl::DiscardNonCommittedEntries() {
}
NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() const {
+ // If there is no pending_entry_, there should be no pending_entry_index_.
+ DCHECK(pending_entry_ || pending_entry_index_ == -1);
+
+ // If there is a pending_entry_index_, then pending_entry_ must be the entry
+ // at that index.
+ DCHECK(pending_entry_index_ == -1 ||
+ pending_entry_ == GetEntryAtIndex(pending_entry_index_));
+
return pending_entry_;
}
int NavigationControllerImpl::GetPendingEntryIndex() const {
+ // The pending entry index must always be less than the number of entries.
+ // If there are no entries, it must be exactly -1.
+ DCHECK_LT(pending_entry_index_, GetEntryCount());
+ DCHECK(GetEntryCount() != 0 || pending_entry_index_ == -1);
return pending_entry_index_;
}
« no previous file with comments | « no previous file | content/public/browser/navigation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698