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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sessions/session_utils.h"
6
7 #include <set>
8
9 #include "chrome/browser/sessions/tab_restore_service.h"
10
11 namespace {
12
13 // This class is used to compare two entries and considers that they are
14 // identical if they share the same URL. See FilteredEntries() below for how
15 // this is used.
16 class EntryComparator {
17 public:
18 bool operator() (const TabRestoreService::Entry* lhs,
19 const TabRestoreService::Entry* rhs) {
20 // Two entries are deemed identical when their visible title and URL are
21 // the same.
22 if (lhs->type == TabRestoreService::WINDOW ||
23 rhs->type == TabRestoreService::WINDOW)
24 return false;
25
26 DCHECK(lhs->type == TabRestoreService::TAB);
27 DCHECK(rhs->type == TabRestoreService::TAB);
28
29 const TabRestoreService::Tab* rh_tab =
30 static_cast<const TabRestoreService::Tab*>(rhs);
31 const TabRestoreService::Tab* lh_tab =
32 static_cast<const TabRestoreService::Tab*>(lhs);
33
34 const TabNavigation& rh_entry =
35 rh_tab->navigations[rh_tab->current_navigation_index];
36 const TabNavigation& lh_entry =
37 lh_tab->navigations[lh_tab->current_navigation_index];
38
39 if (rh_entry.title() == lh_entry.title())
40 return rh_entry.virtual_url().spec() < lh_entry.virtual_url().spec();
41
42 return rh_entry.title() < lh_entry.title();
43 }
44 };
45 } // namespace
46
47 void SessionUtils::FilteredEntries(const TabRestoreService::Entries& entries,
48 TabRestoreService::Entries* filtered_entries) {
49 // A set to remember the entries we already seen.
50 std::set<TabRestoreService::Entry*, EntryComparator> uniquing;
51
52 for (TabRestoreService::Entries::const_iterator iter = entries.begin();
53 iter != entries.end(); ++iter) {
54 TabRestoreService::Entry* entry = *iter;
55
56 if (uniquing.insert(entry).second)
57 // This entry was not seen before, add it to the list.
58 filtered_entries->push_back(entry);
59 }
60 }
61
OLDNEW
« 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