| Index: chrome/browser/sessions/base_session_service.cc
|
| diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc
|
| index 2c6672d67b5c4f0b16b5d449852513a9fb7ec46e..d78bc485e61bfc56de5a9496ad312c785720ae0f 100644
|
| --- a/chrome/browser/sessions/base_session_service.cc
|
| +++ b/chrome/browser/sessions/base_session_service.cc
|
| @@ -17,7 +17,7 @@ namespace {
|
| // thread if it's not canceled.
|
| void RunIfNotCanceled(
|
| const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
|
| - const BaseSessionService::InternalGetCommandsCallback& callback,
|
| + const BaseSessionService::GetCommandsCallback& callback,
|
| ScopedVector<SessionCommand> commands) {
|
| if (is_canceled.Run())
|
| return;
|
| @@ -26,7 +26,7 @@ void RunIfNotCanceled(
|
|
|
| void PostOrRunInternalGetCommandsCallback(
|
| base::TaskRunner* task_runner,
|
| - const BaseSessionService::InternalGetCommandsCallback& callback,
|
| + const BaseSessionService::GetCommandsCallback& callback,
|
| ScopedVector<SessionCommand> commands) {
|
| if (task_runner->RunsTasksOnCurrentThread()) {
|
| callback.Run(commands.Pass());
|
| @@ -42,29 +42,32 @@ void PostOrRunInternalGetCommandsCallback(
|
| // backend.
|
| static const int kSaveDelayMS = 2500;
|
|
|
| -// static
|
| -const int BaseSessionService::max_persist_navigation_count = 6;
|
| -
|
| BaseSessionService::BaseSessionService(
|
| SessionType type,
|
| const base::FilePath& path,
|
| - scoped_ptr<BaseSessionServiceDelegate> delegate)
|
| + BaseSessionServiceDelegate* delegate)
|
| : pending_reset_(false),
|
| commands_since_reset_(0),
|
| - delegate_(delegate.Pass()),
|
| + delegate_(delegate),
|
| sequence_token_(delegate_->GetBlockingPool()->GetSequenceToken()),
|
| weak_factory_(this) {
|
| backend_ = new SessionBackend(type, path);
|
| DCHECK(backend_.get());
|
| }
|
|
|
| -BaseSessionService::~BaseSessionService() {
|
| +BaseSessionService::~BaseSessionService() {}
|
| +
|
| +void BaseSessionService::MoveCurrentSessionToLastSession() {
|
| + Save();
|
| + RunTaskOnBackendThread(
|
| + FROM_HERE, base::Bind(&SessionBackend::MoveCurrentSessionToLastSession,
|
| + backend_));
|
| }
|
|
|
| void BaseSessionService::DeleteLastSession() {
|
| RunTaskOnBackendThread(
|
| FROM_HERE,
|
| - base::Bind(&SessionBackend::DeleteLastSession, backend()));
|
| + base::Bind(&SessionBackend::DeleteLastSession, backend_));
|
| }
|
|
|
| void BaseSessionService::ScheduleCommand(scoped_ptr<SessionCommand> command) {
|
| @@ -74,26 +77,61 @@ void BaseSessionService::ScheduleCommand(scoped_ptr<SessionCommand> command) {
|
| StartSaveTimer();
|
| }
|
|
|
| +void BaseSessionService::AppendRebuildCommand(
|
| + scoped_ptr<SessionCommand> command) {
|
| + DCHECK(command);
|
| + pending_commands_.push_back(command.release());
|
| +}
|
| +
|
| +void BaseSessionService::EraseCommand(SessionCommand* old_command) {
|
| + ScopedVector<SessionCommand>::iterator it =
|
| + std::find(pending_commands_.begin(),
|
| + pending_commands_.end(),
|
| + old_command);
|
| + CHECK(it != pending_commands_.end());
|
| + pending_commands_.erase(it);
|
| +}
|
| +
|
| +void BaseSessionService::SwapCommand(SessionCommand* old_command,
|
| + scoped_ptr<SessionCommand> new_command) {
|
| + ScopedVector<SessionCommand>::iterator it =
|
| + std::find(pending_commands_.begin(),
|
| + pending_commands_.end(),
|
| + old_command);
|
| + CHECK(it != pending_commands_.end());
|
| + *it = new_command.release();
|
| + delete old_command;
|
| +}
|
| +
|
| +void BaseSessionService::ClearPendingCommands() {
|
| + pending_commands_.clear();
|
| +}
|
| +
|
| void BaseSessionService::StartSaveTimer() {
|
| // Don't start a timer when testing.
|
| if (delegate_->ShouldUseDelayedSave() && base::MessageLoop::current() &&
|
| !weak_factory_.HasWeakPtrs()) {
|
| base::MessageLoop::current()->PostDelayedTask(
|
| FROM_HERE,
|
| - base::Bind(&BaseSessionService::Save, weak_factory_.GetWeakPtr()),
|
| + base::Bind(&BaseSessionService::Save,
|
| + weak_factory_.GetWeakPtr()),
|
| base::TimeDelta::FromMilliseconds(kSaveDelayMS));
|
| }
|
| }
|
|
|
| void BaseSessionService::Save() {
|
| - DCHECK(backend());
|
| + // Inform the delegate that we will save the commands now, giving it the
|
| + // opportunity to append more commands.
|
| + delegate_->OnWillSaveCommands();
|
|
|
| if (pending_commands_.empty())
|
| return;
|
|
|
| + // We create a new ScopedVector which will receive all elements from the
|
| + // current commands. This will also clear the current list.
|
| RunTaskOnBackendThread(
|
| FROM_HERE,
|
| - base::Bind(&SessionBackend::AppendCommands, backend(),
|
| + base::Bind(&SessionBackend::AppendCommands, backend_,
|
| base::Passed(&pending_commands_),
|
| pending_reset_));
|
|
|
| @@ -101,30 +139,28 @@ void BaseSessionService::Save() {
|
| commands_since_reset_ = 0;
|
| pending_reset_ = false;
|
| }
|
| -}
|
|
|
| -bool BaseSessionService::ShouldTrackEntry(const GURL& url) {
|
| - return url.is_valid() && delegate_->ShouldTrackEntry(url);
|
| + delegate_->OnSavedCommands();
|
| }
|
|
|
| base::CancelableTaskTracker::TaskId
|
| BaseSessionService::ScheduleGetLastSessionCommands(
|
| - const InternalGetCommandsCallback& callback,
|
| + const GetCommandsCallback& callback,
|
| base::CancelableTaskTracker* tracker) {
|
| base::CancelableTaskTracker::IsCanceledCallback is_canceled;
|
| base::CancelableTaskTracker::TaskId id =
|
| tracker->NewTrackedTaskId(&is_canceled);
|
|
|
| - InternalGetCommandsCallback run_if_not_canceled =
|
| + GetCommandsCallback run_if_not_canceled =
|
| base::Bind(&RunIfNotCanceled, is_canceled, callback);
|
|
|
| - InternalGetCommandsCallback callback_runner =
|
| + GetCommandsCallback callback_runner =
|
| base::Bind(&PostOrRunInternalGetCommandsCallback,
|
| base::MessageLoopProxy::current(), run_if_not_canceled);
|
|
|
| RunTaskOnBackendThread(
|
| FROM_HERE,
|
| - base::Bind(&SessionBackend::ReadLastSessionCommands, backend(),
|
| + base::Bind(&SessionBackend::ReadLastSessionCommands, backend_,
|
| is_canceled, callback_runner));
|
| return id;
|
| }
|
| @@ -142,3 +178,12 @@ void BaseSessionService::RunTaskOnBackendThread(
|
| task.Run();
|
| }
|
| }
|
| +
|
| +bool BaseSessionService::ProcessedAnyCommandsForTest() {
|
| + return backend_->inited() || !pending_commands().empty();
|
| +}
|
| +
|
| +bool BaseSessionService::ReadLastSessionCommandsForTest(
|
| + ScopedVector<SessionCommand>* commands) {
|
| + return backend_->ReadLastSessionCommandsImpl(commands);
|
| +}
|
|
|