Commit 2236b777 authored by Chris Mumford's avatar Chris Mumford Committed by Chromium LUCI CQ

indexeddb: Make IndexedDBContextImpl::data_path_ constant.

Make IndexedDBContextImpl::data_path_ a constant member as it is
never changed. Doing so makes it easier to reason about safe
access on different sequences. set_data_path_for_testing() existed,
and was used by IndexedDBQuotaClientTest, but was only ever set to
the same path passed to the IndexedDBContextImpl constructor.

Also make IndexedDBContextImpl::data_path() return a const reference
to avoid unnecessary creation of intermediate base::FilePath
instances.

Bug: none
Change-Id: If7c5a960c30dd7d4858fd332437548d7363247d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606651Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/master@{#839666}
parent 6b33d8f7
......@@ -135,13 +135,13 @@ IndexedDBContextImpl::IndexedDBContextImpl(
// BLOCK_SHUTDOWN to support clearing session-only storage.
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}))),
dispatcher_host_(this, std::move(io_task_runner)),
data_path_(data_path.empty() ? base::FilePath()
: data_path.Append(kIndexedDBDirectory)),
force_keep_session_state_(false),
quota_manager_proxy_(quota_manager_proxy),
clock_(clock),
filesystem_proxy_(storage::CreateFilesystemProxy()) {
IDB_TRACE("init");
if (!data_path.empty())
data_path_ = data_path.Append(kIndexedDBDirectory);
quota_manager_proxy->RegisterClient(
base::MakeRefCounted<IndexedDBQuotaClient>(this),
storage::QuotaClientType::kIndexedDatabase,
......
......@@ -178,16 +178,11 @@ class CONTENT_EXPORT IndexedDBContextImpl
// order.
std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const;
base::FilePath data_path() const { return data_path_; }
const base::FilePath& data_path() const { return data_path_; }
bool IsInMemoryContext() const { return data_path_.empty(); }
size_t GetConnectionCountSync(const url::Origin& origin);
int GetOriginBlobFileCount(const url::Origin& origin);
// For unit tests allow to override the |data_path_|.
void set_data_path_for_testing(const base::FilePath& data_path) {
data_path_ = data_path;
}
bool is_incognito() const { return data_path_.empty(); }
storage::mojom::BlobStorageContext* blob_storage_context() const {
......@@ -246,7 +241,7 @@ class CONTENT_EXPORT IndexedDBContextImpl
// If |data_path_| is empty then this is an incognito session and the backing
// store will be held in-memory rather than on-disk.
base::FilePath data_path_;
const base::FilePath data_path_;
// If true, nothing (not even session-only data) should be deleted on exit.
bool force_keep_session_state_;
......
......@@ -67,10 +67,7 @@ class IndexedDBQuotaClientTest : public testing::Test {
void CreateTempDir() { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
void SetupTempDir() {
base::FilePath indexeddb_dir =
temp_dir_.GetPath().Append(IndexedDBContextImpl::kIndexedDBDirectory);
ASSERT_TRUE(base::CreateDirectory(indexeddb_dir));
idb_context()->set_data_path_for_testing(indexeddb_dir);
ASSERT_TRUE(base::CreateDirectory(idb_context_->data_path()));
}
~IndexedDBQuotaClientTest() override {
......
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