Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StorageBuckets: Constructing path for QuotaClientType & BucketLocator
This change adds a function in QuotaManagerProxy that constructs file path for a bucket and QuotaClientType. This will be the new path for StorageBucket/Storage Partitioned data persisted to disk. The follow the following path structure. {{storage_partition_path}}/WebStorage/{{bucket_id}}/ - CacheStorage/ - IndexedDB/ - FileSystem/ - ScriptCache/ Design discussion docs: FilePath Discussion: https://docs.google.com/document/d/1G4m8ImZlIGNrpn_IyaWoLR_RLDMe3py8ifWaEyH3Pec/edit?usp=sharing FilePath Design: https://docs.google.com/document/d/1D9Euw9ZgMw2YADFcuOmGj1QAT3e-4V_K6y8MMHxofEQ/edit?usp=sharing&resourcekey=0-MQc2XFLLf7Nl3cWdTY3qtg Bug: 1305365 Change-Id: Iddfcc1d803c1c72117992bf5d0583e77fdf91037 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3537328 Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Commit-Queue: Ayu Ishii <ayui@chromium.org> Cr-Commit-Position: refs/heads/main@{#983981}
- Loading branch information
Showing
12 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2022 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 "storage/browser/quota/quota_manager_proxy.h" | ||
#include "base/files/scoped_temp_dir.h" | ||
#include "base/memory/scoped_refptr.h" | ||
#include "base/strings/string_number_conversions.h" | ||
#include "base/test/task_environment.h" | ||
#include "base/test/test_future.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
#include "components/services/storage/public/cpp/buckets/bucket_info.h" | ||
#include "components/services/storage/public/cpp/constants.h" | ||
#include "components/services/storage/public/cpp/quota_error_or.h" | ||
#include "storage/browser/quota/quota_client_type.h" | ||
#include "storage/browser/quota/quota_manager_impl.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/blink/public/common/storage_key/storage_key.h" | ||
|
||
namespace storage { | ||
|
||
class QuotaManagerProxyTest : public testing::Test { | ||
public: | ||
void SetUp() override { | ||
EXPECT_TRUE(profile_path_.CreateUniqueTempDir()); | ||
quota_manager_ = base::MakeRefCounted<QuotaManagerImpl>( | ||
/*is_incognito*/ false, profile_path_.GetPath(), | ||
base::ThreadTaskRunnerHandle::Get().get(), | ||
/*quota_change_callback=*/base::DoNothing(), | ||
/*storage_policy=*/nullptr, GetQuotaSettingsFunc()); | ||
quota_manager_proxy_ = base::MakeRefCounted<QuotaManagerProxy>( | ||
quota_manager_.get(), base::ThreadTaskRunnerHandle::Get(), | ||
profile_path_.GetPath()); | ||
} | ||
|
||
void TearDown() override { | ||
quota_manager_proxy_ = nullptr; | ||
quota_manager_ = nullptr; | ||
} | ||
|
||
protected: | ||
base::ScopedTempDir profile_path_; | ||
scoped_refptr<QuotaManagerImpl> quota_manager_; | ||
scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | ||
|
||
base::test::TaskEnvironment task_environment_; | ||
}; | ||
|
||
TEST_F(QuotaManagerProxyTest, GetBucketPath) { | ||
base::test::TestFuture<storage::QuotaErrorOr<storage::BucketInfo>> future; | ||
quota_manager_proxy_->GetOrCreateBucket( | ||
blink::StorageKey::CreateFromStringForTesting("http://example.com"), | ||
"draft_bucket", base::ThreadTaskRunnerHandle::Get(), | ||
future.GetCallback()); | ||
auto bucket = future.Take(); | ||
EXPECT_TRUE(bucket.ok()); | ||
|
||
base::FilePath expected_path = | ||
profile_path_.GetPath() | ||
.AppendASCII("WebStorage") | ||
.AppendASCII(base::NumberToString(bucket->id.value())); | ||
EXPECT_EQ(quota_manager_proxy_->GetBucketPath(bucket->ToBucketLocator()), | ||
expected_path); | ||
} | ||
|
||
TEST_F(QuotaManagerProxyTest, GetClientBucketPath) { | ||
base::test::TestFuture<storage::QuotaErrorOr<storage::BucketInfo>> future; | ||
quota_manager_proxy_->GetOrCreateBucket( | ||
blink::StorageKey::CreateFromStringForTesting("http://example.com"), | ||
"draft_bucket", base::ThreadTaskRunnerHandle::Get(), | ||
future.GetCallback()); | ||
auto bucket = future.Take(); | ||
EXPECT_TRUE(bucket.ok()); | ||
|
||
base::FilePath bucket_path = | ||
profile_path_.GetPath() | ||
.AppendASCII("WebStorage") | ||
.AppendASCII(base::NumberToString(bucket->id.value())); | ||
|
||
// FileSystem | ||
base::FilePath expected_path = bucket_path.AppendASCII("FileSystem"); | ||
EXPECT_EQ(quota_manager_proxy_->GetClientBucketPath( | ||
bucket->ToBucketLocator(), QuotaClientType::kFileSystem), | ||
expected_path); | ||
|
||
// IndexedDb | ||
expected_path = bucket_path.AppendASCII("IndexedDB"); | ||
EXPECT_EQ(quota_manager_proxy_->GetClientBucketPath( | ||
bucket->ToBucketLocator(), QuotaClientType::kIndexedDatabase), | ||
expected_path); | ||
|
||
// BackgroundFetch/CacheStorage | ||
expected_path = bucket_path.AppendASCII("CacheStorage"); | ||
EXPECT_EQ(quota_manager_proxy_->GetClientBucketPath( | ||
bucket->ToBucketLocator(), QuotaClientType::kBackgroundFetch), | ||
expected_path); | ||
EXPECT_EQ( | ||
quota_manager_proxy_->GetClientBucketPath( | ||
bucket->ToBucketLocator(), QuotaClientType::kServiceWorkerCache), | ||
expected_path); | ||
|
||
// ServiceWorker | ||
expected_path = bucket_path.AppendASCII("ScriptCache"); | ||
EXPECT_EQ(quota_manager_proxy_->GetClientBucketPath( | ||
bucket->ToBucketLocator(), QuotaClientType::kServiceWorker), | ||
expected_path); | ||
} | ||
|
||
} // namespace storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters