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

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

Issue 2200993004: Make TabRestoreService::Entry noncopyable and fix up surrounding code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-test-cleanup
Patch Set: Eliminate a use-after-free, Windows build fix Created 4 years, 4 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
Index: chrome/browser/android/recently_closed_tabs_bridge.cc
diff --git a/chrome/browser/android/recently_closed_tabs_bridge.cc b/chrome/browser/android/recently_closed_tabs_bridge.cc
index 59bdd1b87d2cab06566df0beb821c8d15418fddf..97537ebc337ce903cd1b83a3fc1136b8732fbc75 100644
--- a/chrome/browser/android/recently_closed_tabs_bridge.cc
+++ b/chrome/browser/android/recently_closed_tabs_bridge.cc
@@ -24,14 +24,12 @@ using base::android::ScopedJavaLocalRef;
namespace {
void AddTabToList(JNIEnv* env,
- sessions::TabRestoreService::Entry* entry,
+ const sessions::TabRestoreService::Tab& tab,
jobject jtabs_list) {
- const sessions::TabRestoreService::Tab* tab =
- static_cast<sessions::TabRestoreService::Tab*>(entry);
const sessions::SerializedNavigationEntry& current_navigation =
- tab->navigations.at(tab->current_navigation_index);
+ tab.navigations.at(tab.current_navigation_index);
Java_RecentlyClosedBridge_pushTab(
- env, jtabs_list, entry->id,
+ env, jtabs_list, tab.id,
ConvertUTF16ToJavaString(env, current_navigation.title()).obj(),
ConvertUTF8ToJavaString(env, current_navigation.virtual_url().spec())
.obj());
@@ -42,14 +40,13 @@ void AddTabsToList(JNIEnv* env,
jobject jtabs_list,
int max_tab_count) {
int added_count = 0;
- for (sessions::TabRestoreService::Entries::const_iterator it =
- entries.begin();
- it != entries.end() && added_count < max_tab_count; ++it) {
- sessions::TabRestoreService::Entry* entry = *it;
+ for (const auto& entry : entries) {
DCHECK_EQ(entry->type, sessions::TabRestoreService::TAB);
if (entry->type == sessions::TabRestoreService::TAB) {
- AddTabToList(env, entry, jtabs_list);
- ++added_count;
+ auto& tab = static_cast<const sessions::TabRestoreService::Tab&>(*entry);
+ AddTabToList(env, tab, jtabs_list);
+ if (++added_count == max_tab_count)
+ break;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698