OLD | NEW |
---|---|
(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 // This class is used to compare two entries and considers that they are | |
sky
2011/09/20 16:24:46
newline between 11 and 12.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
| |
13 // identical if they share the same URL. See FilteredEntries() below for how | |
14 // this is used. | |
15 class EntryComparator { | |
sky
2011/09/20 16:24:46
this should not be indented.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
| |
16 public: | |
17 bool operator() (const TabRestoreService::Entry* lhs, | |
18 const TabRestoreService::Entry* rhs) { | |
19 // Two entries are deemed identical when their visible title and URL are | |
20 // the same. | |
21 if (lhs->type == TabRestoreService::WINDOW || | |
22 rhs->type == TabRestoreService::WINDOW) | |
23 return false; | |
24 | |
25 DCHECK(lhs->type == TabRestoreService::TAB); | |
26 DCHECK(rhs->type == TabRestoreService::TAB); | |
27 | |
28 const TabRestoreService::Tab* rh_tab = | |
29 static_cast<const TabRestoreService::Tab*>(rhs); | |
30 const TabRestoreService::Tab* lh_tab = | |
31 static_cast<const TabRestoreService::Tab*>(lhs); | |
32 | |
33 const TabNavigation& rh_entry = | |
34 rh_tab->navigations[rh_tab->current_navigation_index]; | |
35 const TabNavigation& lh_entry = | |
36 lh_tab->navigations[lh_tab->current_navigation_index]; | |
37 | |
38 if (rh_entry.title() == lh_entry.title()) | |
39 return rh_entry.virtual_url().spec() < lh_entry.virtual_url().spec(); | |
40 | |
41 return rh_entry.title() < lh_entry.title(); | |
42 } | |
43 }; | |
44 } // namespace | |
45 | |
46 void SessionUtils::FilteredEntries(TabRestoreService* service, | |
47 TabRestoreService::Entries* filteredTabs) { | |
48 // A set to remember the entries we already seen. | |
49 std::set<TabRestoreService::Entry*, EntryComparator> uniquing; | |
50 TabRestoreService::Entries entries = service->entries(); | |
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 filteredTabs->push_back(entry); | |
59 } | |
60 } | |
61 | |
OLD | NEW |