| 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/tab_contents/navigation_controller.h" | 20 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 21 #include "chrome/browser/tab_contents/navigation_entry.h" | 21 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 22 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
| 23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 24 | 24 |
| 25 using base::Time; | 25 using base::Time; |
| 26 | 26 |
| 27 // TimeFactory----------------------------------------------------------------- |
| 28 |
| 29 TabRestoreService::TimeFactory::~TimeFactory() {} |
| 30 |
| 27 // Entry ---------------------------------------------------------------------- | 31 // Entry ---------------------------------------------------------------------- |
| 28 | 32 |
| 29 // ID of the next Entry. | 33 // ID of the next Entry. |
| 30 static SessionID::id_type next_entry_id = 1; | 34 static SessionID::id_type next_entry_id = 1; |
| 31 | 35 |
| 32 TabRestoreService::Entry::Entry() | 36 TabRestoreService::Entry::Entry() |
| 33 : id(next_entry_id++), | 37 : id(next_entry_id++), |
| 34 type(TAB), | 38 type(TAB), |
| 35 from_last_session(false) {} | 39 from_last_session(false) {} |
| 36 | 40 |
| 37 TabRestoreService::Entry::Entry(Type type) | 41 TabRestoreService::Entry::Entry(Type type) |
| 38 : id(next_entry_id++), | 42 : id(next_entry_id++), |
| 39 type(type), | 43 type(type), |
| 40 from_last_session(false) {} | 44 from_last_session(false) {} |
| 41 | 45 |
| 46 TabRestoreService::Entry::~Entry() {} |
| 47 |
| 42 // TabRestoreService ---------------------------------------------------------- | 48 // TabRestoreService ---------------------------------------------------------- |
| 43 | 49 |
| 44 // static | 50 // static |
| 45 const size_t TabRestoreService::kMaxEntries = 10; | 51 const size_t TabRestoreService::kMaxEntries = 10; |
| 46 | 52 |
| 47 // Identifier for commands written to file. | 53 // Identifier for commands written to file. |
| 48 // The ordering in the file is as follows: | 54 // The ordering in the file is as follows: |
| 49 // . When the user closes a tab a command of type | 55 // . When the user closes a tab a command of type |
| 50 // kCommandSelectedNavigationInTab is written identifying the tab and | 56 // kCommandSelectedNavigationInTab is written identifying the tab and |
| 51 // the selected index, then a kCommandPinnedState command if the tab was | 57 // the selected index, then a kCommandPinnedState command if the tab was |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } // namespace | 150 } // namespace |
| 145 | 151 |
| 146 TabRestoreService::Tab::Tab() | 152 TabRestoreService::Tab::Tab() |
| 147 : Entry(TAB), | 153 : Entry(TAB), |
| 148 current_navigation_index(-1), | 154 current_navigation_index(-1), |
| 149 browser_id(0), | 155 browser_id(0), |
| 150 tabstrip_index(-1), | 156 tabstrip_index(-1), |
| 151 pinned(false) { | 157 pinned(false) { |
| 152 } | 158 } |
| 153 | 159 |
| 160 TabRestoreService::Tab::~Tab() { |
| 161 } |
| 162 |
| 154 TabRestoreService::Window::Window() : Entry(WINDOW), selected_tab_index(-1) { | 163 TabRestoreService::Window::Window() : Entry(WINDOW), selected_tab_index(-1) { |
| 155 } | 164 } |
| 156 | 165 |
| 166 TabRestoreService::Window::~Window() { |
| 167 } |
| 168 |
| 157 TabRestoreService::TabRestoreService(Profile* profile, | 169 TabRestoreService::TabRestoreService(Profile* profile, |
| 158 TabRestoreService::TimeFactory* time_factory) | 170 TabRestoreService::TimeFactory* time_factory) |
| 159 : BaseSessionService(BaseSessionService::TAB_RESTORE, profile, | 171 : BaseSessionService(BaseSessionService::TAB_RESTORE, profile, |
| 160 FilePath()), | 172 FilePath()), |
| 161 load_state_(NOT_LOADED), | 173 load_state_(NOT_LOADED), |
| 162 restoring_(false), | 174 restoring_(false), |
| 163 reached_max_(false), | 175 reached_max_(false), |
| 164 entries_to_write_(0), | 176 entries_to_write_(0), |
| 165 entries_written_(0), | 177 entries_written_(0), |
| 166 time_factory_(time_factory) { | 178 time_factory_(time_factory) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 set_pending_reset(true); | 265 set_pending_reset(true); |
| 254 | 266 |
| 255 // Schedule a command, otherwise if there are no pending commands Save does | 267 // Schedule a command, otherwise if there are no pending commands Save does |
| 256 // nothing. | 268 // nothing. |
| 257 ScheduleCommand(CreateRestoredEntryCommand(1)); | 269 ScheduleCommand(CreateRestoredEntryCommand(1)); |
| 258 | 270 |
| 259 STLDeleteElements(&entries_); | 271 STLDeleteElements(&entries_); |
| 260 NotifyTabsChanged(); | 272 NotifyTabsChanged(); |
| 261 } | 273 } |
| 262 | 274 |
| 275 const TabRestoreService::Entries& TabRestoreService::entries() const { |
| 276 return entries_; |
| 277 } |
| 278 |
| 263 void TabRestoreService::RestoreMostRecentEntry(Browser* browser) { | 279 void TabRestoreService::RestoreMostRecentEntry(Browser* browser) { |
| 264 if (entries_.empty()) | 280 if (entries_.empty()) |
| 265 return; | 281 return; |
| 266 | 282 |
| 267 RestoreEntryById(browser, entries_.front()->id, false); | 283 RestoreEntryById(browser, entries_.front()->id, false); |
| 268 } | 284 } |
| 269 | 285 |
| 270 void TabRestoreService::RestoreEntryById(Browser* browser, | 286 void TabRestoreService::RestoreEntryById(Browser* browser, |
| 271 SessionID::id_type id, | 287 SessionID::id_type id, |
| 272 bool replace_existing_tab) { | 288 bool replace_existing_tab) { |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 // correctly write out the entries when Save is invoked (Save starts from | 1046 // correctly write out the entries when Save is invoked (Save starts from |
| 1031 // the front, not the end and we just added the entries to the end). | 1047 // the front, not the end and we just added the entries to the end). |
| 1032 entries_to_write_ = staging_entries_.size(); | 1048 entries_to_write_ = staging_entries_.size(); |
| 1033 | 1049 |
| 1034 PruneAndNotify(); | 1050 PruneAndNotify(); |
| 1035 } | 1051 } |
| 1036 | 1052 |
| 1037 Time TabRestoreService::TimeNow() const { | 1053 Time TabRestoreService::TimeNow() const { |
| 1038 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1054 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
| 1039 } | 1055 } |
| OLD | NEW |