Skip to content

Commit

Permalink
weblayer: renames SessionService to BrowserPersister
Browse files Browse the repository at this point in the history
This better conveys what the object does.

BUG=none
TEST=none

Change-Id: I21df5bcf0eca88184ace9a479e35b0e76a4be595
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051018
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740452}
  • Loading branch information
Scott Violet authored and Commit Bot committed Feb 11, 2020
1 parent 315e9f1 commit 9843d0a
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 101 deletions.
4 changes: 2 additions & 2 deletions weblayer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ jumbo_static_library("weblayer_lib") {
"browser/navigation_impl.h",
"browser/persistence/browser_persistence_common.cc",
"browser/persistence/browser_persistence_common.h",
"browser/persistence/browser_persister.cc",
"browser/persistence/browser_persister.h",
"browser/persistence/minimal_browser_persister.cc",
"browser/persistence/minimal_browser_persister.h",
"browser/persistence/session_service.cc",
"browser/persistence/session_service.h",
"browser/profile_impl.cc",
"browser/profile_impl.h",
"browser/ssl_error_controller_client.cc",
Expand Down
22 changes: 11 additions & 11 deletions weblayer/browser/browser_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "base/path_service.h"
#include "components/base32/base32.h"
#include "content/public/browser/browser_context.h"
#include "weblayer/browser/persistence/browser_persister.h"
#include "weblayer/browser/persistence/minimal_browser_persister.h"
#include "weblayer/browser/persistence/session_service.h"
#include "weblayer/browser/profile_impl.h"
#include "weblayer/browser/tab_impl.h"
#include "weblayer/common/weblayer_paths.h"
Expand Down Expand Up @@ -132,18 +132,18 @@ ScopedJavaLocalRef<jstring> BrowserImpl::GetPersistenceId(
base::android::ConvertUTF8ToJavaString(env, GetPersistenceId()));
}

void BrowserImpl::SaveSessionServiceIfNecessary(
void BrowserImpl::SaveBrowserPersisterIfNecessary(
JNIEnv* env,
const JavaParamRef<jobject>& caller) {
session_service_->SaveIfNecessary();
browser_persister_->SaveIfNecessary();
}

ScopedJavaLocalRef<jbyteArray> BrowserImpl::GetSessionServiceCryptoKey(
ScopedJavaLocalRef<jbyteArray> BrowserImpl::GetBrowserPersisterCryptoKey(
JNIEnv* env,
const JavaParamRef<jobject>& caller) {
std::vector<uint8_t> key;
if (session_service_)
key = session_service_->GetCryptoKey();
if (browser_persister_)
key = browser_persister_->GetCryptoKey();
return base::android::ToJavaByteArray(env, key);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ std::vector<Tab*> BrowserImpl::GetTabs() {
}

void BrowserImpl::PrepareForShutdown() {
session_service_.reset();
browser_persister_.reset();
}

std::string BrowserImpl::GetPersistenceId() {
Expand Down Expand Up @@ -293,8 +293,8 @@ void BrowserImpl::RestoreStateIfNecessary(
const PersistenceInfo& persistence_info) {
persistence_id_ = persistence_info.id;
if (!persistence_id_.empty()) {
session_service_ = std::make_unique<SessionService>(
GetSessionServiceDataPath(), this, persistence_info.last_crypto_key);
browser_persister_ = std::make_unique<BrowserPersister>(
GetBrowserPersisterDataPath(), this, persistence_info.last_crypto_key);
} else if (!persistence_info.minimal_state.empty()) {
RestoreMinimalState(this, persistence_info.minimal_state);
}
Expand All @@ -307,8 +307,8 @@ void BrowserImpl::VisibleSecurityStateOfActiveTabChanged() {
#endif
}

base::FilePath BrowserImpl::GetSessionServiceDataPath() {
base::FilePath base_path = profile_->GetSessionServiceDataBaseDir();
base::FilePath BrowserImpl::GetBrowserPersisterDataPath() {
base::FilePath base_path = profile_->GetBrowserPersisterDataBaseDir();
DCHECK(!GetPersistenceId().empty());
const std::string encoded_name = base32::Base32Encode(GetPersistenceId());
return base_path.AppendASCII("State" + encoded_name);
Expand Down
14 changes: 7 additions & 7 deletions weblayer/browser/browser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class WebContents;

namespace weblayer {

class BrowserPersister;
class ProfileImpl;
class SessionService;
class TabImpl;

class BrowserImpl : public Browser {
Expand All @@ -36,7 +36,7 @@ class BrowserImpl : public Browser {
BrowserImpl& operator=(const BrowserImpl&) = delete;
~BrowserImpl() override;

SessionService* session_service() { return session_service_.get(); }
BrowserPersister* browser_persister() { return browser_persister_.get(); }

ProfileImpl* profile() { return profile_; }

Expand Down Expand Up @@ -66,10 +66,10 @@ class BrowserImpl : public Browser {
base::android::ScopedJavaLocalRef<jstring> GetPersistenceId(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& caller);
void SaveSessionServiceIfNecessary(
void SaveBrowserPersisterIfNecessary(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& caller);
base::android::ScopedJavaLocalRef<jbyteArray> GetSessionServiceCryptoKey(
base::android::ScopedJavaLocalRef<jbyteArray> GetBrowserPersisterCryptoKey(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& caller);
base::android::ScopedJavaLocalRef<jbyteArray> GetMinimalPersistenceState(
Expand Down Expand Up @@ -113,8 +113,8 @@ class BrowserImpl : public Browser {

void RestoreStateIfNecessary(const PersistenceInfo& persistence_info);

// Returns the path used by |session_service_|.
base::FilePath GetSessionServiceDataPath();
// Returns the path used by |browser_persister_|.
base::FilePath GetBrowserPersisterDataPath();

#if defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> java_impl_;
Expand All @@ -124,7 +124,7 @@ class BrowserImpl : public Browser {
std::vector<std::unique_ptr<Tab>> tabs_;
TabImpl* active_tab_ = nullptr;
std::string persistence_id_;
std::unique_ptr<SessionService> session_service_;
std::unique_ptr<BrowserPersister> browser_persister_;
};

} // namespace weblayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public void onSaveInstanceState(Bundle outState) {
if (mProfile.isIncognito() && hasPersistenceId) {
// Trigger a save now as saving may generate a new crypto key. This doesn't actually
// save synchronously, rather triggers a save on a background task runner.
BrowserImplJni.get().saveSessionServiceIfNecessary(mNativeBrowser, this);
BrowserImplJni.get().saveBrowserPersisterIfNecessary(mNativeBrowser, this);
outState.putByteArray(SAVED_STATE_SESSION_SERVICE_CRYPTO_KEY,
BrowserImplJni.get().getSessionServiceCryptoKey(mNativeBrowser, this));
BrowserImplJni.get().getBrowserPersisterCryptoKey(mNativeBrowser, this));
} else if (!hasPersistenceId) {
outState.putByteArray(SAVED_STATE_MINIMAL_PERSISTENCE_STATE_KEY,
BrowserImplJni.get().getMinimalPersistenceState(mNativeBrowser, this));
Expand Down Expand Up @@ -401,8 +401,8 @@ interface Natives {
TabImpl getActiveTab(long nativeBrowserImpl, BrowserImpl browser);
void prepareForShutdown(long nativeBrowserImpl, BrowserImpl browser);
String getPersistenceId(long nativeBrowserImpl, BrowserImpl browser);
void saveSessionServiceIfNecessary(long nativeBrowserImpl, BrowserImpl browser);
byte[] getSessionServiceCryptoKey(long nativeBrowserImpl, BrowserImpl browser);
void saveBrowserPersisterIfNecessary(long nativeBrowserImpl, BrowserImpl browser);
byte[] getBrowserPersisterCryptoKey(long nativeBrowserImpl, BrowserImpl browser);
byte[] getMinimalPersistenceState(long nativeBrowserImpl, BrowserImpl browser);
void restoreStateIfNecessary(long nativeBrowserImpl, BrowserImpl browser,
String persistenceId, byte[] persistenceCryptoKey, byte[] minimalPersistenceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "weblayer/browser/persistence/session_service.h"
#include "weblayer/browser/persistence/browser_persister.h"

#include <stddef.h>

Expand Down Expand Up @@ -48,11 +48,12 @@ int GetIndexOfTab(BrowserImpl* browser, Tab* tab) {
// Every kWritesPerReset commands triggers recreating the file.
constexpr int kWritesPerReset = 250;

// SessionService -------------------------------------------------------------
// BrowserPersister
// -------------------------------------------------------------

SessionService::SessionService(const base::FilePath& path,
BrowserImpl* browser,
const std::vector<uint8_t>& decryption_key)
BrowserPersister::BrowserPersister(const base::FilePath& path,
BrowserImpl* browser,
const std::vector<uint8_t>& decryption_key)
: browser_(browser),
browser_session_id_(SessionID::NewUnique()),
command_storage_manager_(
Expand All @@ -64,30 +65,30 @@ SessionService::SessionService(const base::FilePath& path,
crypto_key_(decryption_key) {
browser_->AddObserver(this);
command_storage_manager_->ScheduleGetCurrentSessionCommands(
base::BindOnce(&SessionService::OnGotCurrentSessionCommands,
base::BindOnce(&BrowserPersister::OnGotCurrentSessionCommands,
base::Unretained(this)),
decryption_key, &cancelable_task_tracker_);
}

SessionService::~SessionService() {
BrowserPersister::~BrowserPersister() {
SaveIfNecessary();
browser_->RemoveObserver(this);
}

void SessionService::SaveIfNecessary() {
void BrowserPersister::SaveIfNecessary() {
if (command_storage_manager_->HasPendingSave())
command_storage_manager_->Save();
}

const std::vector<uint8_t>& SessionService::GetCryptoKey() const {
const std::vector<uint8_t>& BrowserPersister::GetCryptoKey() const {
return crypto_key_;
}

bool SessionService::ShouldUseDelayedSave() {
bool BrowserPersister::ShouldUseDelayedSave() {
return true;
}

void SessionService::OnWillSaveCommands() {
void BrowserPersister::OnWillSaveCommands() {
if (!rebuild_on_next_save_)
return;

Expand All @@ -98,11 +99,12 @@ void SessionService::OnWillSaveCommands() {
BuildCommandsForBrowser();
}

void SessionService::OnGeneratedNewCryptoKey(const std::vector<uint8_t>& key) {
void BrowserPersister::OnGeneratedNewCryptoKey(
const std::vector<uint8_t>& key) {
crypto_key_ = key;
}

void SessionService::OnTabAdded(Tab* tab) {
void BrowserPersister::OnTabAdded(Tab* tab) {
content::WebContents* web_contents =
static_cast<TabImpl*>(tab)->web_contents();
auto* tab_helper = sessions::SessionTabHelper::FromWebContents(web_contents);
Expand All @@ -127,7 +129,7 @@ void SessionService::OnTabAdded(Tab* tab) {
}
}

void SessionService::OnTabRemoved(Tab* tab, bool active_tab_changed) {
void BrowserPersister::OnTabRemoved(Tab* tab, bool active_tab_changed) {
// Allow the associated sessionStorage to get deleted; it won't be needed
// in the session restore.
content::WebContents* web_contents =
Expand All @@ -150,7 +152,7 @@ void SessionService::OnTabRemoved(Tab* tab, bool active_tab_changed) {
tab_to_available_range_.erase(i);
}

void SessionService::OnActiveTabChanged(Tab* tab) {
void BrowserPersister::OnActiveTabChanged(Tab* tab) {
if (rebuild_on_next_save_)
return;

Expand All @@ -159,7 +161,7 @@ void SessionService::OnActiveTabChanged(Tab* tab) {
browser_session_id_, index));
}

void SessionService::SetTabUserAgentOverride(
void BrowserPersister::SetTabUserAgentOverride(
const SessionID& window_id,
const SessionID& tab_id,
const std::string& user_agent_override) {
Expand All @@ -170,9 +172,9 @@ void SessionService::SetTabUserAgentOverride(
tab_id, user_agent_override));
}

void SessionService::SetSelectedNavigationIndex(const SessionID& window_id,
const SessionID& tab_id,
int index) {
void BrowserPersister::SetSelectedNavigationIndex(const SessionID& window_id,
const SessionID& tab_id,
int index) {
if (rebuild_on_next_save_)
return;

Expand All @@ -189,7 +191,7 @@ void SessionService::SetSelectedNavigationIndex(const SessionID& window_id,
sessions::CreateSetSelectedNavigationIndexCommand(tab_id, index));
}

void SessionService::UpdateTabNavigation(
void BrowserPersister::UpdateTabNavigation(
const SessionID& window_id,
const SessionID& tab_id,
const SerializedNavigationEntry& navigation) {
Expand All @@ -204,10 +206,10 @@ void SessionService::UpdateTabNavigation(
ScheduleCommand(CreateUpdateTabNavigationCommand(tab_id, navigation));
}

void SessionService::TabNavigationPathPruned(const SessionID& window_id,
const SessionID& tab_id,
int index,
int count) {
void BrowserPersister::TabNavigationPathPruned(const SessionID& window_id,
const SessionID& tab_id,
int index,
int count) {
if (rebuild_on_next_save_)
return;

Expand Down Expand Up @@ -241,8 +243,9 @@ void SessionService::TabNavigationPathPruned(const SessionID& window_id,
sessions::CreateTabNavigationPathPrunedCommand(tab_id, index, count));
}

void SessionService::TabNavigationPathEntriesDeleted(const SessionID& window_id,
const SessionID& tab_id) {
void BrowserPersister::TabNavigationPathEntriesDeleted(
const SessionID& window_id,
const SessionID& tab_id) {
if (rebuild_on_next_save_)
return;

Expand All @@ -252,19 +255,19 @@ void SessionService::TabNavigationPathEntriesDeleted(const SessionID& window_id,
command_storage_manager_->StartSaveTimer();
}

void SessionService::ScheduleRebuildOnNextSave() {
void BrowserPersister::ScheduleRebuildOnNextSave() {
rebuild_on_next_save_ = true;
command_storage_manager_->StartSaveTimer();
}

void SessionService::OnGotCurrentSessionCommands(
void BrowserPersister::OnGotCurrentSessionCommands(
std::vector<std::unique_ptr<sessions::SessionCommand>> commands) {
ScheduleRebuildOnNextSave();

RestoreBrowserState(browser_, std::move(commands));
}

void SessionService::BuildCommandsForTab(TabImpl* tab, int index_in_browser) {
void BrowserPersister::BuildCommandsForTab(TabImpl* tab, int index_in_browser) {
command_storage_manager_->AppendRebuildCommands(
BuildCommandsForTabConfiguration(browser_session_id_, tab,
index_in_browser));
Expand Down Expand Up @@ -303,8 +306,8 @@ void SessionService::BuildCommandsForTab(TabImpl* tab, int index_in_browser) {
session_id, session_storage_namespace->id()));
}

void SessionService::BuildCommandsForBrowser() {
// This is necessary for SessionService to restore the browser. The type is
void BrowserPersister::BuildCommandsForBrowser() {
// This is necessary for BrowserPersister to restore the browser. The type is
// effectively ignored.
command_storage_manager_->AppendRebuildCommand(
sessions::CreateSetWindowTypeCommand(
Expand All @@ -325,7 +328,7 @@ void SessionService::BuildCommandsForBrowser() {
active_index));
}

void SessionService::ScheduleCommand(
void BrowserPersister::ScheduleCommand(
std::unique_ptr<sessions::SessionCommand> command) {
DCHECK(command);
if (ReplacePendingCommand(command_storage_manager_.get(), &command))
Expand Down
Loading

0 comments on commit 9843d0a

Please sign in to comment.