| Index: chrome/browser/sessions/persistent_tab_restore_service.cc
|
| diff --git a/chrome/browser/sessions/persistent_tab_restore_service.cc b/chrome/browser/sessions/persistent_tab_restore_service.cc
|
| index bc7555ca5290ac70acbf3655e306783466a65626..735327d39310b5285fe4df288ec7af1b2475fa8f 100644
|
| --- a/chrome/browser/sessions/persistent_tab_restore_service.cc
|
| +++ b/chrome/browser/sessions/persistent_tab_restore_service.cc
|
| @@ -22,7 +22,6 @@
|
| #include "chrome/browser/sessions/base_session_service_commands.h"
|
| #include "chrome/browser/sessions/base_session_service_delegate_impl.h"
|
| #include "chrome/browser/sessions/session_command.h"
|
| -#include "chrome/browser/sessions/session_service.h"
|
| #include "chrome/browser/sessions/session_service_factory.h"
|
| #include "chrome/browser/sessions/tab_restore_service_factory.h"
|
| #include "content/public/browser/session_storage_namespace.h"
|
| @@ -114,17 +113,18 @@ const size_t kMaxEntries = TabRestoreServiceHelper::kMaxEntries;
|
|
|
| // PersistentTabRestoreService::Delegate ---------------------------------------
|
|
|
| -// Implements the link between the tab restore service and the session backend.
|
| +// This restore service will create and own a BaseSessionService and implement
|
| +// the required BaseSessionServiceDelegateImpl.
|
| class PersistentTabRestoreService::Delegate
|
| - : public BaseSessionService,
|
| + : public BaseSessionServiceDelegateImpl,
|
| public TabRestoreServiceHelper::Observer {
|
| public:
|
| explicit Delegate(Profile* profile);
|
|
|
| ~Delegate() override;
|
|
|
| - // BaseSessionService:
|
| - void Save() override;
|
| + // BaseSessionServiceDelegateImpl:
|
| + void OnWillSaveCommands() override;
|
|
|
| // TabRestoreServiceHelper::Observer:
|
| void OnClearEntries() override;
|
| @@ -139,6 +139,8 @@ class PersistentTabRestoreService::Delegate
|
|
|
| void LoadTabsFromLastSession();
|
|
|
| + void DeleteLastSession();
|
| +
|
| bool IsLoaded() const;
|
|
|
| // Creates and add entries to |entries| for each of the windows in |windows|.
|
| @@ -189,7 +191,7 @@ class PersistentTabRestoreService::Delegate
|
| // also deletes any entries beyond the max number of entries we can hold.
|
| static void ValidateAndDeleteEmptyEntries(std::vector<Entry*>* entries);
|
|
|
| - // Callback from SessionService when we've received the windows from the
|
| + // Callback from BaseSessionService when we've received the windows from the
|
| // previous session. This creates and add entries to |staging_entries_| and
|
| // invokes LoadStateChanged. |ignored_active_window| is ignored because we
|
| // don't need to restore activation.
|
| @@ -214,6 +216,8 @@ class PersistentTabRestoreService::Delegate
|
| std::vector<TabRestoreService::Entry*>* entries);
|
|
|
| private:
|
| + scoped_ptr<BaseSessionService> base_session_service_;
|
| +
|
| // The associated profile.
|
| Profile* profile_;
|
|
|
| @@ -240,11 +244,11 @@ class PersistentTabRestoreService::Delegate
|
| };
|
|
|
| PersistentTabRestoreService::Delegate::Delegate(Profile* profile)
|
| - : BaseSessionService(
|
| - BaseSessionService::TAB_RESTORE,
|
| - profile->GetPath(),
|
| - scoped_ptr<BaseSessionServiceDelegate>(
|
| - new BaseSessionServiceDelegateImpl(true))),
|
| + : BaseSessionServiceDelegateImpl(true),
|
| + base_session_service_(
|
| + new BaseSessionService(BaseSessionService::TAB_RESTORE,
|
| + profile->GetPath(),
|
| + this)),
|
| profile_(profile),
|
| tab_restore_service_helper_(NULL),
|
| entries_to_write_(0),
|
| @@ -256,14 +260,14 @@ PersistentTabRestoreService::Delegate::Delegate(Profile* profile)
|
|
|
| PersistentTabRestoreService::Delegate::~Delegate() {}
|
|
|
| -void PersistentTabRestoreService::Delegate::Save() {
|
| +void PersistentTabRestoreService::Delegate::OnWillSaveCommands() {
|
| const Entries& entries = tab_restore_service_helper_->entries();
|
| int to_write_count = std::min(entries_to_write_,
|
| static_cast<int>(entries.size()));
|
| entries_to_write_ = 0;
|
| if (entries_written_ + to_write_count > kEntriesPerReset) {
|
| to_write_count = entries.size();
|
| - set_pending_reset(true);
|
| + base_session_service_->set_pending_reset(true);
|
| }
|
| if (to_write_count) {
|
| // Write the to_write_count most recently added entries out. The most
|
| @@ -285,25 +289,25 @@ void PersistentTabRestoreService::Delegate::Save() {
|
| entries_written_++;
|
| }
|
| }
|
| - if (pending_reset())
|
| + if (base_session_service_->pending_reset())
|
| entries_written_ = 0;
|
| - BaseSessionService::Save();
|
| }
|
|
|
| void PersistentTabRestoreService::Delegate::OnClearEntries() {
|
| // Mark all the tabs as closed so that we don't attempt to restore them.
|
| const Entries& entries = tab_restore_service_helper_->entries();
|
| for (Entries::const_iterator i = entries.begin(); i != entries.end(); ++i)
|
| - ScheduleCommand(CreateRestoredEntryCommand((*i)->id).Pass());
|
| + base_session_service_->ScheduleCommand(
|
| + CreateRestoredEntryCommand((*i)->id).Pass());
|
|
|
| entries_to_write_ = 0;
|
|
|
| // Schedule a pending reset so that we nuke the file on next write.
|
| - set_pending_reset(true);
|
| + base_session_service_->set_pending_reset(true);
|
|
|
| // Schedule a command, otherwise if there are no pending commands Save does
|
| // nothing.
|
| - ScheduleCommand(CreateRestoredEntryCommand(1).Pass());
|
| + base_session_service_->ScheduleCommand(CreateRestoredEntryCommand(1).Pass());
|
| }
|
|
|
| void PersistentTabRestoreService::Delegate::OnRestoreEntryById(
|
| @@ -317,12 +321,12 @@ void PersistentTabRestoreService::Delegate::OnRestoreEntryById(
|
| if (static_cast<int>(index) < entries_to_write_)
|
| entries_to_write_--;
|
|
|
| - ScheduleCommand(CreateRestoredEntryCommand(id).Pass());
|
| + base_session_service_->ScheduleCommand(CreateRestoredEntryCommand(id).Pass());
|
| }
|
|
|
| void PersistentTabRestoreService::Delegate::OnAddEntry() {
|
| // Start the save timer, when it fires we'll generate the commands.
|
| - StartSaveTimer();
|
| + base_session_service_->StartSaveTimer();
|
| entries_to_write_++;
|
| }
|
|
|
| @@ -366,11 +370,15 @@ void PersistentTabRestoreService::Delegate::LoadTabsFromLastSession() {
|
| // Request the tabs closed in the last session. If the last session crashed,
|
| // this won't contain the tabs/window that were open at the point of the
|
| // crash (the call to GetLastSession above requests those).
|
| - ScheduleGetLastSessionCommands(
|
| + base_session_service_->ScheduleGetLastSessionCommands(
|
| base::Bind(&Delegate::OnGotLastSessionCommands, base::Unretained(this)),
|
| &cancelable_task_tracker_);
|
| }
|
|
|
| +void PersistentTabRestoreService::Delegate::DeleteLastSession() {
|
| + base_session_service_->DeleteLastSession();
|
| +}
|
| +
|
| bool PersistentTabRestoreService::Delegate::IsLoaded() const {
|
| return !(load_state_ & (NOT_LOADED | LOADING));
|
| }
|
| @@ -387,8 +395,7 @@ void PersistentTabRestoreService::Delegate::CreateEntriesFromWindows(
|
| }
|
|
|
| void PersistentTabRestoreService::Delegate::Shutdown() {
|
| - if (backend())
|
| - Save();
|
| + base_session_service_->SaveNow();
|
| }
|
|
|
| void PersistentTabRestoreService::Delegate::ScheduleCommandsForWindow(
|
| @@ -407,16 +414,17 @@ void PersistentTabRestoreService::Delegate::ScheduleCommandsForWindow(
|
| if (valid_tab_count == 0)
|
| return; // No tabs to persist.
|
|
|
| - ScheduleCommand(
|
| + base_session_service_->ScheduleCommand(
|
| CreateWindowCommand(window.id,
|
| std::min(real_selected_tab, valid_tab_count - 1),
|
| valid_tab_count,
|
| window.timestamp).Pass());
|
|
|
| if (!window.app_name.empty()) {
|
| - ScheduleCommand(CreateSetWindowAppNameCommand(kCommandSetWindowAppName,
|
| - window.id,
|
| - window.app_name).Pass());
|
| + base_session_service_->ScheduleCommand(
|
| + CreateSetWindowAppNameCommand(kCommandSetWindowAppName,
|
| + window.id,
|
| + window.app_name).Pass());
|
| }
|
|
|
| for (size_t i = 0; i < window.tabs.size(); ++i) {
|
| @@ -437,7 +445,8 @@ void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab(
|
| int valid_count_before_selected = 0;
|
| int first_index_to_persist = selected_index;
|
| for (int i = selected_index - 1; i >= 0 &&
|
| - valid_count_before_selected < max_persist_navigation_count; --i) {
|
| + valid_count_before_selected <
|
| + BaseSessionService::max_persist_navigation_count; --i) {
|
| if (ShouldTrackEntry(navigations[i].virtual_url())) {
|
| first_index_to_persist = i;
|
| valid_count_before_selected++;
|
| @@ -445,7 +454,7 @@ void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab(
|
| }
|
|
|
| // Write the command that identifies the selected tab.
|
| - ScheduleCommand(
|
| + base_session_service_->ScheduleCommand(
|
| CreateSelectedNavigationInTabCommand(tab.id,
|
| valid_count_before_selected,
|
| tab.timestamp).Pass());
|
| @@ -455,31 +464,32 @@ void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab(
|
| scoped_ptr<SessionCommand> command(
|
| new SessionCommand(kCommandPinnedState, sizeof(payload)));
|
| memcpy(command->contents(), &payload, sizeof(payload));
|
| - ScheduleCommand(command.Pass());
|
| + base_session_service_->ScheduleCommand(command.Pass());
|
| }
|
|
|
| if (!tab.extension_app_id.empty()) {
|
| - ScheduleCommand(CreateSetTabExtensionAppIDCommand(
|
| - kCommandSetExtensionAppID,
|
| - tab.id,
|
| - tab.extension_app_id).Pass());
|
| + base_session_service_->ScheduleCommand(
|
| + CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID,
|
| + tab.id,
|
| + tab.extension_app_id).Pass());
|
| }
|
|
|
| if (!tab.user_agent_override.empty()) {
|
| - ScheduleCommand(CreateSetTabUserAgentOverrideCommand(
|
| - kCommandSetTabUserAgentOverride,
|
| - tab.id,
|
| - tab.user_agent_override).Pass());
|
| + base_session_service_->ScheduleCommand(
|
| + CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride,
|
| + tab.id,
|
| + tab.user_agent_override).Pass());
|
| }
|
|
|
| // Then write the navigations.
|
| for (int i = first_index_to_persist, wrote_count = 0;
|
| - i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) {
|
| + wrote_count < 2 * BaseSessionService::max_persist_navigation_count &&
|
| + i < max_index; ++i) {
|
| if (ShouldTrackEntry(navigations[i].virtual_url())) {
|
| - ScheduleCommand(CreateUpdateTabNavigationCommand(
|
| - kCommandUpdateTabNavigation,
|
| - tab.id,
|
| - navigations[i]));
|
| + base_session_service_->ScheduleCommand(
|
| + CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation,
|
| + tab.id,
|
| + navigations[i]));
|
| }
|
| }
|
| }
|
|
|