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

Unified Diff: chrome/browser/ui/cocoa/history_menu_bridge.mm

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/ui/cocoa/history_menu_bridge.mm
diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm
index 82ac3853c6eb2becf5fd4f9750b4dc760498e5c8..2de3d122443dd374e177b5862e32bd82bab7f839 100644
--- a/chrome/browser/ui/cocoa/history_menu_bridge.mm
+++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm
@@ -137,16 +137,15 @@ void HistoryMenuBridge::TabRestoreServiceChanged(
NSInteger index = [menu indexOfItemWithTag:kRecentlyClosedTitle] + 1;
NSUInteger added_count = 0;
- for (sessions::TabRestoreService::Entries::const_iterator it =
- entries.begin();
- it != entries.end() && added_count < kRecentlyClosedCount; ++it) {
- sessions::TabRestoreService::Entry* entry = *it;
-
+ for (const auto& entry : entries) {
+ if (added_count >= kRecentlyClosedCount)
+ break;
// If this is a window, create a submenu for all of its tabs.
if (entry->type == sessions::TabRestoreService::WINDOW) {
- sessions::TabRestoreService::Window* entry_win =
- (sessions::TabRestoreService::Window*)entry;
- std::vector<sessions::TabRestoreService::Tab>& tabs = entry_win->tabs;
+ const auto* entry_win =
+ static_cast<sessions::TabRestoreService::Window*>(entry.get());
+ const std::vector<std::unique_ptr<sessions::TabRestoreService::Tab>>&
+ tabs = entry_win->tabs;
if (tabs.empty())
continue;
@@ -178,9 +177,8 @@ void HistoryMenuBridge::TabRestoreServiceChanged(
// Loop over the window's tabs and add them to the submenu.
NSInteger subindex = [[submenu itemArray] count];
- std::vector<sessions::TabRestoreService::Tab>::const_iterator it;
- for (it = tabs.begin(); it != tabs.end(); ++it) {
- HistoryItem* tab_item = HistoryItemForTab(*it);
+ for (const auto& tab : tabs) {
+ HistoryItem* tab_item = HistoryItemForTab(*tab);
if (tab_item) {
item->tabs.push_back(tab_item);
AddItemToMenu(tab_item, submenu.get(), kRecentlyClosed + 1,
@@ -203,9 +201,8 @@ void HistoryMenuBridge::TabRestoreServiceChanged(
++added_count;
}
} else if (entry->type == sessions::TabRestoreService::TAB) {
- sessions::TabRestoreService::Tab* tab =
- static_cast<sessions::TabRestoreService::Tab*>(entry);
- HistoryItem* item = HistoryItemForTab(*tab);
+ const auto& tab = static_cast<sessions::TabRestoreService::Tab&>(*entry);
+ HistoryItem* item = HistoryItemForTab(tab);
if (item) {
AddItemToMenu(item, menu, kRecentlyClosed, index++);
++added_count;

Powered by Google App Engine
This is Rietveld 408576698