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

Side by Side Diff: chrome/browser/sessions/tab_restore_service.cc

Issue 7931027: Refactoring recently closed tab filtering (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sessions/tab_restore_service.h" 5 #include "chrome/browser/sessions/tab_restore_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <set>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_tab_helper.h" 17 #include "chrome/browser/extensions/extension_tab_helper.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sessions/session_service.h" 19 #include "chrome/browser/sessions/session_service.h"
19 #include "chrome/browser/sessions/session_service_factory.h" 20 #include "chrome/browser/sessions/session_service_factory.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 set_pending_reset(true); 285 set_pending_reset(true);
285 286
286 // Schedule a command, otherwise if there are no pending commands Save does 287 // Schedule a command, otherwise if there are no pending commands Save does
287 // nothing. 288 // nothing.
288 ScheduleCommand(CreateRestoredEntryCommand(1)); 289 ScheduleCommand(CreateRestoredEntryCommand(1));
289 290
290 STLDeleteElements(&entries_); 291 STLDeleteElements(&entries_);
291 NotifyTabsChanged(); 292 NotifyTabsChanged();
292 } 293 }
293 294
295 namespace {
296 // This class is used to compare two entries and considers that they are
297 // identical if they share the same URL. See FilteredEntries() below for how
298 // this is used.
299 class EntryComparator {
300 public:
301 bool operator() (const TabRestoreService::Entry* lhs,
302 const TabRestoreService::Entry* rhs) const {
303 // Two entries are deemed identical when their visible title and URL are the
304 // same.
305 if (lhs->type == TabRestoreService::WINDOW ||
306 rhs->type == TabRestoreService::WINDOW)
307 return false;
308
309 DCHECK(lhs->type == TabRestoreService::TAB);
310 DCHECK(rhs->type == TabRestoreService::TAB);
311
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
312
313 const TabRestoreService::Tab* rh_tab =
314 static_cast<const TabRestoreService::Tab*>(rhs);
315 const TabRestoreService::Tab* lh_tab =
316 static_cast<const TabRestoreService::Tab*>(lhs);
317
318 const TabNavigation& rh_entry =
319 rh_tab->navigations[rh_tab->current_navigation_index];
320 const TabNavigation& lh_entry =
321 lh_tab->navigations[lh_tab->current_navigation_index];
322
323 if (rh_entry.title() == lh_entry.title())
324 return rh_entry.virtual_url().spec() < lh_entry.virtual_url().spec();
325 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
326 return rh_entry.title() < lh_entry.title();
327 }
328 };
329 } // namespace
330
331 void TabRestoreService::FilteredEntries(
332 TabRestoreService::Entries* filteredEntries) const {
333 // A set to remember the entries we already seen.
334 std::set<Entry*, EntryComparator> uniquing;
335
336 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
337 for (iter = entries_.begin(); iter != entries_.end(); ++iter) {
338 Entry* entry = *iter;
339
340 if (uniquing.insert(entry).second)
341 // This entry was not seen before, add it to the list.
342 filteredEntries->push_back(entry);
343 }
344 }
345
294 const TabRestoreService::Entries& TabRestoreService::entries() const { 346 const TabRestoreService::Entries& TabRestoreService::entries() const {
295 return entries_; 347 return entries_;
296 } 348 }
297 349
298 void TabRestoreService::RestoreMostRecentEntry( 350 void TabRestoreService::RestoreMostRecentEntry(
299 TabRestoreServiceDelegate* delegate) { 351 TabRestoreServiceDelegate* delegate) {
300 if (entries_.empty()) 352 if (entries_.empty())
301 return; 353 return;
302 354
303 RestoreEntryById(delegate, entries_.front()->id, false); 355 RestoreEntryById(delegate, entries_.front()->id, false);
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 // correctly write out the entries when Save is invoked (Save starts from 1137 // correctly write out the entries when Save is invoked (Save starts from
1086 // the front, not the end and we just added the entries to the end). 1138 // the front, not the end and we just added the entries to the end).
1087 entries_to_write_ = staging_entries_.size(); 1139 entries_to_write_ = staging_entries_.size();
1088 1140
1089 PruneAndNotify(); 1141 PruneAndNotify();
1090 } 1142 }
1091 1143
1092 Time TabRestoreService::TimeNow() const { 1144 Time TabRestoreService::TimeNow() const {
1093 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); 1145 return time_factory_ ? time_factory_->TimeNow() : Time::Now();
1094 } 1146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698