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

Unified Diff: chrome/browser/android/tab_state.cc

Issue 2802213002: Simplify WebContentsState::GetContentsStateAsByteBuffer (Closed)
Patch Set: 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/tab_state.cc
diff --git a/chrome/browser/android/tab_state.cc b/chrome/browser/android/tab_state.cc
index b3547a251ce1c89d51214178aaf7b8daa892885e..d79661332806b67620c7efd97c7c7f718a090d50 100644
--- a/chrome/browser/android/tab_state.cc
+++ b/chrome/browser/android/tab_state.cc
@@ -286,37 +286,31 @@ bool ExtractNavigationEntries(
}; // anonymous namespace
ScopedJavaLocalRef<jobject> WebContentsState::GetContentsStateAsByteBuffer(
- JNIEnv* env, TabAndroid* tab) {
+ JNIEnv* env,
+ TabAndroid* tab) {
Profile* profile = tab->GetProfile();
if (!profile)
return ScopedJavaLocalRef<jobject>();
content::NavigationController& controller =
tab->web_contents()->GetController();
+ const int entry_count = controller.GetEntryCount();
+ const int current_index = controller.GetLastCommittedEntryIndex();
const int pending_index = controller.GetPendingEntryIndex();
- int entry_count = controller.GetEntryCount();
- if (entry_count == 0 && pending_index == 0)
- entry_count++;
+ DCHECK(current_index < entry_count);
+ DCHECK(pending_index < entry_count);
if (entry_count == 0)
return ScopedJavaLocalRef<jobject>();
- int current_entry = controller.GetLastCommittedEntryIndex();
- if (current_entry == -1 && entry_count > 0)
- current_entry = 0;
-
std::vector<content::NavigationEntry*> navigations(entry_count);
for (int i = 0; i < entry_count; ++i) {
- content::NavigationEntry* entry = (i == pending_index) ?
- controller.GetPendingEntry() : controller.GetEntryAtIndex(i);
- navigations[i] = entry;
+ navigations[i] = (i == pending_index) ? controller.GetPendingEntry()
Eugene But (OOO till 7-30) 2017/04/07 15:21:07 I was under impression that if |i == pending_index
arthursonzogni 2017/04/10 08:16:35 It would have been nice if the code could be simpl
+ : controller.GetEntryAtIndex(i);
}
return WebContentsState::WriteNavigationsAsByteBuffer(
- env,
- profile->IsOffTheRecord(),
- navigations,
- current_entry);
+ env, profile->IsOffTheRecord(), navigations, current_index);
}
// Common implementation for GetContentsStateAsByteBuffer() and
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698