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

Unified Diff: chrome/browser/sessions/tab_restore_service.cc

Issue 7931027: Refactoring recently closed tab filtering (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 3 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/sessions/tab_restore_service.cc
diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc
index 7391612254b6de6ed577119aa4d8e6b93bd4d86e..59aec0ec73a11eb04c032c877d4b2b2fae6ef839 100644
--- a/chrome/browser/sessions/tab_restore_service.cc
+++ b/chrome/browser/sessions/tab_restore_service.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <iterator>
#include <map>
+#include <set>
#include "base/callback.h"
#include "base/memory/scoped_vector.h"
@@ -291,6 +292,57 @@ void TabRestoreService::ClearEntries() {
NotifyTabsChanged();
}
+namespace {
+// This class is used to compare two entries and considers that they are
+// identical if they share the same URL. See FilteredEntries() below for how
+// this is used.
+class EntryComparator {
+ public:
+ bool operator() (const TabRestoreService::Entry* lhs,
+ const TabRestoreService::Entry* rhs) const {
+ // Two entries are deemed identical when their visible title and URL are the
+ // same.
+ if (lhs->type == TabRestoreService::WINDOW ||
+ rhs->type == TabRestoreService::WINDOW)
+ return false;
+
+ DCHECK(lhs->type == TabRestoreService::TAB);
+ DCHECK(rhs->type == TabRestoreService::TAB);
+
sky 2011/09/19 16:23:15 remove one of these lines.
noyau (Ping after 24h) 2011/09/20 15:46:58 Done in session_utils.cc
+
+ const TabRestoreService::Tab* rh_tab =
+ static_cast<const TabRestoreService::Tab*>(rhs);
+ const TabRestoreService::Tab* lh_tab =
+ static_cast<const TabRestoreService::Tab*>(lhs);
+
+ const TabNavigation& rh_entry =
+ rh_tab->navigations[rh_tab->current_navigation_index];
+ const TabNavigation& lh_entry =
+ lh_tab->navigations[lh_tab->current_navigation_index];
+
+ if (rh_entry.title() == lh_entry.title())
+ return rh_entry.virtual_url().spec() < lh_entry.virtual_url().spec();
+ else
sky 2011/09/19 16:23:15 no else
noyau (Ping after 24h) 2011/09/20 15:46:58 Done in session_utils.cc
+ return rh_entry.title() < lh_entry.title();
+ }
+};
+} // namespace
+
+void TabRestoreService::FilteredEntries(
+ TabRestoreService::Entries* filteredEntries) const {
+ // A set to remember the entries we already seen.
+ std::set<Entry*, EntryComparator> uniquing;
+
+ TabRestoreService::Entries::const_iterator iter;
sky 2011/09/19 16:23:15 put iterator into for loop.
noyau (Ping after 24h) 2011/09/20 15:46:58 Done in session_utils.cc
+ for (iter = entries_.begin(); iter != entries_.end(); ++iter) {
+ Entry* entry = *iter;
+
+ if (uniquing.insert(entry).second)
+ // This entry was not seen before, add it to the list.
+ filteredEntries->push_back(entry);
+ }
+}
+
const TabRestoreService::Entries& TabRestoreService::entries() const {
return entries_;
}

Powered by Google App Engine
This is Rietveld 408576698