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

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

Issue 7931027: Refactoring recently closed tab filtering (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Long live the STL 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
« no previous file with comments | « chrome/browser/sessions/session_utils.h ('k') | chrome/browser/sessions/session_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sessions/session_utils.cc
diff --git a/chrome/browser/sessions/session_utils.cc b/chrome/browser/sessions/session_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ae293c41e989b6012732d35242ae80f5429f24b
--- /dev/null
+++ b/chrome/browser/sessions/session_utils.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sessions/session_utils.h"
+
+#include <set>
+
+#include "chrome/browser/sessions/tab_restore_service.h"
+
+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) {
+ // 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);
+
+ 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();
+
+ return rh_entry.title() < lh_entry.title();
+ }
+};
+} // namespace
+
+void SessionUtils::FilteredEntries(const TabRestoreService::Entries& entries,
+ TabRestoreService::Entries* filtered_entries) {
+ // A set to remember the entries we already seen.
+ std::set<TabRestoreService::Entry*, EntryComparator> uniquing;
+
+ for (TabRestoreService::Entries::const_iterator iter = entries.begin();
+ iter != entries.end(); ++iter) {
+ TabRestoreService::Entry* entry = *iter;
+
+ if (uniquing.insert(entry).second)
+ // This entry was not seen before, add it to the list.
+ filtered_entries->push_back(entry);
+ }
+}
+
« no previous file with comments | « chrome/browser/sessions/session_utils.h ('k') | chrome/browser/sessions/session_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698