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