OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/scoped_vector.h" | 12 #include "base/scoped_vector.h" |
13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
14 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
15 #include "chrome/browser/browser_window.h" | 15 #include "chrome/browser/browser_window.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
17 #include "chrome/browser/sessions/session_service.h" | 17 #include "chrome/browser/sessions/session_service.h" |
18 #include "chrome/browser/sessions/session_command.h" | 18 #include "chrome/browser/sessions/session_command.h" |
19 #include "chrome/browser/sessions/session_types.h" | 19 #include "chrome/browser/sessions/session_types.h" |
20 #include "chrome/browser/sessions/tab_restore_service_observer.h" | |
21 #include "chrome/browser/tab_contents/navigation_controller.h" | 20 #include "chrome/browser/tab_contents/navigation_controller.h" |
22 #include "chrome/browser/tab_contents/navigation_entry.h" | 21 #include "chrome/browser/tab_contents/navigation_entry.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
24 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
25 | 24 |
26 using base::Time; | 25 using base::Time; |
27 | 26 |
28 // TimeFactory----------------------------------------------------------------- | 27 // TimeFactory----------------------------------------------------------------- |
29 | 28 |
30 TabRestoreService::TimeFactory::~TimeFactory() {} | 29 TabRestoreService::TimeFactory::~TimeFactory() {} |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 reached_max_(false), | 175 reached_max_(false), |
177 entries_to_write_(0), | 176 entries_to_write_(0), |
178 entries_written_(0), | 177 entries_written_(0), |
179 time_factory_(time_factory) { | 178 time_factory_(time_factory) { |
180 } | 179 } |
181 | 180 |
182 TabRestoreService::~TabRestoreService() { | 181 TabRestoreService::~TabRestoreService() { |
183 if (backend()) | 182 if (backend()) |
184 Save(); | 183 Save(); |
185 | 184 |
186 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, | 185 FOR_EACH_OBSERVER(Observer, observer_list_, TabRestoreServiceDestroyed(this)); |
187 TabRestoreServiceDestroyed(this)); | |
188 STLDeleteElements(&entries_); | 186 STLDeleteElements(&entries_); |
189 STLDeleteElements(&staging_entries_); | 187 STLDeleteElements(&staging_entries_); |
190 time_factory_ = NULL; | 188 time_factory_ = NULL; |
191 } | 189 } |
192 | 190 |
193 void TabRestoreService::AddObserver(TabRestoreServiceObserver* observer) { | 191 void TabRestoreService::AddObserver(Observer* observer) { |
194 observer_list_.AddObserver(observer); | 192 observer_list_.AddObserver(observer); |
195 } | 193 } |
196 | 194 |
197 void TabRestoreService::RemoveObserver(TabRestoreServiceObserver* observer) { | 195 void TabRestoreService::RemoveObserver(Observer* observer) { |
198 observer_list_.RemoveObserver(observer); | 196 observer_list_.RemoveObserver(observer); |
199 } | 197 } |
200 | 198 |
201 void TabRestoreService::CreateHistoricalTab(NavigationController* tab) { | 199 void TabRestoreService::CreateHistoricalTab(NavigationController* tab) { |
202 if (restoring_) | 200 if (restoring_) |
203 return; | 201 return; |
204 | 202 |
205 Browser* browser = Browser::GetBrowserForController(tab, NULL); | 203 Browser* browser = Browser::GetBrowserForController(tab, NULL); |
206 if (closing_browsers_.find(browser) != closing_browsers_.end()) | 204 if (closing_browsers_.find(browser) != closing_browsers_.end()) |
207 return; | 205 return; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // Browser may be NULL during unit tests. | 477 // Browser may be NULL during unit tests. |
480 if (browser) { | 478 if (browser) { |
481 tab->browser_id = browser->session_id().id(); | 479 tab->browser_id = browser->session_id().id(); |
482 tab->tabstrip_index = | 480 tab->tabstrip_index = |
483 browser->tabstrip_model()->GetIndexOfController(controller); | 481 browser->tabstrip_model()->GetIndexOfController(controller); |
484 tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index); | 482 tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index); |
485 } | 483 } |
486 } | 484 } |
487 | 485 |
488 void TabRestoreService::NotifyTabsChanged() { | 486 void TabRestoreService::NotifyTabsChanged() { |
489 FOR_EACH_OBSERVER(TabRestoreServiceObserver, observer_list_, | 487 FOR_EACH_OBSERVER(Observer, observer_list_, TabRestoreServiceChanged(this)); |
490 TabRestoreServiceChanged(this)); | |
491 } | 488 } |
492 | 489 |
493 void TabRestoreService::AddEntry(Entry* entry, bool notify, bool to_front) { | 490 void TabRestoreService::AddEntry(Entry* entry, bool notify, bool to_front) { |
494 if (to_front) | 491 if (to_front) |
495 entries_.push_front(entry); | 492 entries_.push_front(entry); |
496 else | 493 else |
497 entries_.push_back(entry); | 494 entries_.push_back(entry); |
498 if (notify) | 495 if (notify) |
499 PruneAndNotify(); | 496 PruneAndNotify(); |
500 // Start the save timer, when it fires we'll generate the commands. | 497 // Start the save timer, when it fires we'll generate the commands. |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 // correctly write out the entries when Save is invoked (Save starts from | 1047 // correctly write out the entries when Save is invoked (Save starts from |
1051 // the front, not the end and we just added the entries to the end). | 1048 // the front, not the end and we just added the entries to the end). |
1052 entries_to_write_ = staging_entries_.size(); | 1049 entries_to_write_ = staging_entries_.size(); |
1053 | 1050 |
1054 PruneAndNotify(); | 1051 PruneAndNotify(); |
1055 } | 1052 } |
1056 | 1053 |
1057 Time TabRestoreService::TimeNow() const { | 1054 Time TabRestoreService::TimeNow() const { |
1058 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1055 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
1059 } | 1056 } |
OLD | NEW |