Commit cae997b5 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

sessions: rename some sessions classes in preparation for refactor

As a last file doesn't make sense for WebLayer this is structuring
the code in such a way that the last file related code is not in
the base class.

This does the following:
renames BaseSessionService* to CommandStorageManager*

Next step is to move the functions related to a 'last file' out of
CommandStorageManagerinto CommandStorageManagerWithBackup. Specifically
the functions:
MoveCurrentSessionToLastSession, DeleteLastSession,
ScheduleGetLastSessionCommands. CommandStorageManagerWithBackup
will subclass CommandStorageManager.

SessionBackend will be similarly split such that functions related to last
session are moved into SessionBackendWithBackup, which will extend
SessionBackend.

I'm not dead set on the 'WithBackup' suffix. It's not really
a backup, so much as the last session. I considered the prefix
'MultiFile' but that's a bit too generic and obscure. I'm certainly
open to other suggestions.

BUG=112512
TEST=none

Change-Id: I33d2c9be43bbaea4336fa32bdb3fe750d39f543a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2005809Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732878}
parent e8904e0d
......@@ -315,7 +315,8 @@ ScopedJavaLocalRef<jobject> WriteSerializedNavigationsAsByteBuffer(
// Write each SerializedNavigationEntry as a separate pickle to avoid
// optional reads of one tab bleeding into the next tab's data.
base::Pickle tab_navigation_pickle;
// Max size taken from BaseSessionService::CreateUpdateTabNavigationCommand.
// Max size taken from
// CommandStorageManager::CreateUpdateTabNavigationCommand.
static const size_t max_state_size =
std::numeric_limits<sessions::SessionCommand::size_type>::max() - 1024;
navigation.WriteToPickle(max_state_size, &tab_navigation_pickle);
......
This diff is collapsed.
......@@ -26,7 +26,7 @@
#include "chrome/browser/ui/browser_list_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sessions/content/session_tab_helper_delegate.h"
#include "components/sessions/core/base_session_service_delegate.h"
#include "components/sessions/core/command_storage_manager_delegate.h"
#include "components/sessions/core/session_service_commands.h"
#include "components/sessions/core/tab_restore_service_client.h"
#include "components/tab_groups/tab_group_id.h"
......@@ -66,7 +66,7 @@ struct SessionWindow;
// flushed to |SessionBackend| and written to a file. Every so often
// |SessionService| rebuilds the contents of the file from the open state of the
// browser.
class SessionService : public sessions::BaseSessionServiceDelegate,
class SessionService : public sessions::CommandStorageManagerDelegate,
public sessions::SessionTabHelperDelegate,
public KeyedService,
public BrowserListObserver {
......@@ -200,7 +200,7 @@ class SessionService : public sessions::BaseSessionServiceDelegate,
sessions::GetLastSessionCallback callback,
base::CancelableTaskTracker* tracker);
// BaseSessionServiceDelegate:
// CommandStorageManagerDelegate:
bool ShouldUseDelayedSave() override;
void OnWillSaveCommands() override;
......@@ -325,7 +325,7 @@ class SessionService : public sessions::BaseSessionServiceDelegate,
void MaybeDeleteSessionOnlyData();
// Unit test accessors.
sessions::BaseSessionService* GetBaseSessionServiceForTest();
sessions::CommandStorageManager* GetCommandStorageManagerForTest();
void SetAvailableRangeForTest(const SessionID& tab_id,
const std::pair<int, int>& range);
......@@ -339,8 +339,7 @@ class SessionService : public sessions::BaseSessionServiceDelegate,
// (which should only be used for testing).
bool should_use_delayed_save_;
// The owned BaseSessionService.
std::unique_ptr<sessions::BaseSessionService> base_session_service_;
std::unique_ptr<sessions::CommandStorageManager> command_storage_manager_;
// Maps from session tab id to the range of navigation entries that has
// been written to disk.
......
......@@ -5,7 +5,7 @@
#include "chrome/browser/sessions/session_service_test_helper.h"
#include "chrome/browser/sessions/session_service.h"
#include "components/sessions/core/base_session_service_test_helper.h"
#include "components/sessions/core/command_storage_manager_test_helper.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "components/sessions/core/session_backend.h"
#include "components/sessions/core/session_id.h"
......@@ -58,8 +58,8 @@ void SessionServiceTestHelper::ReadWindows(
std::vector<std::unique_ptr<sessions::SessionWindow>>* windows,
SessionID* active_window_id) {
std::vector<std::unique_ptr<sessions::SessionCommand>> read_commands;
sessions::BaseSessionServiceTestHelper test_helper(
service_->GetBaseSessionServiceForTest());
sessions::CommandStorageManagerTestHelper test_helper(
service_->GetCommandStorageManagerForTest());
test_helper.ReadLastSessionCommands(&read_commands);
RestoreSessionFromCommands(read_commands, windows, active_window_id);
service()->RemoveUnusedRestoreWindows(windows);
......@@ -117,8 +117,8 @@ SessionService* SessionServiceTestHelper::ReleaseService() {
void SessionServiceTestHelper::RunTaskOnBackendThread(
const base::Location& from_here,
const base::Closure& task) {
sessions::BaseSessionServiceTestHelper test_helper(
service_->GetBaseSessionServiceForTest());
sessions::CommandStorageManagerTestHelper test_helper(
service_->GetCommandStorageManagerForTest());
test_helper.RunTaskOnBackendThread(from_here, task);
}
......
......@@ -78,7 +78,7 @@
#include "components/embedder_support/switches.h"
#include "components/omnibox/common/omnibox_focus_state.h"
#include "components/prefs/pref_service.h"
#include "components/sessions/core/base_session_service_test_helper.h"
#include "components/sessions/core/command_storage_manager_test_helper.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/common/language_detection_details.h"
#include "content/public/browser/browser_context.h"
......@@ -2212,8 +2212,9 @@ class NoStartupWindowTest : public BrowserTest {
// Returns true if any commands were processed.
bool ProcessedAnyCommands(
sessions::BaseSessionService* base_session_service) {
sessions::BaseSessionServiceTestHelper test_helper(base_session_service);
sessions::CommandStorageManager* command_storage_manager) {
sessions::CommandStorageManagerTestHelper test_helper(
command_storage_manager);
return test_helper.ProcessedAnyCommands();
}
};
......@@ -2236,13 +2237,13 @@ IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, DontInitSessionServiceForApps) {
SessionService* session_service =
SessionServiceFactory::GetForProfile(profile);
sessions::BaseSessionService* base_session_service =
session_service->GetBaseSessionServiceForTest();
ASSERT_FALSE(ProcessedAnyCommands(base_session_service));
sessions::CommandStorageManager* command_storage_manager =
session_service->GetCommandStorageManagerForTest();
ASSERT_FALSE(ProcessedAnyCommands(command_storage_manager));
CreateBrowserForApp("blah", profile);
ASSERT_FALSE(ProcessedAnyCommands(base_session_service));
ASSERT_FALSE(ProcessedAnyCommands(command_storage_manager));
}
#endif // !defined(OS_CHROMEOS)
......
......@@ -84,11 +84,11 @@ source_set("shared") {
visibility = [ ":*" ]
sources = [
"core/base_session_service.cc",
"core/base_session_service.h",
"core/base_session_service_commands.cc",
"core/base_session_service_commands.h",
"core/base_session_service_delegate.h",
"core/command_storage_manager.cc",
"core/command_storage_manager.h",
"core/command_storage_manager_delegate.h",
"core/live_tab.cc",
"core/live_tab.h",
"core/live_tab_context.h",
......@@ -159,8 +159,8 @@ static_library("test_support") {
if (!is_android && !is_ios) {
sources += [
"core/base_session_service_test_helper.cc",
"core/base_session_service_test_helper.h",
"core/command_storage_manager_test_helper.cc",
"core/command_storage_manager_test_helper.h",
]
}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sessions/core/base_session_service_test_helper.h"
#include "components/sessions/core/base_session_service.h"
#include "components/sessions/core/session_backend.h"
namespace sessions {
BaseSessionServiceTestHelper::BaseSessionServiceTestHelper(
BaseSessionService* base_session_service)
: base_session_service_(base_session_service) {
CHECK(base_session_service);
}
BaseSessionServiceTestHelper::~BaseSessionServiceTestHelper() {
}
void BaseSessionServiceTestHelper::RunTaskOnBackendThread(
const base::Location& from_here,
const base::Closure& task) {
base_session_service_->RunTaskOnBackendThread(from_here, task);
}
bool BaseSessionServiceTestHelper::ProcessedAnyCommands() {
return base_session_service_->backend_->inited() ||
!base_session_service_->pending_commands().empty();
}
bool BaseSessionServiceTestHelper::ReadLastSessionCommands(
std::vector<std::unique_ptr<SessionCommand>>* commands) {
return base_session_service_->backend_->ReadLastSessionCommandsImpl(commands);
}
} // namespace sessions
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sessions/core/base_session_service.h"
#include "components/sessions/core/command_storage_manager.h"
#include <utility>
......@@ -13,11 +13,9 @@
#include "base/task/post_task.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/sessions/core/base_session_service_delegate.h"
#include "components/sessions/core/command_storage_manager_delegate.h"
#include "components/sessions/core/session_backend.h"
// BaseSessionService ---------------------------------------------------------
namespace sessions {
namespace {
......@@ -25,7 +23,7 @@ namespace {
// thread if it's not canceled.
void RunIfNotCanceled(
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
BaseSessionService::GetCommandsCallback callback,
CommandStorageManager::GetCommandsCallback callback,
std::vector<std::unique_ptr<SessionCommand>> commands) {
if (is_canceled.Run())
return;
......@@ -34,7 +32,7 @@ void RunIfNotCanceled(
void PostOrRunInternalGetCommandsCallback(
base::SequencedTaskRunner* task_runner,
BaseSessionService::GetCommandsCallback callback,
CommandStorageManager::GetCommandsCallback callback,
std::vector<std::unique_ptr<SessionCommand>> commands) {
if (task_runner->RunsTasksInCurrentSequence()) {
std::move(callback).Run(std::move(commands));
......@@ -50,9 +48,10 @@ void PostOrRunInternalGetCommandsCallback(
// backend.
static const int kSaveDelayMS = 2500;
BaseSessionService::BaseSessionService(SessionType type,
const base::FilePath& path,
BaseSessionServiceDelegate* delegate)
CommandStorageManager::CommandStorageManager(
SessionType type,
const base::FilePath& path,
CommandStorageManagerDelegate* delegate)
: pending_reset_(false),
commands_since_reset_(0),
delegate_(delegate),
......@@ -64,9 +63,9 @@ BaseSessionService::BaseSessionService(SessionType type,
DCHECK(backend_);
}
BaseSessionService::~BaseSessionService() {}
CommandStorageManager::~CommandStorageManager() {}
void BaseSessionService::MoveCurrentSessionToLastSession() {
void CommandStorageManager::MoveCurrentSessionToLastSession() {
Save();
RunTaskOnBackendThread(
FROM_HERE,
......@@ -74,12 +73,12 @@ void BaseSessionService::MoveCurrentSessionToLastSession() {
backend_));
}
void BaseSessionService::DeleteLastSession() {
void CommandStorageManager::DeleteLastSession() {
RunTaskOnBackendThread(
FROM_HERE, base::BindOnce(&SessionBackend::DeleteLastSession, backend_));
}
void BaseSessionService::ScheduleCommand(
void CommandStorageManager::ScheduleCommand(
std::unique_ptr<SessionCommand> command) {
DCHECK(command);
commands_since_reset_++;
......@@ -87,13 +86,13 @@ void BaseSessionService::ScheduleCommand(
StartSaveTimer();
}
void BaseSessionService::AppendRebuildCommand(
void CommandStorageManager::AppendRebuildCommand(
std::unique_ptr<SessionCommand> command) {
DCHECK(command);
pending_commands_.push_back(std::move(command));
}
void BaseSessionService::EraseCommand(SessionCommand* old_command) {
void CommandStorageManager::EraseCommand(SessionCommand* old_command) {
auto it = std::find_if(
pending_commands_.begin(), pending_commands_.end(),
[old_command](const std::unique_ptr<SessionCommand>& command_ptr) {
......@@ -103,7 +102,7 @@ void BaseSessionService::EraseCommand(SessionCommand* old_command) {
pending_commands_.erase(it);
}
void BaseSessionService::SwapCommand(
void CommandStorageManager::SwapCommand(
SessionCommand* old_command,
std::unique_ptr<SessionCommand> new_command) {
auto it = std::find_if(
......@@ -115,22 +114,23 @@ void BaseSessionService::SwapCommand(
*it = std::move(new_command);
}
void BaseSessionService::ClearPendingCommands() {
void CommandStorageManager::ClearPendingCommands() {
pending_commands_.clear();
}
void BaseSessionService::StartSaveTimer() {
void CommandStorageManager::StartSaveTimer() {
// Don't start a timer when testing.
if (delegate_->ShouldUseDelayedSave() &&
base::ThreadTaskRunnerHandle::IsSet() && !weak_factory_.HasWeakPtrs()) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&BaseSessionService::Save, weak_factory_.GetWeakPtr()),
base::BindOnce(&CommandStorageManager::Save,
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kSaveDelayMS));
}
}
void BaseSessionService::Save() {
void CommandStorageManager::Save() {
// Inform the delegate that we will save the commands now, giving it the
// opportunity to append more commands.
delegate_->OnWillSaveCommands();
......@@ -151,7 +151,7 @@ void BaseSessionService::Save() {
}
base::CancelableTaskTracker::TaskId
BaseSessionService::ScheduleGetLastSessionCommands(
CommandStorageManager::ScheduleGetLastSessionCommands(
GetCommandsCallback callback,
base::CancelableTaskTracker* tracker) {
base::CancelableTaskTracker::IsCanceledCallback is_canceled;
......@@ -173,8 +173,9 @@ BaseSessionService::ScheduleGetLastSessionCommands(
return id;
}
void BaseSessionService::RunTaskOnBackendThread(const base::Location& from_here,
base::OnceClosure task) {
void CommandStorageManager::RunTaskOnBackendThread(
const base::Location& from_here,
base::OnceClosure task) {
backend_task_runner_->PostNonNestableTask(from_here, std::move(task));
}
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_
#define COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_
#ifndef COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_H_
#define COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_H_
#include <memory>
......@@ -20,34 +20,33 @@ class SequencedTaskRunner;
}
namespace sessions {
class BaseSessionServiceDelegate;
class CommandStorageManagerDelegate;
class SessionCommand;
class SessionBackend;
// BaseSessionService is the super class of both tab restore service and
// session service. It contains commonality needed by both, in particular
// it manages a set of SessionCommands that are periodically sent to a
// SessionBackend.
class SESSIONS_EXPORT BaseSessionService {
// CommandStorageManager is responsible for reading/writing SessionCommands
// to disk. SessionCommands are used to save and restore the state of the
// browser. CommandStorageManager runs on the main thread and uses
// SessionBackend (which runs on a background task runner) for the actual
// reading/writing. In hopes of minimizing IO, SessionCommands are queued up
// and processed after a delay.
class SESSIONS_EXPORT CommandStorageManager {
public:
// Identifies the type of session service this is. This is used by the
// backend to determine the name of the files.
enum SessionType {
SESSION_RESTORE,
TAB_RESTORE
};
enum SessionType { SESSION_RESTORE, TAB_RESTORE };
using GetCommandsCallback =
base::OnceCallback<void(std::vector<std::unique_ptr<SessionCommand>>)>;
// Creates a new BaseSessionService. After creation you need to invoke
// Creates a new CommandStorageManager. After creation you need to invoke
// Init. |delegate| will remain owned by the creator and it is guaranteed
// that its lifetime surpasses this class.
// |type| gives the type of session service, |path| the path to save files to.
BaseSessionService(SessionType type,
const base::FilePath& path,
BaseSessionServiceDelegate* delegate);
~BaseSessionService();
CommandStorageManager(SessionType type,
const base::FilePath& path,
CommandStorageManagerDelegate* delegate);
~CommandStorageManager();
// Moves the current session to the last session.
void MoveCurrentSessionToLastSession();
......@@ -103,7 +102,7 @@ class SESSIONS_EXPORT BaseSessionService {
base::CancelableTaskTracker* tracker);
private:
friend class BaseSessionServiceTestHelper;
friend class CommandStorageManagerTestHelper;
// This posts the task to the TaskRunner.
void RunTaskOnBackendThread(const base::Location& from_here,
......@@ -122,18 +121,18 @@ class SESSIONS_EXPORT BaseSessionService {
// The number of commands sent to the backend before doing a reset.
int commands_since_reset_;
BaseSessionServiceDelegate* delegate_;
CommandStorageManagerDelegate* delegate_;
// TaskRunner all backend tasks are run on. This is a SequencedTaskRunner as
// all tasks *must* be processed in the order they are scheduled.
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
// Used to invoke Save.
base::WeakPtrFactory<BaseSessionService> weak_factory_{this};
base::WeakPtrFactory<CommandStorageManager> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(BaseSessionService);
DISALLOW_COPY_AND_ASSIGN(CommandStorageManager);
};
} // namespace sessions
#endif // COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_
#endif // COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_H_
......@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_DELEGATE_H_
#define COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_DELEGATE_H_
#ifndef COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_DELEGATE_H_
#define COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_DELEGATE_H_
namespace sessions {
// The BaseSessionServiceDelegate decouples the BaseSessionService from
// The CommandStorageManagerDelegate decouples the CommandStorageManager from
// chrome/content dependencies.
class BaseSessionServiceDelegate {
class CommandStorageManagerDelegate {
public:
BaseSessionServiceDelegate() {}
CommandStorageManagerDelegate() {}
// Returns true if save operations can be performed as a delayed task - which
// is usually only used by unit tests.
......@@ -21,9 +21,9 @@ class BaseSessionServiceDelegate {
virtual void OnWillSaveCommands() {}
protected:
virtual ~BaseSessionServiceDelegate() {}
virtual ~CommandStorageManagerDelegate() {}
};
} // namespace sessions
#endif // COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_DELEGATE_H_
#endif // COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_DELEGATE_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sessions/core/command_storage_manager_test_helper.h"
#include "components/sessions/core/command_storage_manager.h"
#include "components/sessions/core/session_backend.h"
namespace sessions {
CommandStorageManagerTestHelper::CommandStorageManagerTestHelper(
CommandStorageManager* command_storage_manager)
: command_storage_manager_(command_storage_manager) {
CHECK(command_storage_manager);
}
void CommandStorageManagerTestHelper::RunTaskOnBackendThread(
const base::Location& from_here,
const base::Closure& task) {
command_storage_manager_->RunTaskOnBackendThread(from_here, task);
}
bool CommandStorageManagerTestHelper::ProcessedAnyCommands() {
return command_storage_manager_->backend_->inited() ||
!command_storage_manager_->pending_commands().empty();
}
bool CommandStorageManagerTestHelper::ReadLastSessionCommands(
std::vector<std::unique_ptr<SessionCommand>>* commands) {
return command_storage_manager_->backend_->ReadLastSessionCommandsImpl(
commands);
}
scoped_refptr<base::SequencedTaskRunner>
CommandStorageManagerTestHelper::GetBackendTaskRunner() {
return command_storage_manager_->backend_task_runner_;
}
} // namespace sessions
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_TEST_HELPER_H_
#define COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_TEST_HELPER_H_
#ifndef COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_TEST_HELPER_H_
#define COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_TEST_HELPER_H_
#include <memory>
#include <vector>
......@@ -14,13 +14,13 @@
namespace sessions {
class SessionCommand;
class BaseSessionService;
class CommandStorageManager;
class BaseSessionServiceTestHelper {
class CommandStorageManagerTestHelper {
public:
explicit BaseSessionServiceTestHelper(
BaseSessionService* base_session_service_);
~BaseSessionServiceTestHelper();
explicit CommandStorageManagerTestHelper(
CommandStorageManager* command_storage_manager_);
~CommandStorageManagerTestHelper() = default;
// This posts the task to the SequencedWorkerPool, or run immediately
// if the SequencedWorkerPool has been shutdown.
......@@ -34,12 +34,14 @@ class BaseSessionServiceTestHelper {
bool ReadLastSessionCommands(
std::vector<std::unique_ptr<SessionCommand>>* commands);
scoped_refptr<base::SequencedTaskRunner> GetBackendTaskRunner();
private:
BaseSessionService* base_session_service_;
CommandStorageManager* command_storage_manager_;
DISALLOW_COPY_AND_ASSIGN(BaseSessionServiceTestHelper);
DISALLOW_COPY_AND_ASSIGN(CommandStorageManagerTestHelper);
};
} // namespace sessions
#endif // COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_TEST_HELPER_H_
#endif // COMPONENTS_SESSIONS_CORE_COMMAND_STORAGE_MANAGER_TEST_HELPER_H_
......@@ -14,8 +14,6 @@
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
using base::TimeTicks;
namespace sessions {
// File version number.
......@@ -195,7 +193,7 @@ const int SessionBackend::kFileReadBufferSize = 1024;
SessionBackend::SessionBackend(
scoped_refptr<base::SequencedTaskRunner> owning_task_runner,
sessions::BaseSessionService::SessionType type,
sessions::CommandStorageManager::SessionType type,
const base::FilePath& path_to_dir)
: RefCountedDeleteOnSequence(owning_task_runner),
type_(type),
......@@ -214,7 +212,6 @@ void SessionBackend::Init() {
// Create the directory for session info.
base::CreateDirectory(path_to_dir_);
MoveCurrentSessionToLastSession();
}
......@@ -238,7 +235,7 @@ void SessionBackend::AppendCommands(
void SessionBackend::ReadLastSessionCommands(
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
sessions::BaseSessionService::GetCommandsCallback callback) {
sessions::CommandStorageManager::GetCommandsCallback callback) {
if (is_canceled.Run())
return;
......@@ -363,7 +360,7 @@ base::File* SessionBackend::OpenAndWriteHeader(const base::FilePath& path) {
base::FilePath SessionBackend::GetLastSessionPath() {
base::FilePath path = path_to_dir_;
if (type_ == sessions::BaseSessionService::TAB_RESTORE)
if (type_ == sessions::CommandStorageManager::TAB_RESTORE)
path = path.AppendASCII(kLastTabSessionFileName);
else
path = path.AppendASCII(kLastSessionFileName);
......@@ -372,7 +369,7 @@ base::FilePath SessionBackend::GetLastSessionPath() {
base::FilePath SessionBackend::GetCurrentSessionPath() {
base::FilePath path = path_to_dir_;
if (type_ == sessions::BaseSessionService::TAB_RESTORE)
if (type_ == sessions::CommandStorageManager::TAB_RESTORE)
path = path.AppendASCII(kCurrentTabSessionFileName);
else
path = path.AppendASCII(kCurrentSessionFileName);
......
......@@ -13,7 +13,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/sessions/core/base_session_service.h"
#include "components/sessions/core/command_storage_manager.h"
#include "components/sessions/core/session_command.h"
#include "components/sessions/core/sessions_export.h"
......@@ -24,17 +24,18 @@ class File;
namespace sessions {
// SessionBackend -------------------------------------------------------------
// SessionBackend is the backend used by BaseSessionService. It is responsible
// for maintaining two files:
// SessionBackend is the backend used by CommandStorageManager. It is
// responsible for maintaining two files:
//
// . The current file, which is the file commands passed to AppendCommands
// get written to.
// . The last file. When created the current file is moved to the last
// file.
//
// Each file contains an arbitrary set of commands supplied from
// BaseSessionService. A command consists of a unique id and a stream of bytes.
// SessionBackend does not use the id in anyway, that is used by
// BaseSessionService.
// CommandStorageManager. A command consists of a unique id and a stream of
// bytes. SessionBackend does not use the id in anyway, that is used by
// CommandStorageManager.
class SESSIONS_EXPORT SessionBackend
: public base::RefCountedDeleteOnSequence<SessionBackend> {
public:
......@@ -53,7 +54,7 @@ class SESSIONS_EXPORT SessionBackend
// indicates which service is using this backend. |type| is used to determine
// the name of the files to use as well as for logging.
SessionBackend(scoped_refptr<base::SequencedTaskRunner> owning_task_runner,
sessions::BaseSessionService::SessionType type,
sessions::CommandStorageManager::SessionType type,
const base::FilePath& path_to_dir);
// Moves the current file to the last file, and recreates the current file.
......@@ -73,7 +74,7 @@ class SESSIONS_EXPORT SessionBackend
// session, invokes ReadLastSessionCommandsImpl to do the work.
void ReadLastSessionCommands(
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
sessions::BaseSessionService::GetCommandsCallback callback);
sessions::CommandStorageManager::GetCommandsCallback callback);
// Reads the commands from the last file.
//
......@@ -119,7 +120,7 @@ class SESSIONS_EXPORT SessionBackend
base::File* file,
const std::vector<std::unique_ptr<sessions::SessionCommand>>& commands);
const sessions::BaseSessionService::SessionType type_;
const sessions::CommandStorageManager::SessionType type_;
// Returns the path to the last file.
base::FilePath GetLastSessionPath();
......
......@@ -59,7 +59,7 @@ class SessionBackendTest : public testing::Test {
scoped_refptr<SessionBackend> CreateBackend() {
return MakeRefCounted<SessionBackend>(
task_environment_.GetMainThreadTaskRunner(),
sessions::BaseSessionService::SESSION_RESTORE, path_);
sessions::CommandStorageManager::SESSION_RESTORE, path_);
}
base::test::TaskEnvironment task_environment_;
......
......@@ -15,7 +15,7 @@
#include "base/pickle.h"
#include "base/token.h"
#include "components/sessions/core/base_session_service_commands.h"
#include "components/sessions/core/base_session_service_delegate.h"
#include "components/sessions/core/command_storage_manager_delegate.h"
#include "components/sessions/core/session_command.h"
#include "components/sessions/core/session_types.h"
#include "components/tab_groups/tab_group_color.h"
......@@ -986,7 +986,7 @@ std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand(
app_name);
}
bool ReplacePendingCommand(BaseSessionService* base_session_service,
bool ReplacePendingCommand(CommandStorageManager* command_storage_manager,
std::unique_ptr<SessionCommand>* command) {
// We optimize page navigations, which can happen quite frequently and
// is expensive. And activation is like Highlander, there can only be one!
......@@ -994,8 +994,8 @@ bool ReplacePendingCommand(BaseSessionService* base_session_service,
(*command)->id() != kCommandSetActiveWindow) {
return false;
}
for (auto i = base_session_service->pending_commands().rbegin();
i != base_session_service->pending_commands().rend(); ++i) {
for (auto i = command_storage_manager->pending_commands().rbegin();
i != command_storage_manager->pending_commands().rend(); ++i) {
SessionCommand* existing_command = i->get();
if ((*command)->id() == kCommandUpdateTabNavigation &&
existing_command->id() == kCommandUpdateTabNavigation) {
......@@ -1027,16 +1027,16 @@ bool ReplacePendingCommand(BaseSessionService* base_session_service,
// existing_command is an update for the same tab/index pair. Replace
// it with the new one. We need to add to the end of the list just in
// case there is a prune command after the update command.
base_session_service->EraseCommand((i.base() - 1)->get());
base_session_service->AppendRebuildCommand(std::move(*command));
command_storage_manager->EraseCommand((i.base() - 1)->get());
command_storage_manager->AppendRebuildCommand(std::move(*command));
return true;
}
return false;
}
if ((*command)->id() == kCommandSetActiveWindow &&
existing_command->id() == kCommandSetActiveWindow) {
base_session_service->SwapCommand(existing_command,
(std::move(*command)));
command_storage_manager->SwapCommand(existing_command,
(std::move(*command)));
return true;
}
}
......
......@@ -14,7 +14,7 @@
#include "base/optional.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/token.h"
#include "components/sessions/core/base_session_service.h"
#include "components/sessions/core/command_storage_manager.h"
#include "components/sessions/core/session_types.h"
#include "components/sessions/core/sessions_export.h"
#include "components/tab_groups/tab_group_id.h"
......@@ -89,12 +89,12 @@ SESSIONS_EXPORT std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand(
const SessionID& window_id,
const std::string& workspace);
// Searches for a pending command using |base_session_service| that can be
// Searches for a pending command using |command_storage_manager| that can be
// replaced with |command|. If one is found, pending command is removed, the
// command is added to the pending commands (taken ownership) and true is
// returned.
SESSIONS_EXPORT bool ReplacePendingCommand(
BaseSessionService* base_session_service,
CommandStorageManager* command_storage_manager,
std::unique_ptr<SessionCommand>* command);
// Returns true if provided |command| either closes a window or a tab.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment