| OLD | NEW |
| 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 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_tab_helper.h" | 16 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/session_service.h" | 18 #include "chrome/browser/sessions/session_service.h" |
| 19 #include "chrome/browser/sessions/session_service_factory.h" |
| 19 #include "chrome/browser/sessions/session_command.h" | 20 #include "chrome/browser/sessions/session_command.h" |
| 20 #include "chrome/browser/sessions/session_types.h" | 21 #include "chrome/browser/sessions/session_types.h" |
| 21 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 22 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
| 22 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 23 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "content/browser/tab_contents/navigation_controller.h" | 27 #include "content/browser/tab_contents/navigation_controller.h" |
| 27 #include "content/browser/tab_contents/navigation_entry.h" | 28 #include "content/browser/tab_contents/navigation_entry.h" |
| 28 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 restoring_ = false; | 414 restoring_ = false; |
| 414 NotifyTabsChanged(); | 415 NotifyTabsChanged(); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void TabRestoreService::LoadTabsFromLastSession() { | 418 void TabRestoreService::LoadTabsFromLastSession() { |
| 418 if (load_state_ != NOT_LOADED || reached_max_) | 419 if (load_state_ != NOT_LOADED || reached_max_) |
| 419 return; | 420 return; |
| 420 | 421 |
| 421 load_state_ = LOADING; | 422 load_state_ = LOADING; |
| 422 | 423 |
| 424 SessionService* session_service = |
| 425 SessionServiceFactory::GetForProfile(profile()); |
| 423 if (!profile()->restored_last_session() && | 426 if (!profile()->restored_last_session() && |
| 424 !profile()->DidLastSessionExitCleanly() && | 427 !profile()->DidLastSessionExitCleanly() && |
| 425 profile()->GetSessionService()) { | 428 session_service) { |
| 426 // The previous session crashed and wasn't restored. Load the tabs/windows | 429 // The previous session crashed and wasn't restored. Load the tabs/windows |
| 427 // that were open at the point of crash from the session service. | 430 // that were open at the point of crash from the session service. |
| 428 profile()->GetSessionService()->GetLastSession( | 431 session_service->GetLastSession(&load_consumer_, |
| 429 &load_consumer_, | |
| 430 NewCallback(this, &TabRestoreService::OnGotPreviousSession)); | 432 NewCallback(this, &TabRestoreService::OnGotPreviousSession)); |
| 431 } else { | 433 } else { |
| 432 load_state_ |= LOADED_LAST_SESSION; | 434 load_state_ |= LOADED_LAST_SESSION; |
| 433 } | 435 } |
| 434 | 436 |
| 435 // Request the tabs closed in the last session. If the last session crashed, | 437 // Request the tabs closed in the last session. If the last session crashed, |
| 436 // this won't contain the tabs/window that were open at the point of the | 438 // this won't contain the tabs/window that were open at the point of the |
| 437 // crash (the call to GetLastSession above requests those). | 439 // crash (the call to GetLastSession above requests those). |
| 438 ScheduleGetLastSessionCommands( | 440 ScheduleGetLastSessionCommands( |
| 439 new InternalGetCommandsRequest( | 441 new InternalGetCommandsRequest( |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 // correctly write out the entries when Save is invoked (Save starts from | 1085 // correctly write out the entries when Save is invoked (Save starts from |
| 1084 // the front, not the end and we just added the entries to the end). | 1086 // the front, not the end and we just added the entries to the end). |
| 1085 entries_to_write_ = staging_entries_.size(); | 1087 entries_to_write_ = staging_entries_.size(); |
| 1086 | 1088 |
| 1087 PruneAndNotify(); | 1089 PruneAndNotify(); |
| 1088 } | 1090 } |
| 1089 | 1091 |
| 1090 Time TabRestoreService::TimeNow() const { | 1092 Time TabRestoreService::TimeNow() const { |
| 1091 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1093 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
| 1092 } | 1094 } |
| OLD | NEW |