Chromium Code Reviews| 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..b62b55bcee34392ea877bcea6e34c2697afdd94d |
| --- /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 |
|
sky
2011/09/20 16:24:46
newline between 11 and 12.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + // identical if they share the same URL. See FilteredEntries() below for how |
| + // this is used. |
| + 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.
|
| + 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(TabRestoreService* service, |
| + TabRestoreService::Entries* filteredTabs) { |
| + // A set to remember the entries we already seen. |
| + std::set<TabRestoreService::Entry*, EntryComparator> uniquing; |
| + TabRestoreService::Entries entries = service->entries(); |
| + |
| + 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. |
| + filteredTabs->push_back(entry); |
| + } |
| +} |
| + |