Chromium Code Reviews| 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_; |
| } |