Refactor QuotaManagerImpl to use StorageKey
This is part of an effort to move the storage APIs to use StorageKey instead of Origin. For now, the call sites of QuotaManagerImpl (of which there are many) have been changed to convert an Origin to a StorageKey before calling the QuotaManager APIs. Subsequent CLs will continue to convert Origin usage to StorageKey at the call sites. Bug: 1215208 Change-Id: I63937964cd8185e617eb29998fabd9ac55734555 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2957857 Commit-Queue: Ali Beyad <abeyad@chromium.org> Reviewed-by: Joshua Bell <jsbell@chromium.org> Reviewed-by: Ayu Ishii <ayui@chromium.org> Reviewed-by: Marijn Kruisselbrink <mek@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Cr-Commit-Position: refs/heads/master@{#894015}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f30e1f3f82
commit
8e89cdb65f
android_webview/browser
chrome/browser
apps
platform_apps
api
sync_file_system
browsing_data
sync_file_system
ui
webui
quota_internals
content/browser
cache_storage
cache_storage_blob_to_disk_cache_unittest.cccache_storage_cache_unittest.cccache_storage_manager_unittest.cc
devtools
protocol
indexed_db
native_io
quota
storage_partition_impl.ccstorage_partition_impl_unittest.ccstorage/browser
file_system
copy_or_move_operation_delegate_unittest.ccfile_system_operation_impl_unittest.ccfile_system_operation_impl_write_unittest.ccsandbox_file_stream_writer_unittest.cc
quota
quota_callbacks.hquota_manager_impl.ccquota_manager_impl.hquota_manager_proxy.ccquota_manager_unittest.ccquota_temporary_storage_evictor.ccquota_temporary_storage_evictor.hquota_temporary_storage_evictor_unittest.cc
test
@ -93,6 +93,7 @@ include_rules = [
|
||||
"+storage/common/quota",
|
||||
|
||||
"+third_party/blink/public/common/page_state/page_state.h",
|
||||
"+third_party/blink/public/common/storage_key/storage_key.h",
|
||||
"+third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h",
|
||||
"+third_party/crashpad/crashpad/client",
|
||||
"+third_party/crashpad/crashpad/util",
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
@ -39,21 +40,22 @@ namespace {
|
||||
// there are no concurrent accesses to instance variables. Also this object
|
||||
// is refcounted in the various callbacks, and is destroyed when all callbacks
|
||||
// are destroyed at the end of DoneOnUIThread.
|
||||
class GetOriginsTask : public base::RefCountedThreadSafe<GetOriginsTask> {
|
||||
class GetStorageKeysTask
|
||||
: public base::RefCountedThreadSafe<GetStorageKeysTask> {
|
||||
public:
|
||||
GetOriginsTask(AwQuotaManagerBridge::GetOriginsCallback callback,
|
||||
QuotaManager* quota_manager);
|
||||
GetStorageKeysTask(AwQuotaManagerBridge::GetOriginsCallback callback,
|
||||
QuotaManager* quota_manager);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<GetOriginsTask>;
|
||||
~GetOriginsTask();
|
||||
friend class base::RefCountedThreadSafe<GetStorageKeysTask>;
|
||||
~GetStorageKeysTask();
|
||||
|
||||
void OnOriginsObtained(const std::set<url::Origin>& origins,
|
||||
blink::mojom::StorageType type);
|
||||
void OnStorageKeysObtained(const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type);
|
||||
|
||||
void OnUsageAndQuotaObtained(const url::Origin& origin,
|
||||
void OnUsageAndQuotaObtained(const blink::StorageKey& storage_key,
|
||||
blink::mojom::QuotaStatusCode status_code,
|
||||
int64_t usage,
|
||||
int64_t quota);
|
||||
@ -71,52 +73,55 @@ class GetOriginsTask : public base::RefCountedThreadSafe<GetOriginsTask> {
|
||||
size_t num_callbacks_to_wait_;
|
||||
size_t num_callbacks_received_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GetOriginsTask);
|
||||
DISALLOW_COPY_AND_ASSIGN(GetStorageKeysTask);
|
||||
};
|
||||
|
||||
GetOriginsTask::GetOriginsTask(
|
||||
GetStorageKeysTask::GetStorageKeysTask(
|
||||
AwQuotaManagerBridge::GetOriginsCallback callback,
|
||||
QuotaManager* quota_manager)
|
||||
: ui_callback_(std::move(callback)), quota_manager_(quota_manager) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
}
|
||||
|
||||
GetOriginsTask::~GetOriginsTask() {}
|
||||
GetStorageKeysTask::~GetStorageKeysTask() {}
|
||||
|
||||
void GetOriginsTask::Run() {
|
||||
void GetStorageKeysTask::Run() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
content::GetIOThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&QuotaManager::GetOriginsModifiedBetween, quota_manager_,
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::Time() /* Since beginning of time. */,
|
||||
base::Time::Max() /* Until the end of times */,
|
||||
base::BindOnce(&GetOriginsTask::OnOriginsObtained, this)));
|
||||
base::BindOnce(
|
||||
&QuotaManager::GetStorageKeysModifiedBetween, quota_manager_,
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::Time() /* Since beginning of time. */,
|
||||
base::Time::Max() /* Until the end of time. */,
|
||||
base::BindOnce(&GetStorageKeysTask::OnStorageKeysObtained, this)));
|
||||
}
|
||||
|
||||
void GetOriginsTask::OnOriginsObtained(const std::set<url::Origin>& origins,
|
||||
blink::mojom::StorageType type) {
|
||||
void GetStorageKeysTask::OnStorageKeysObtained(
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
num_callbacks_to_wait_ = origins.size();
|
||||
num_callbacks_to_wait_ = storage_keys.size();
|
||||
num_callbacks_received_ = 0u;
|
||||
|
||||
for (const url::Origin& origin : origins) {
|
||||
for (const blink::StorageKey& storage_key : storage_keys) {
|
||||
quota_manager_->GetUsageAndQuota(
|
||||
origin, type,
|
||||
base::BindOnce(&GetOriginsTask::OnUsageAndQuotaObtained, this, origin));
|
||||
storage_key, type,
|
||||
base::BindOnce(&GetStorageKeysTask::OnUsageAndQuotaObtained, this,
|
||||
storage_key));
|
||||
}
|
||||
|
||||
CheckDone();
|
||||
}
|
||||
|
||||
void GetOriginsTask::OnUsageAndQuotaObtained(
|
||||
const url::Origin& origin,
|
||||
void GetStorageKeysTask::OnUsageAndQuotaObtained(
|
||||
const blink::StorageKey& storage_key,
|
||||
blink::mojom::QuotaStatusCode status_code,
|
||||
int64_t usage,
|
||||
int64_t quota) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (status_code == blink::mojom::QuotaStatusCode::kOk) {
|
||||
origin_.push_back(origin.GetURL().spec());
|
||||
origin_.push_back(storage_key.origin().GetURL().spec());
|
||||
usage_.push_back(usage);
|
||||
quota_.push_back(quota);
|
||||
}
|
||||
@ -125,18 +130,18 @@ void GetOriginsTask::OnUsageAndQuotaObtained(
|
||||
CheckDone();
|
||||
}
|
||||
|
||||
void GetOriginsTask::CheckDone() {
|
||||
void GetStorageKeysTask::CheckDone() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (num_callbacks_received_ == num_callbacks_to_wait_) {
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE, base::BindOnce(&GetOriginsTask::DoneOnUIThread, this));
|
||||
FROM_HERE, base::BindOnce(&GetStorageKeysTask::DoneOnUIThread, this));
|
||||
} else if (num_callbacks_received_ > num_callbacks_to_wait_) {
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
// This method is to avoid copying the 3 vector arguments into a bound callback.
|
||||
void GetOriginsTask::DoneOnUIThread() {
|
||||
void GetStorageKeysTask::DoneOnUIThread() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
std::move(ui_callback_).Run(origin_, usage_, quota_);
|
||||
}
|
||||
@ -239,8 +244,8 @@ void AwQuotaManagerBridge::GetOriginsOnUiThread(jint callback_id) {
|
||||
GetOriginsCallback ui_callback =
|
||||
base::BindOnce(&AwQuotaManagerBridge::GetOriginsCallbackImpl,
|
||||
weak_factory_.GetWeakPtr(), callback_id);
|
||||
base::MakeRefCounted<GetOriginsTask>(std::move(ui_callback),
|
||||
GetQuotaManager())
|
||||
base::MakeRefCounted<GetStorageKeysTask>(std::move(ui_callback),
|
||||
GetQuotaManager())
|
||||
->Run();
|
||||
}
|
||||
|
||||
@ -306,7 +311,7 @@ void AwQuotaManagerBridge::GetUsageAndQuotaForOriginOnUiThread(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
&QuotaManager::GetUsageAndQuota, GetQuotaManager(),
|
||||
url::Origin::Create(GURL(origin)),
|
||||
blink::StorageKey(url::Origin::Create(GURL(origin))),
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::BindOnce(&OnUsageAndQuotaObtained, std::move(ui_callback))));
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ namespace android_webview {
|
||||
|
||||
class AwBrowserContext;
|
||||
|
||||
// TODO(crbug.com/1215208): Change the functions in this class to reference
|
||||
// StorageKey instead of Origin.
|
||||
class AwQuotaManagerBridge
|
||||
: public base::RefCountedThreadSafe<AwQuotaManagerBridge> {
|
||||
public:
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "storage/common/file_system/file_system_types.h"
|
||||
#include "storage/common/file_system/file_system_util.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
using content::BrowserContext;
|
||||
@ -337,7 +338,7 @@ SyncFileSystemGetUsageAndQuotaFunction::Run() {
|
||||
FROM_HERE,
|
||||
BindOnce(
|
||||
&storage::QuotaManager::GetUsageAndQuotaForWebApps, quota_manager,
|
||||
url::Origin::Create(source_url()),
|
||||
blink::StorageKey(url::Origin::Create(source_url())),
|
||||
storage::FileSystemTypeToQuotaStorageType(file_system_url.type()),
|
||||
BindOnce(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota,
|
||||
this)));
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
@ -77,23 +78,23 @@ void BrowsingDataQuotaHelperImpl::FetchQuotaInfoOnIOThread(
|
||||
base::Owned(pending_hosts)));
|
||||
|
||||
for (const StorageType& type : types) {
|
||||
quota_manager_->GetOriginsModifiedBetween(
|
||||
quota_manager_->GetStorageKeysModifiedBetween(
|
||||
type, base::Time(), base::Time::Max(),
|
||||
base::BindOnce(&BrowsingDataQuotaHelperImpl::GotOrigins,
|
||||
base::BindOnce(&BrowsingDataQuotaHelperImpl::GotStorageKeys,
|
||||
weak_factory_.GetWeakPtr(), pending_hosts, completion));
|
||||
}
|
||||
}
|
||||
|
||||
void BrowsingDataQuotaHelperImpl::GotOrigins(
|
||||
void BrowsingDataQuotaHelperImpl::GotStorageKeys(
|
||||
PendingHosts* pending_hosts,
|
||||
base::OnceClosure completion,
|
||||
const std::set<url::Origin>& origins,
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
StorageType type) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
for (const url::Origin& origin : origins) {
|
||||
if (!browsing_data::IsWebScheme(origin.scheme()))
|
||||
for (const blink::StorageKey& storage_key : storage_keys) {
|
||||
if (!browsing_data::IsWebScheme(storage_key.origin().scheme()))
|
||||
continue; // Non-websafe state is not considered browsing data.
|
||||
pending_hosts->insert(std::make_pair(origin.host(), type));
|
||||
pending_hosts->insert(std::make_pair(storage_key.origin().host(), type));
|
||||
}
|
||||
std::move(completion).Run();
|
||||
}
|
||||
|
@ -19,12 +19,12 @@
|
||||
#include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h"
|
||||
|
||||
namespace storage {
|
||||
class QuotaManager;
|
||||
namespace blink {
|
||||
class StorageKey;
|
||||
}
|
||||
|
||||
namespace url {
|
||||
class Origin;
|
||||
namespace storage {
|
||||
class QuotaManager;
|
||||
}
|
||||
|
||||
// Implementation of BrowsingDataQuotaHelper. Since a client of
|
||||
@ -43,14 +43,14 @@ class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper {
|
||||
explicit BrowsingDataQuotaHelperImpl(storage::QuotaManager* quota_manager);
|
||||
~BrowsingDataQuotaHelperImpl() override;
|
||||
|
||||
// Calls QuotaManager::GetOriginModifiedSince for each storage type.
|
||||
// Calls QuotaManager::GetStorageKeysModifiedBetween for each storage type.
|
||||
void FetchQuotaInfoOnIOThread(FetchResultCallback callback);
|
||||
|
||||
// Callback function for QuotaManager::GetOriginModifiedSince.
|
||||
void GotOrigins(PendingHosts* pending_hosts,
|
||||
base::OnceClosure completion,
|
||||
const std::set<url::Origin>& origins,
|
||||
blink::mojom::StorageType type);
|
||||
// Callback function for QuotaManager::GetStorageKeysModifiedBetween.
|
||||
void GotStorageKeys(PendingHosts* pending_hosts,
|
||||
base::OnceClosure completion,
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type);
|
||||
|
||||
// Calls QuotaManager::GetHostUsage for each (origin, type) pair.
|
||||
void OnGetOriginsComplete(FetchResultCallback callback,
|
||||
|
@ -22,9 +22,9 @@
|
||||
#include "services/network/public/mojom/cookie_manager.mojom.h"
|
||||
#include "storage/browser/file_system/file_system_context.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
#include "components/cdm/browser/media_drm_storage_impl.h" // nogncheck crbug.com/1125897
|
||||
@ -60,11 +60,11 @@ void SiteDataCountingHelper::CountAndDestroySelfWhenFinished() {
|
||||
|
||||
storage::QuotaManager* quota_manager = partition->GetQuotaManager();
|
||||
if (quota_manager) {
|
||||
// Count origins with filesystem, websql, appcache, indexeddb,
|
||||
// Count storage keys with filesystem, websql, appcache, indexeddb,
|
||||
// serviceworkers and cachestorage using quota manager.
|
||||
auto origins_callback =
|
||||
base::BindRepeating(&SiteDataCountingHelper::GetQuotaOriginsCallback,
|
||||
base::Unretained(this));
|
||||
auto storage_keys_callback = base::BindRepeating(
|
||||
&SiteDataCountingHelper::GetQuotaStorageKeysCallback,
|
||||
base::Unretained(this));
|
||||
const blink::mojom::StorageType types[] = {
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
blink::mojom::StorageType::kPersistent,
|
||||
@ -73,8 +73,9 @@ void SiteDataCountingHelper::CountAndDestroySelfWhenFinished() {
|
||||
tasks_ += 1;
|
||||
content::GetIOThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&storage::QuotaManager::GetOriginsModifiedBetween,
|
||||
quota_manager, type, begin_, end_, origins_callback));
|
||||
base::BindOnce(&storage::QuotaManager::GetStorageKeysModifiedBetween,
|
||||
quota_manager, type, begin_, end_,
|
||||
storage_keys_callback));
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,14 +156,14 @@ void SiteDataCountingHelper::GetCookiesCallback(
|
||||
base::Unretained(this), origins));
|
||||
}
|
||||
|
||||
void SiteDataCountingHelper::GetQuotaOriginsCallback(
|
||||
const std::set<url::Origin>& origins,
|
||||
void SiteDataCountingHelper::GetQuotaStorageKeysCallback(
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
std::vector<GURL> urls;
|
||||
urls.resize(origins.size());
|
||||
for (const url::Origin& origin : origins)
|
||||
urls.push_back(origin.GetURL());
|
||||
urls.resize(storage_keys.size());
|
||||
for (const blink::StorageKey& storage_key : storage_keys)
|
||||
urls.push_back(storage_key.origin().GetURL());
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE, base::BindOnce(&SiteDataCountingHelper::Done,
|
||||
base::Unretained(this), std::move(urls)));
|
||||
|
@ -19,12 +19,12 @@
|
||||
class Profile;
|
||||
class HostContentSettingsMap;
|
||||
|
||||
namespace content {
|
||||
struct StorageUsageInfo;
|
||||
namespace blink {
|
||||
class StorageKey;
|
||||
}
|
||||
|
||||
namespace url {
|
||||
class Origin;
|
||||
namespace content {
|
||||
struct StorageUsageInfo;
|
||||
}
|
||||
|
||||
namespace storage {
|
||||
@ -52,8 +52,9 @@ class SiteDataCountingHelper {
|
||||
const scoped_refptr<storage::SpecialStoragePolicy>&
|
||||
special_storage_policy,
|
||||
const std::vector<content::StorageUsageInfo>& infos);
|
||||
void GetQuotaOriginsCallback(const std::set<url::Origin>& origin_set,
|
||||
blink::mojom::StorageType type);
|
||||
void GetQuotaStorageKeysCallback(
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type);
|
||||
void SitesWithMediaLicensesCallback(
|
||||
const std::list<BrowsingDataMediaLicenseHelper::MediaLicenseInfo>&
|
||||
media_license_info_list);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "storage/browser/test/mock_special_storage_policy.h"
|
||||
#include "storage/browser/test/test_file_system_options.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
using base::File;
|
||||
@ -677,7 +678,7 @@ void CannedSyncableFileSystem::DoGetUsageAndQuota(
|
||||
EXPECT_TRUE(is_filesystem_opened_);
|
||||
DCHECK(quota_manager_.get());
|
||||
quota_manager_->GetUsageAndQuota(
|
||||
url::Origin::Create(origin_), storage_type(),
|
||||
blink::StorageKey(url::Origin::Create(origin_)), storage_type(),
|
||||
base::BindOnce(&DidGetUsageAndQuota, std::move(callback), usage, quota));
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ void QuotaInternalsProxy::TriggerStoragePressure(
|
||||
this, origin, quota_manager));
|
||||
return;
|
||||
}
|
||||
quota_manager->SimulateStoragePressure(origin);
|
||||
quota_manager->SimulateStoragePressure(blink::StorageKey(origin));
|
||||
}
|
||||
|
||||
QuotaInternalsProxy::~QuotaInternalsProxy() = default;
|
||||
@ -182,20 +182,21 @@ void QuotaInternalsProxy::DidGetHostUsage(
|
||||
void QuotaInternalsProxy::RequestPerOriginInfo(StorageType type) {
|
||||
DCHECK(quota_manager_.get());
|
||||
|
||||
std::set<url::Origin> origins = quota_manager_->GetCachedOrigins(type);
|
||||
std::set<blink::StorageKey> storage_keys =
|
||||
quota_manager_->GetCachedStorageKeys(type);
|
||||
|
||||
std::vector<PerOriginStorageInfo> origin_info;
|
||||
origin_info.reserve(origins.size());
|
||||
origin_info.reserve(storage_keys.size());
|
||||
|
||||
std::set<std::string> hosts;
|
||||
std::vector<PerHostStorageInfo> host_info;
|
||||
|
||||
for (const url::Origin& origin : origins) {
|
||||
PerOriginStorageInfo info(origin.GetURL(), type);
|
||||
info.set_in_use(quota_manager_->IsOriginInUse(origin));
|
||||
for (const blink::StorageKey& storage_key : storage_keys) {
|
||||
PerOriginStorageInfo info(storage_key.origin().GetURL(), type);
|
||||
info.set_in_use(quota_manager_->IsStorageKeyInUse(storage_key));
|
||||
origin_info.push_back(info);
|
||||
|
||||
const std::string& host = origin.host();
|
||||
const std::string& host = storage_key.origin().host();
|
||||
if (hosts.insert(host).second) {
|
||||
PerHostStorageInfo info(host, type);
|
||||
host_info.push_back(info);
|
||||
|
@ -250,7 +250,7 @@ TEST_F(CacheStorageBlobToDiskCacheTest, NotifyQuotaAboutWriteErrors) {
|
||||
auto write_error_tracker = quota_manager()->write_error_tracker();
|
||||
EXPECT_EQ(1U, write_error_tracker.size());
|
||||
auto write_error_log = write_error_tracker.find(
|
||||
cache_storage_blob_to_disk_cache_->storage_key().origin());
|
||||
cache_storage_blob_to_disk_cache_->storage_key());
|
||||
EXPECT_NE(write_error_tracker.end(), write_error_log);
|
||||
EXPECT_EQ(1, write_error_log->second);
|
||||
}
|
||||
|
@ -983,8 +983,9 @@ class CacheStorageCacheTest : public testing::Test {
|
||||
virtual bool MemoryOnly() { return false; }
|
||||
|
||||
void SetQuota(uint64_t quota) {
|
||||
mock_quota_manager_->SetQuota(url::Origin::Create(kTestUrl),
|
||||
blink::mojom::StorageType::kTemporary, quota);
|
||||
mock_quota_manager_->SetQuota(
|
||||
blink::StorageKey(url::Origin::Create(kTestUrl)),
|
||||
blink::mojom::StorageType::kTemporary, quota);
|
||||
}
|
||||
|
||||
void SetMaxQuerySizeBytes(size_t max_bytes) {
|
||||
|
@ -346,10 +346,10 @@ class CacheStorageManagerTest : public testing::Test {
|
||||
mock_quota_manager_ = base::MakeRefCounted<storage::MockQuotaManager>(
|
||||
MemoryOnly(), temp_dir_path, base::ThreadTaskRunnerHandle::Get().get(),
|
||||
quota_policy_.get());
|
||||
mock_quota_manager_->SetQuota(storage_key1_.origin(),
|
||||
StorageType::kTemporary, 1024 * 1024 * 100);
|
||||
mock_quota_manager_->SetQuota(storage_key2_.origin(),
|
||||
StorageType::kTemporary, 1024 * 1024 * 100);
|
||||
mock_quota_manager_->SetQuota(storage_key1_, StorageType::kTemporary,
|
||||
1024 * 1024 * 100);
|
||||
mock_quota_manager_->SetQuota(storage_key2_, StorageType::kTemporary,
|
||||
1024 * 1024 * 100);
|
||||
|
||||
quota_manager_proxy_ =
|
||||
base::MakeRefCounted<MockCacheStorageQuotaManagerProxy>(
|
||||
|
@ -106,11 +106,11 @@ void GotUsageAndQuotaDataCallback(
|
||||
|
||||
void GetUsageAndQuotaOnIOThread(
|
||||
storage::QuotaManager* manager,
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
std::unique_ptr<StorageHandler::GetUsageAndQuotaCallback> callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
manager->GetUsageAndQuotaForDevtools(
|
||||
origin, blink::mojom::StorageType::kTemporary,
|
||||
storage_key, blink::mojom::StorageType::kTemporary,
|
||||
base::BindOnce(&GotUsageAndQuotaDataCallback, std::move(callback)));
|
||||
}
|
||||
|
||||
@ -413,7 +413,8 @@ void StorageHandler::GetUsageAndQuota(
|
||||
GetIOThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&GetUsageAndQuotaOnIOThread, base::RetainedRef(manager),
|
||||
url::Origin::Create(origin_url), std::move(callback)));
|
||||
blink::StorageKey(url::Origin::Create(origin_url)),
|
||||
std::move(callback)));
|
||||
}
|
||||
|
||||
void StorageHandler::OverrideQuotaForOrigin(
|
||||
|
@ -908,8 +908,7 @@ TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) {
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
ASSERT_EQ(1U, quota_manager()->write_error_tracker().size());
|
||||
EXPECT_EQ(storage_key.origin(),
|
||||
quota_manager()->write_error_tracker().begin()->first);
|
||||
EXPECT_EQ(storage_key, quota_manager()->write_error_tracker().begin()->first);
|
||||
EXPECT_EQ(1, quota_manager()->write_error_tracker().begin()->second);
|
||||
}
|
||||
|
||||
@ -928,8 +927,7 @@ TEST_F(IndexedDBFactoryTest, NotifyQuotaOnDatabaseError) {
|
||||
storage_key, leveldb::Status::IOError("Disk is full."), "Disk is full.");
|
||||
base::RunLoop().RunUntilIdle();
|
||||
ASSERT_EQ(1U, quota_manager()->write_error_tracker().size());
|
||||
EXPECT_EQ(storage_key.origin(),
|
||||
quota_manager()->write_error_tracker().begin()->first);
|
||||
EXPECT_EQ(storage_key, quota_manager()->write_error_tracker().begin()->first);
|
||||
EXPECT_EQ(1, quota_manager()->write_error_tracker().begin()->second);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include "content/shell/browser/shell.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "storage/common/database/database_identifier.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -68,13 +68,13 @@ class NativeIOManagerBrowserTest : public ContentBrowserTest {
|
||||
|
||||
static void DeleteNativeIODataOnIOThread(
|
||||
scoped_refptr<storage::QuotaManager> quota_manager,
|
||||
url::Origin origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
base::OnceCallback<void(blink::mojom::QuotaStatusCode)> callback) {
|
||||
storage::QuotaClientTypes nativeio_quota_client_type;
|
||||
nativeio_quota_client_type.insert(storage::QuotaClientType::kNativeIO);
|
||||
|
||||
quota_manager->DeleteOriginData(
|
||||
origin, blink::mojom::StorageType::kTemporary,
|
||||
quota_manager->DeleteStorageKeyData(
|
||||
storage_key, blink::mojom::StorageType::kTemporary,
|
||||
nativeio_quota_client_type, std::move(callback));
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ IN_PROC_BROWSER_TEST_F(NativeIOManagerBrowserTest,
|
||||
blink::mojom::QuotaStatusCode deletion_result;
|
||||
RunOnIOThreadBlocking(base::BindOnce(
|
||||
&NativeIOManagerBrowserTest::DeleteNativeIODataOnIOThread, quota_manager,
|
||||
url::Origin::Create(test_url),
|
||||
blink::StorageKey::CreateFromStringForTesting(test_url.spec()),
|
||||
base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode result) {
|
||||
deletion_result = result;
|
||||
run_loop.Quit();
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "storage/browser/quota/quota_device_info_helper.h"
|
||||
#include "storage/browser/quota/quota_features.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
|
||||
|
||||
using storage::QuotaManager;
|
||||
@ -72,11 +73,12 @@ class QuotaChangeBrowserTest : public ContentBrowserTest,
|
||||
void TriggerStoragePressureCheck(const GURL& test_url) {
|
||||
GetIOThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&QuotaManager::GetUsageAndQuotaForWebApps,
|
||||
quota_manager(), url::Origin::Create(test_url),
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::DoNothing::Once<blink::mojom::QuotaStatusCode,
|
||||
int64_t, int64_t>()));
|
||||
base::BindOnce(
|
||||
&QuotaManager::GetUsageAndQuotaForWebApps, quota_manager(),
|
||||
blink::StorageKey::CreateFromStringForTesting(test_url.spec()),
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::DoNothing::Once<blink::mojom::QuotaStatusCode, int64_t,
|
||||
int64_t>()));
|
||||
}
|
||||
|
||||
Shell* browser() {
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
@ -37,7 +38,7 @@ QuotaManagerHost::QuotaManagerHost(
|
||||
scoped_refptr<QuotaChangeDispatcher> quota_change_dispatcher)
|
||||
: process_id_(process_id),
|
||||
render_frame_id_(render_frame_id),
|
||||
origin_(origin),
|
||||
storage_key_(blink::StorageKey(origin)),
|
||||
quota_manager_(quota_manager),
|
||||
permission_context_(permission_context),
|
||||
quota_change_dispatcher_(std::move(quota_change_dispatcher)) {
|
||||
@ -50,7 +51,9 @@ void QuotaManagerHost::AddChangeListener(
|
||||
mojo::PendingRemote<blink::mojom::QuotaChangeListener> mojo_listener,
|
||||
AddChangeListenerCallback callback) {
|
||||
if (quota_change_dispatcher_) {
|
||||
quota_change_dispatcher_->AddChangeListener(origin_,
|
||||
// TODO(crbug.com/1215208): Change to StorageKey instead of an Origin when
|
||||
// the QuotaChangeDispatcher interface has changed.
|
||||
quota_change_dispatcher_->AddChangeListener(storage_key_.origin(),
|
||||
std::move(mojo_listener));
|
||||
}
|
||||
std::move(callback).Run();
|
||||
@ -60,7 +63,7 @@ void QuotaManagerHost::QueryStorageUsageAndQuota(
|
||||
blink::mojom::StorageType storage_type,
|
||||
QueryStorageUsageAndQuotaCallback callback) {
|
||||
quota_manager_->GetUsageAndQuotaWithBreakdown(
|
||||
origin_, storage_type,
|
||||
storage_key_, storage_type,
|
||||
base::BindOnce(&QuotaManagerHost::DidQueryStorageUsageAndQuota,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||
}
|
||||
@ -81,8 +84,8 @@ void QuotaManagerHost::RequestStorageQuota(
|
||||
return;
|
||||
}
|
||||
|
||||
if (origin_.opaque()) {
|
||||
mojo::ReportBadMessage("Unique origins may not request storage quota.");
|
||||
if (storage_key_.origin().opaque()) {
|
||||
mojo::ReportBadMessage("Opaque origins may not request storage quota.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -90,13 +93,13 @@ void QuotaManagerHost::RequestStorageQuota(
|
||||
storage_type == blink::mojom::StorageType::kPersistent);
|
||||
if (storage_type == blink::mojom::StorageType::kPersistent) {
|
||||
quota_manager_->GetUsageAndQuotaForWebApps(
|
||||
origin_, storage_type,
|
||||
storage_key_, storage_type,
|
||||
base::BindOnce(&QuotaManagerHost::DidGetPersistentUsageAndQuota,
|
||||
weak_factory_.GetWeakPtr(), storage_type, requested_size,
|
||||
std::move(callback)));
|
||||
} else {
|
||||
quota_manager_->GetUsageAndQuotaForWebApps(
|
||||
origin_, storage_type,
|
||||
storage_key_, storage_type,
|
||||
base::BindOnce(&QuotaManagerHost::DidGetTemporaryUsageAndQuota,
|
||||
weak_factory_.GetWeakPtr(), requested_size,
|
||||
std::move(callback)));
|
||||
@ -130,7 +133,7 @@ void QuotaManagerHost::DidGetPersistentUsageAndQuota(
|
||||
// TODO(nhiroki): The backend should accept uint64_t values.
|
||||
int64_t requested_quota_signed =
|
||||
base::saturated_cast<int64_t>(requested_quota);
|
||||
if (quota_manager_->IsStorageUnlimited(origin_, storage_type) ||
|
||||
if (quota_manager_->IsStorageUnlimited(storage_key_, storage_type) ||
|
||||
requested_quota_signed <= current_quota) {
|
||||
std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk, current_usage,
|
||||
requested_quota);
|
||||
@ -142,7 +145,7 @@ void QuotaManagerHost::DidGetPersistentUsageAndQuota(
|
||||
DCHECK(permission_context_);
|
||||
StorageQuotaParams params;
|
||||
params.render_frame_id = render_frame_id_;
|
||||
params.origin_url = origin_.GetURL();
|
||||
params.origin_url = storage_key_.origin().GetURL();
|
||||
params.storage_type = storage_type;
|
||||
params.requested_size = requested_quota;
|
||||
|
||||
@ -168,7 +171,7 @@ void QuotaManagerHost::DidGetPermissionResponse(
|
||||
|
||||
// Otherwise, return the new quota.
|
||||
quota_manager_->SetPersistentHostQuota(
|
||||
origin_.host(), requested_quota,
|
||||
storage_key_.origin().host(), requested_quota,
|
||||
base::BindOnce(&QuotaManagerHost::DidSetHostQuota,
|
||||
weak_factory_.GetWeakPtr(), current_usage,
|
||||
std::move(callback)));
|
||||
|
@ -13,6 +13,10 @@
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_manager_host.mojom.h"
|
||||
|
||||
namespace blink {
|
||||
class StorageKey;
|
||||
}
|
||||
|
||||
namespace storage {
|
||||
class QuotaManager;
|
||||
}
|
||||
@ -39,6 +43,8 @@ class QuotaManagerHost : public blink::mojom::QuotaManagerHost {
|
||||
public:
|
||||
// The owner must guarantee that |quota_manager| and |permission_context|
|
||||
// outlive this instance.
|
||||
// TODO(crbug.com/1215208): Change the constructor to take a StorageKey
|
||||
// instead of an Origin.
|
||||
QuotaManagerHost(
|
||||
int process_id,
|
||||
int render_frame_id,
|
||||
@ -99,8 +105,8 @@ class QuotaManagerHost : public blink::mojom::QuotaManagerHost {
|
||||
// MSG_ROUTING_NONE if this host is connected to a worker.
|
||||
const int render_frame_id_;
|
||||
|
||||
// The origin of the frame or worker connected to this host.
|
||||
const url::Origin origin_;
|
||||
// The storage key of the frame or worker connected to this host.
|
||||
const blink::StorageKey storage_key_;
|
||||
|
||||
// Raw pointer use is safe because the QuotaContext that indirectly owns this
|
||||
// QuotaManagerHost owner holds a reference to the QuotaManager. Therefore
|
||||
|
@ -262,16 +262,16 @@ void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count,
|
||||
}
|
||||
}
|
||||
|
||||
void OnQuotaManagedOriginDeleted(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
size_t* deletion_task_count,
|
||||
base::OnceClosure callback,
|
||||
blink::mojom::QuotaStatusCode status) {
|
||||
void OnQuotaManagedStorageKeyDeleted(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
size_t* deletion_task_count,
|
||||
base::OnceClosure callback,
|
||||
blink::mojom::QuotaStatusCode status) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
DCHECK_GT(*deletion_task_count, 0u);
|
||||
if (status != blink::mojom::QuotaStatusCode::kOk) {
|
||||
DLOG(ERROR) << "Couldn't remove data of type " << static_cast<int>(type)
|
||||
<< " for origin " << origin
|
||||
<< " for storage key " << storage_key.GetDebugString()
|
||||
<< ". Status: " << static_cast<int>(status);
|
||||
}
|
||||
|
||||
@ -867,14 +867,14 @@ class StoragePartitionImpl::QuotaManagedDataDeletionHelper {
|
||||
StoragePartition::OriginMatcherFunction origin_matcher,
|
||||
bool perform_storage_cleanup);
|
||||
|
||||
void ClearOriginsOnIOThread(
|
||||
void ClearStorageKeysOnIOThread(
|
||||
storage::QuotaManager* quota_manager,
|
||||
const scoped_refptr<storage::SpecialStoragePolicy>&
|
||||
special_storage_policy,
|
||||
StoragePartition::OriginMatcherFunction origin_matcher,
|
||||
bool perform_storage_cleanup,
|
||||
base::OnceClosure callback,
|
||||
const std::set<url::Origin>& origins,
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType quota_storage_type);
|
||||
|
||||
private:
|
||||
@ -1160,14 +1160,16 @@ void StoragePartitionImpl::Initialize(
|
||||
// base::Unretained is safe to use because the BrowserContext is guaranteed
|
||||
// to outlive QuotaManager. This is because BrowserContext outlives this
|
||||
// StoragePartitionImpl, which destroys the QuotaManager on teardown.
|
||||
base::RepeatingCallback<void(const url::Origin)>
|
||||
base::RepeatingCallback<void(const blink::StorageKey)>
|
||||
send_notification_function = base::BindRepeating(
|
||||
[](StorageNotificationService* service, const url::Origin origin) {
|
||||
[](StorageNotificationService* service,
|
||||
const blink::StorageKey storage_key) {
|
||||
GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&StorageNotificationService::
|
||||
MaybeShowStoragePressureNotification,
|
||||
base::Unretained(service), std::move(origin)));
|
||||
base::Unretained(service),
|
||||
std::move(storage_key.origin())));
|
||||
},
|
||||
base::Unretained(storage_notification_service));
|
||||
|
||||
@ -2043,57 +2045,60 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper::ClearDataOnIOThread(
|
||||
|
||||
if (quota_storage_remove_mask_ & QUOTA_MANAGED_STORAGE_MASK_PERSISTENT) {
|
||||
IncrementTaskCountOnIO();
|
||||
// Ask the QuotaManager for all origins with persistent quota modified
|
||||
// Ask the QuotaManager for all storage keys with persistent quota modified
|
||||
// within the user-specified timeframe, and deal with the resulting set in
|
||||
// ClearQuotaManagedOriginsOnIOThread().
|
||||
quota_manager->GetOriginsModifiedBetween(
|
||||
quota_manager->GetStorageKeysModifiedBetween(
|
||||
blink::mojom::StorageType::kPersistent, begin, end,
|
||||
base::BindOnce(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, origin_matcher,
|
||||
perform_storage_cleanup, decrement_callback));
|
||||
base::BindOnce(
|
||||
&QuotaManagedDataDeletionHelper::ClearStorageKeysOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, origin_matcher, perform_storage_cleanup,
|
||||
decrement_callback));
|
||||
}
|
||||
|
||||
// Do the same for temporary quota.
|
||||
if (quota_storage_remove_mask_ & QUOTA_MANAGED_STORAGE_MASK_TEMPORARY) {
|
||||
IncrementTaskCountOnIO();
|
||||
quota_manager->GetOriginsModifiedBetween(
|
||||
quota_manager->GetStorageKeysModifiedBetween(
|
||||
blink::mojom::StorageType::kTemporary, begin, end,
|
||||
base::BindOnce(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, origin_matcher,
|
||||
perform_storage_cleanup, decrement_callback));
|
||||
base::BindOnce(
|
||||
&QuotaManagedDataDeletionHelper::ClearStorageKeysOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, origin_matcher, perform_storage_cleanup,
|
||||
decrement_callback));
|
||||
}
|
||||
|
||||
// Do the same for syncable quota.
|
||||
if (quota_storage_remove_mask_ & QUOTA_MANAGED_STORAGE_MASK_SYNCABLE) {
|
||||
IncrementTaskCountOnIO();
|
||||
quota_manager->GetOriginsModifiedBetween(
|
||||
quota_manager->GetStorageKeysModifiedBetween(
|
||||
blink::mojom::StorageType::kSyncable, begin, end,
|
||||
base::BindOnce(&QuotaManagedDataDeletionHelper::ClearOriginsOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, std::move(origin_matcher),
|
||||
perform_storage_cleanup, decrement_callback));
|
||||
base::BindOnce(
|
||||
&QuotaManagedDataDeletionHelper::ClearStorageKeysOnIOThread,
|
||||
base::Unretained(this), base::RetainedRef(quota_manager),
|
||||
special_storage_policy, std::move(origin_matcher),
|
||||
perform_storage_cleanup, decrement_callback));
|
||||
}
|
||||
|
||||
DecrementTaskCountOnIO();
|
||||
}
|
||||
|
||||
void StoragePartitionImpl::QuotaManagedDataDeletionHelper::
|
||||
ClearOriginsOnIOThread(
|
||||
ClearStorageKeysOnIOThread(
|
||||
storage::QuotaManager* quota_manager,
|
||||
const scoped_refptr<storage::SpecialStoragePolicy>&
|
||||
special_storage_policy,
|
||||
StoragePartition::OriginMatcherFunction origin_matcher,
|
||||
bool perform_storage_cleanup,
|
||||
base::OnceClosure callback,
|
||||
const std::set<url::Origin>& origins,
|
||||
const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType quota_storage_type) {
|
||||
// The QuotaManager manages all storage other than cookies, LocalStorage,
|
||||
// and SessionStorage. This loop wipes out most HTML5 storage for the given
|
||||
// origins.
|
||||
// storage keys.
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (origins.empty()) {
|
||||
if (storage_keys.empty()) {
|
||||
std::move(callback).Run();
|
||||
return;
|
||||
}
|
||||
@ -2113,13 +2118,13 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper::
|
||||
|
||||
size_t* deletion_task_count = new size_t(0u);
|
||||
(*deletion_task_count)++;
|
||||
for (const auto& origin : origins) {
|
||||
for (const auto& storage_key : storage_keys) {
|
||||
// TODO(mkwst): Clean this up, it's slow. http://crbug.com/130746
|
||||
if (storage_origin_.has_value() && origin != *storage_origin_)
|
||||
if (storage_origin_.has_value() && storage_key.origin() != *storage_origin_)
|
||||
continue;
|
||||
|
||||
if (origin_matcher &&
|
||||
!origin_matcher.Run(origin, special_storage_policy.get())) {
|
||||
if (origin_matcher && !origin_matcher.Run(storage_key.origin(),
|
||||
special_storage_policy.get())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2127,10 +2132,11 @@ void StoragePartitionImpl::QuotaManagedDataDeletionHelper::
|
||||
done_callback = std::move(split_callback.first);
|
||||
|
||||
(*deletion_task_count)++;
|
||||
quota_manager->DeleteOriginData(
|
||||
origin, quota_storage_type, quota_client_types,
|
||||
base::BindOnce(&OnQuotaManagedOriginDeleted, origin, quota_storage_type,
|
||||
deletion_task_count, std::move(split_callback.second)));
|
||||
quota_manager->DeleteStorageKeyData(
|
||||
storage_key, quota_storage_type, quota_client_types,
|
||||
base::BindOnce(&OnQuotaManagedStorageKeyDeleted, storage_key,
|
||||
quota_storage_type, deletion_task_count,
|
||||
std::move(split_callback.second)));
|
||||
}
|
||||
(*deletion_task_count)--;
|
||||
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/features.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
|
||||
#include "third_party/leveldatabase/env_chromium.h"
|
||||
@ -946,54 +947,69 @@ TEST_F(StoragePartitionImplTest, QuotaClientTypesGeneration) {
|
||||
storage::QuotaClientType::kNativeIO));
|
||||
}
|
||||
|
||||
void PopulateTestQuotaManagedPersistentData(storage::MockQuotaManager* manager,
|
||||
const url::Origin& origin1,
|
||||
const url::Origin& origin2) {
|
||||
manager->AddOrigin(origin1, kPersistent, {kClientFile}, base::Time());
|
||||
manager->AddOrigin(origin2, kPersistent, {kClientFile},
|
||||
base::Time::Now() - base::TimeDelta::FromDays(1));
|
||||
void PopulateTestQuotaManagedPersistentData(
|
||||
storage::MockQuotaManager* manager,
|
||||
const blink::StorageKey& storage_key_1,
|
||||
const blink::StorageKey& storage_key_2) {
|
||||
manager->AddStorageKey(storage_key_1, kPersistent, {kClientFile},
|
||||
base::Time());
|
||||
manager->AddStorageKey(storage_key_2, kPersistent, {kClientFile},
|
||||
base::Time::Now() - base::TimeDelta::FromDays(1));
|
||||
|
||||
EXPECT_TRUE(manager->OriginHasData(origin1, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(manager->OriginHasData(origin2, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager->StorageKeyHasData(storage_key_1, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager->StorageKeyHasData(storage_key_2, kPersistent, kClientFile));
|
||||
}
|
||||
|
||||
void PopulateTestQuotaManagedTemporaryData(storage::MockQuotaManager* manager,
|
||||
const url::Origin& origin1,
|
||||
const url::Origin& origin2) {
|
||||
manager->AddOrigin(origin1, kTemporary, {kClientFile}, base::Time::Now());
|
||||
manager->AddOrigin(origin2, kTemporary, {kClientFile},
|
||||
base::Time::Now() - base::TimeDelta::FromDays(1));
|
||||
void PopulateTestQuotaManagedTemporaryData(
|
||||
storage::MockQuotaManager* manager,
|
||||
const blink::StorageKey& storage_key_1,
|
||||
const blink::StorageKey& storage_key_2) {
|
||||
manager->AddStorageKey(storage_key_1, kTemporary, {kClientFile},
|
||||
base::Time::Now());
|
||||
manager->AddStorageKey(storage_key_2, kTemporary, {kClientFile},
|
||||
base::Time::Now() - base::TimeDelta::FromDays(1));
|
||||
|
||||
EXPECT_TRUE(manager->OriginHasData(origin1, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(manager->OriginHasData(origin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager->StorageKeyHasData(storage_key_1, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager->StorageKeyHasData(storage_key_2, kTemporary, kClientFile));
|
||||
}
|
||||
|
||||
void PopulateTestQuotaManagedData(storage::MockQuotaManager* manager,
|
||||
const url::Origin& origin1,
|
||||
const url::Origin& origin2,
|
||||
const url::Origin& origin3) {
|
||||
// Set up origin1 with a temporary quota, origin2 with a persistent quota, and
|
||||
// origin3 with both. origin1 is modified now, origin2 is modified at the
|
||||
// beginning of time, and origin3 is modified one day ago.
|
||||
PopulateTestQuotaManagedTemporaryData(manager, origin1, origin3);
|
||||
PopulateTestQuotaManagedPersistentData(manager, origin2, origin3);
|
||||
EXPECT_FALSE(manager->OriginHasData(origin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager->OriginHasData(origin2, kTemporary, kClientFile));
|
||||
const blink::StorageKey& storage_key_1,
|
||||
const blink::StorageKey& storage_key_2,
|
||||
const blink::StorageKey& storage_key_3) {
|
||||
// Set up storage_key_1 with a temporary quota, storage_key_2 with a
|
||||
// persistent quota, and storage_key_3 with both. storage_key_1 is modified
|
||||
// now, storage_key_2 is modified at the beginning of time, and storage_key_3
|
||||
// is modified one day ago.
|
||||
PopulateTestQuotaManagedTemporaryData(manager, storage_key_1, storage_key_3);
|
||||
PopulateTestQuotaManagedPersistentData(manager, storage_key_2, storage_key_3);
|
||||
EXPECT_FALSE(
|
||||
manager->StorageKeyHasData(storage_key_1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager->StorageKeyHasData(storage_key_2, kTemporary, kClientFile));
|
||||
}
|
||||
|
||||
void PopulateTestQuotaManagedNonBrowsingData(
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
storage::MockQuotaManager* manager) {
|
||||
manager->AddOrigin(origin, kTemporary, {kClientFile}, base::Time());
|
||||
manager->AddOrigin(origin, kPersistent, {kClientFile}, base::Time());
|
||||
manager->AddStorageKey(storage_key, kTemporary, {kClientFile}, base::Time());
|
||||
manager->AddStorageKey(storage_key, kPersistent, {kClientFile}, base::Time());
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1004,25 +1020,28 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) {
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaData, partition, &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
|
||||
PopulateTestQuotaManagedTemporaryData(GetMockManager(), kOrigin1, kOrigin2);
|
||||
PopulateTestQuotaManagedTemporaryData(GetMockManager(), kStorageKey1,
|
||||
kStorageKey2);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1033,21 +1052,24 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaData, partition, &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
|
||||
PopulateTestQuotaManagedPersistentData(GetMockManager(), kOrigin1, kOrigin2);
|
||||
PopulateTestQuotaManagedPersistentData(GetMockManager(), kStorageKey1,
|
||||
kStorageKey2);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1058,20 +1080,23 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaData, partition, &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1082,26 +1107,30 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) {
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaData, partition, &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1109,30 +1138,35 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
|
||||
|
||||
base::RunLoop run_loop;
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaDataForOrigin, partition,
|
||||
kOrigin1.GetURL(), base::Time(), &run_loop));
|
||||
FROM_HERE,
|
||||
base::BindOnce(&ClearQuotaDataForOrigin, partition,
|
||||
kStorageKey1.origin().GetURL(), base::Time(), &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1146,26 +1180,30 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) {
|
||||
&run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
base::RunLoop run_loop;
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
@ -1178,30 +1216,34 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) {
|
||||
&run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
// Protect kOrigin1.
|
||||
// Protect kStorageKey1.
|
||||
auto mock_policy = base::MakeRefCounted<storage::MockSpecialStoragePolicy>();
|
||||
mock_policy->AddProtected(kOrigin1.GetURL());
|
||||
mock_policy->AddProtected(kStorageKey1.origin().GetURL());
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1216,32 +1258,36 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) {
|
||||
base::Time(), &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
const blink::StorageKey kStorageKey1 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const blink::StorageKey kStorageKey2 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const blink::StorageKey kStorageKey3 =
|
||||
blink::StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
// Protect kOrigin1.
|
||||
// Protect kStorageKey1.
|
||||
auto mock_policy = base::MakeRefCounted<storage::MockSpecialStoragePolicy>();
|
||||
mock_policy->AddProtected(kOrigin1.GetURL());
|
||||
mock_policy->AddProtected(kStorageKey1.origin().GetURL());
|
||||
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kOrigin1, kOrigin2, kOrigin3);
|
||||
PopulateTestQuotaManagedData(GetMockManager(), kStorageKey1, kStorageKey2,
|
||||
kStorageKey3);
|
||||
|
||||
// Try to remove kOrigin1. Expect success.
|
||||
// Try to remove kStorageKey1. Expect success.
|
||||
base::RunLoop run_loop;
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
@ -1255,42 +1301,43 @@ TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) {
|
||||
base::Time(), &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
GetMockManager()->OriginHasData(kOrigin3, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey1, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey2, kPersistent,
|
||||
kClientFile));
|
||||
EXPECT_FALSE(GetMockManager()->StorageKeyHasData(kStorageKey3, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) {
|
||||
const url::Origin kOrigin =
|
||||
url::Origin::Create(GURL("devtools://abcdefghijklmnopqrstuvw/"));
|
||||
const blink::StorageKey kStorageKey =
|
||||
blink::StorageKey::CreateFromStringForTesting(
|
||||
"devtools://abcdefghijklmnopqrstuvw/");
|
||||
|
||||
PopulateTestQuotaManagedNonBrowsingData(kOrigin, GetMockManager());
|
||||
PopulateTestQuotaManagedNonBrowsingData(kStorageKey, GetMockManager());
|
||||
|
||||
base::RunLoop run_loop;
|
||||
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
|
||||
browser_context()->GetDefaultStoragePartition());
|
||||
partition->OverrideQuotaManagerForTesting(GetMockManager());
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&ClearQuotaDataWithOriginMatcher, partition,
|
||||
base::BindRepeating(&DoesOriginMatchUnprotected, kOrigin),
|
||||
base::Time(), &run_loop));
|
||||
FROM_HERE, base::BindOnce(&ClearQuotaDataWithOriginMatcher, partition,
|
||||
base::BindRepeating(&DoesOriginMatchUnprotected,
|
||||
kStorageKey.origin()),
|
||||
base::Time(), &run_loop));
|
||||
run_loop.Run();
|
||||
|
||||
// Check that devtools data isn't removed.
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
GetMockManager()->OriginHasData(kOrigin, kPersistent, kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey, kTemporary,
|
||||
kClientFile));
|
||||
EXPECT_TRUE(GetMockManager()->StorageKeyHasData(kStorageKey, kPersistent,
|
||||
kClientFile));
|
||||
}
|
||||
|
||||
TEST_F(StoragePartitionImplTest, RemoveCookieForever) {
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "storage/common/file_system/file_system_mount_option.h"
|
||||
#include "storage/common/file_system/file_system_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace storage {
|
||||
@ -223,10 +224,12 @@ class CopyOrMoveOperationTestHelper {
|
||||
task_environment_.RunUntilIdle();
|
||||
|
||||
// Grant relatively big quota initially.
|
||||
quota_manager_->SetQuota(
|
||||
origin_, FileSystemTypeToQuotaStorageType(src_type_), 1024 * 1024);
|
||||
quota_manager_->SetQuota(
|
||||
origin_, FileSystemTypeToQuotaStorageType(dest_type_), 1024 * 1024);
|
||||
quota_manager_->SetQuota(blink::StorageKey(origin_),
|
||||
FileSystemTypeToQuotaStorageType(src_type_),
|
||||
1024 * 1024);
|
||||
quota_manager_->SetQuota(blink::StorageKey(origin_),
|
||||
FileSystemTypeToQuotaStorageType(dest_type_),
|
||||
1024 * 1024);
|
||||
}
|
||||
|
||||
int64_t GetSourceUsage() {
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "storage/browser/test/sandbox_file_system_test_helper.h"
|
||||
#include "storage/common/file_system/file_system_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "url/gurl.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -257,7 +257,7 @@ class FileSystemOperationImplTest : public testing::Test {
|
||||
void GrantQuotaForCurrentUsage() {
|
||||
int64_t usage;
|
||||
GetUsageAndQuota(&usage, nullptr);
|
||||
quota_manager()->SetQuota(sandbox_file_system_.origin(),
|
||||
quota_manager()->SetQuota(blink::StorageKey(sandbox_file_system_.origin()),
|
||||
sandbox_file_system_.storage_type(), usage);
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ class FileSystemOperationImplTest : public testing::Test {
|
||||
void AddQuota(int64_t quota_delta) {
|
||||
int64_t quota;
|
||||
GetUsageAndQuota(nullptr, "a);
|
||||
quota_manager()->SetQuota(sandbox_file_system_.origin(),
|
||||
quota_manager()->SetQuota(blink::StorageKey(sandbox_file_system_.origin()),
|
||||
sandbox_file_system_.storage_type(),
|
||||
quota + quota_delta);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "storage/browser/test/test_file_system_context.h"
|
||||
#include "storage/common/file_system/file_system_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
@ -249,9 +250,9 @@ TEST_F(FileSystemOperationImplWriteTest, TestWriteDir) {
|
||||
TEST_F(FileSystemOperationImplWriteTest, TestWriteFailureByQuota) {
|
||||
ScopedTextBlob blob(blob_storage_context(), "blob:success",
|
||||
"Hello, world!\n");
|
||||
quota_manager_->SetQuota(url::Origin::Create(GURL(kOrigin)),
|
||||
FileSystemTypeToQuotaStorageType(kFileSystemType),
|
||||
10);
|
||||
quota_manager_->SetQuota(
|
||||
blink::StorageKey::CreateFromStringForTesting(kOrigin),
|
||||
FileSystemTypeToQuotaStorageType(kFileSystemType), 10);
|
||||
file_system_context_->operation_runner()->Write(URLForPath(virtual_path_),
|
||||
blob.GetBlobDataHandle(), 0,
|
||||
RecordWriteCallback());
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "storage/browser/test/mock_special_storage_policy.h"
|
||||
#include "storage/browser/test/test_file_system_context.h"
|
||||
#include "storage/common/file_system/file_system_types.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -149,7 +150,7 @@ class SandboxFileStreamWriterTest : public FileStreamWriterTest {
|
||||
quota_usage_and_info GetUsageAndQuotaSync() {
|
||||
quota_usage_and_info info;
|
||||
quota_manager_->GetUsageAndQuota(
|
||||
url::Origin::Create(GURL(kURLOrigin)),
|
||||
blink::StorageKey::CreateFromStringForTesting(kURLOrigin),
|
||||
blink::mojom::StorageType::kTemporary,
|
||||
base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode status,
|
||||
int64_t usage, int64_t quota) {
|
||||
@ -161,8 +162,9 @@ class SandboxFileStreamWriterTest : public FileStreamWriterTest {
|
||||
}
|
||||
|
||||
void SetQuota(int64_t quota) {
|
||||
quota_manager_->SetQuota(url::Origin::Create(GURL(kURLOrigin)),
|
||||
blink::mojom::StorageType::kTemporary, quota);
|
||||
quota_manager_->SetQuota(
|
||||
blink::StorageKey::CreateFromStringForTesting(kURLOrigin),
|
||||
blink::mojom::StorageType::kTemporary, quota);
|
||||
}
|
||||
|
||||
int64_t GetFreeQuota() {
|
||||
|
@ -18,8 +18,8 @@
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h"
|
||||
|
||||
namespace url {
|
||||
class Origin;
|
||||
namespace blink {
|
||||
class StorageKey;
|
||||
}
|
||||
|
||||
namespace storage {
|
||||
@ -41,12 +41,12 @@ using UsageWithBreakdownCallback =
|
||||
using AvailableSpaceCallback =
|
||||
base::OnceCallback<void(blink::mojom::QuotaStatusCode, int64_t)>;
|
||||
using StatusCallback = base::OnceCallback<void(blink::mojom::QuotaStatusCode)>;
|
||||
using GetOriginsCallback =
|
||||
base::OnceCallback<void(const std::set<url::Origin>& origins,
|
||||
using GetStorageKeysCallback =
|
||||
base::OnceCallback<void(const std::set<blink::StorageKey>& storage_keys,
|
||||
blink::mojom::StorageType type)>;
|
||||
using GetUsageInfoCallback = base::OnceCallback<void(UsageInfoEntries)>;
|
||||
using GetOriginCallback =
|
||||
base::OnceCallback<void(const absl::optional<url::Origin>&)>;
|
||||
using GetStorageKeyCallback = base::OnceCallback<void(
|
||||
const absl::optional<blink::StorageKey>& storage_key)>;
|
||||
|
||||
// Simple template wrapper for a callback queue.
|
||||
template <typename CallbackType, typename... Args>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -39,9 +39,9 @@
|
||||
#include "storage/browser/quota/quota_task.h"
|
||||
#include "storage/browser/quota/special_storage_policy.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace base {
|
||||
class SequencedTaskRunner;
|
||||
@ -77,15 +77,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaEvictionHandler {
|
||||
// the current settings, capacity, and usage.
|
||||
virtual void GetEvictionRoundInfo(EvictionRoundInfoCallback callback) = 0;
|
||||
|
||||
// Returns next origin to evict, or nullopt if there are no evictable origins.
|
||||
virtual void GetEvictionOrigin(blink::mojom::StorageType type,
|
||||
int64_t global_quota,
|
||||
GetOriginCallback callback) = 0;
|
||||
// Returns the next storage key to evict, or nullopt if there are no evictable
|
||||
// storage keys.
|
||||
virtual void GetEvictionStorageKey(blink::mojom::StorageType type,
|
||||
int64_t global_quota,
|
||||
GetStorageKeyCallback callback) = 0;
|
||||
|
||||
// Called to evict an origin.
|
||||
virtual void EvictOriginData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
StatusCallback callback) = 0;
|
||||
// Called to evict a storage key.
|
||||
virtual void EvictStorageKeyData(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
StatusCallback callback) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~QuotaEvictionHandler() = default;
|
||||
@ -159,17 +160,17 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
// Returns a proxy object that can be used on any thread.
|
||||
QuotaManagerProxy* proxy() { return proxy_.get(); }
|
||||
|
||||
// Creates a bucket for `origin` with `bucket_name` and returns BucketInfo
|
||||
// to the callback. Will return a QuotaError to the callback on operation
|
||||
// failure.
|
||||
void CreateBucket(const url::Origin& origin,
|
||||
// Creates a bucket for `storage_key` with `bucket_name` and returns the
|
||||
// BucketInfo to the callback. Will return a QuotaError to the callback on
|
||||
// operation failure.
|
||||
void CreateBucket(const blink::StorageKey& storage_key,
|
||||
const std::string& bucket_name,
|
||||
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)>);
|
||||
|
||||
// Retrieves the BucketInfo of the bucket with `bucket_name` for `origin` and
|
||||
// returns it to the callback. Will return a QuotaError if the bucket does
|
||||
// Retrieves the BucketInfo of the bucket with `bucket_name` for `storage_key`
|
||||
// and returns it to the callback. Will return a QuotaError if the bucket does
|
||||
// not exist or on operation failure.
|
||||
void GetBucket(const url::Origin& origin,
|
||||
void GetBucket(const blink::StorageKey& storage_key,
|
||||
const std::string& bucket_name,
|
||||
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)>);
|
||||
|
||||
@ -178,31 +179,31 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
// Called by Web Apps (deprecated quota API).
|
||||
// This method is declared as virtual to allow test code to override it.
|
||||
virtual void GetUsageAndQuotaForWebApps(const url::Origin& origin,
|
||||
virtual void GetUsageAndQuotaForWebApps(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
UsageAndQuotaCallback callback);
|
||||
|
||||
// Called by Web Apps (navigator.storage.estimate())
|
||||
// This method is declared as virtual to allow test code to override it.
|
||||
virtual void GetUsageAndQuotaWithBreakdown(
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
UsageAndQuotaWithBreakdownCallback callback);
|
||||
|
||||
// Called by DevTools.
|
||||
virtual void GetUsageAndQuotaForDevtools(
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
UsageAndQuotaForDevtoolsCallback callback);
|
||||
|
||||
// Called by storage backends.
|
||||
//
|
||||
// For UnlimitedStorage origins, this version skips usage and quota handling
|
||||
// to avoid extra query cost. Do not call this method for apps/user-facing
|
||||
// code.
|
||||
// For UnlimitedStorage storage keys, this version skips usage and quota
|
||||
// handling to avoid extra query cost. Do not call this method for
|
||||
// apps/user-facing code.
|
||||
//
|
||||
// This method is declared as virtual to allow test code to override it.
|
||||
virtual void GetUsageAndQuota(const url::Origin& origin,
|
||||
virtual void GetUsageAndQuota(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
UsageAndQuotaCallback callback);
|
||||
|
||||
@ -210,7 +211,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
//
|
||||
// Quota-managed storage backends should call this method when storage is
|
||||
// accessed. Used to maintain LRU ordering.
|
||||
void NotifyStorageAccessed(const url::Origin& origin,
|
||||
void NotifyStorageAccessed(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
base::Time access_time);
|
||||
|
||||
@ -219,7 +220,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
// Quota-managed storage backends must call this method when they have made
|
||||
// any modifications that change the amount of data stored in their storage.
|
||||
void NotifyStorageModified(QuotaClientType client_id,
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
int64_t delta,
|
||||
base::Time modification_time,
|
||||
@ -232,33 +233,33 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
// of space, and trigger actions if deemed appropriate.
|
||||
//
|
||||
// This method is declared as virtual to allow test code to override it.
|
||||
virtual void NotifyWriteFailed(const url::Origin& origin);
|
||||
virtual void NotifyWriteFailed(const blink::StorageKey& storage_key);
|
||||
|
||||
// Used to avoid evicting origins with open pages.
|
||||
// A call to NotifyOriginInUse must be balanced by a later call
|
||||
// to NotifyOriginNoLongerInUse.
|
||||
void NotifyOriginInUse(const url::Origin& origin);
|
||||
void NotifyOriginNoLongerInUse(const url::Origin& origin);
|
||||
bool IsOriginInUse(const url::Origin& origin) const {
|
||||
// Used to avoid evicting storage keys with open pages.
|
||||
// A call to NotifyStorageKeyInUse must be balanced by a later call
|
||||
// to NotifyStorageKeyNoLongerInUse.
|
||||
void NotifyStorageKeyInUse(const blink::StorageKey& storage_key);
|
||||
void NotifyStorageKeyNoLongerInUse(const blink::StorageKey& storage_key);
|
||||
bool IsStorageKeyInUse(const blink::StorageKey& storage_key) const {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
return base::Contains(origins_in_use_, origin);
|
||||
return base::Contains(storage_keys_in_use_, storage_key);
|
||||
}
|
||||
|
||||
void SetUsageCacheEnabled(QuotaClientType client_id,
|
||||
const url::Origin& origin,
|
||||
const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
bool enabled);
|
||||
|
||||
// DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a
|
||||
// particular blink::mojom::StorageType associated with either a specific
|
||||
// origin or set of origins. Each method additionally requires a
|
||||
// DeleteStorageKeyData and DeleteHostData (surprisingly enough) delete data
|
||||
// of a particular blink::mojom::StorageType associated with either a specific
|
||||
// storage key or set of storage keys. Each method additionally requires a
|
||||
// |quota_client_types| which specifies the types of QuotaClients to delete
|
||||
// from the origin. Pass in QuotaClientType::AllClients() to remove all
|
||||
// clients from the origin, regardless of type.
|
||||
virtual void DeleteOriginData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback);
|
||||
// from the storage key. Pass in QuotaClientType::AllClients() to remove all
|
||||
// clients from the storage key, regardless of type.
|
||||
virtual void DeleteStorageKeyData(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback);
|
||||
void DeleteHostData(const std::string& host,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
@ -283,29 +284,30 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
std::map<std::string, std::string> GetStatistics();
|
||||
|
||||
bool IsStorageUnlimited(const url::Origin& origin,
|
||||
bool IsStorageUnlimited(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type) const;
|
||||
|
||||
virtual void GetOriginsModifiedBetween(blink::mojom::StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetOriginsCallback callback);
|
||||
virtual void GetStorageKeysModifiedBetween(blink::mojom::StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetStorageKeysCallback callback);
|
||||
|
||||
bool ResetUsageTracker(blink::mojom::StorageType type);
|
||||
|
||||
// Called when StoragePartition is initialized if embedder has an
|
||||
// implementation of StorageNotificationService.
|
||||
void SetStoragePressureCallback(
|
||||
base::RepeatingCallback<void(url::Origin)> storage_pressure_callback);
|
||||
base::RepeatingCallback<void(blink::StorageKey)>
|
||||
storage_pressure_callback);
|
||||
|
||||
// DevTools Quota Override methods:
|
||||
int GetOverrideHandleId();
|
||||
void OverrideQuotaForOrigin(int handle_id,
|
||||
const url::Origin& origin,
|
||||
absl::optional<int64_t> quota_size);
|
||||
void OverrideQuotaForStorageKey(int handle_id,
|
||||
const blink::StorageKey& storage_key,
|
||||
absl::optional<int64_t> quota_size);
|
||||
// Called when a DevTools client releases all overrides, however, overrides
|
||||
// will not be disabled for any origins for which there are other DevTools
|
||||
// clients/QuotaOverrideHandle with an active override.
|
||||
// will not be disabled for any storage keys for which there are other
|
||||
// DevTools clients/QuotaOverrideHandle with an active override.
|
||||
void WithdrawOverridesForHandle(int handle_id);
|
||||
|
||||
// Cap size for per-host persistent quota determined by the histogram.
|
||||
@ -321,6 +323,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
static constexpr int kThresholdRandomizationPercent = 5;
|
||||
|
||||
static constexpr char kDatabaseName[] = "QuotaManager";
|
||||
|
||||
// TODO(crbug.com/1215208): Change counters to have StorageKey in their names.
|
||||
static constexpr char kEvictedOriginAccessedCountHistogram[] =
|
||||
"Quota.EvictedOriginAccessCount";
|
||||
static constexpr char kEvictedOriginDaysSinceAccessHistogram[] =
|
||||
@ -355,7 +359,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
class EvictionRoundInfoHelper;
|
||||
class UsageAndQuotaInfoGatherer;
|
||||
class GetUsageInfoTask;
|
||||
class OriginDataDeleter;
|
||||
class StorageKeyDataDeleter;
|
||||
class HostDataDeleter;
|
||||
class GetModifiedSinceHelper;
|
||||
class DumpQuotaTableHelper;
|
||||
@ -393,9 +397,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
struct EvictionContext {
|
||||
EvictionContext();
|
||||
~EvictionContext();
|
||||
url::Origin evicted_origin;
|
||||
blink::mojom::StorageType evicted_type;
|
||||
StatusCallback evict_origin_data_callback;
|
||||
blink::StorageKey evicted_storage_key;
|
||||
blink::mojom::StorageType evicted_type =
|
||||
blink::mojom::StorageType::kUnknown;
|
||||
StatusCallback evict_storage_key_data_callback;
|
||||
};
|
||||
|
||||
// Lazily called on the IO thread when the first quota manager API is called.
|
||||
@ -404,10 +409,11 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
// manager by RegisterClient().
|
||||
void LazyInitialize();
|
||||
void FinishLazyInitialize(bool is_database_bootstraped);
|
||||
void BootstrapDatabaseForEviction(GetOriginCallback did_get_origin_callback,
|
||||
int64_t unused_usage,
|
||||
int64_t unused_unlimited_usage);
|
||||
void DidBootstrapDatabase(GetOriginCallback did_get_origin_callback,
|
||||
void BootstrapDatabaseForEviction(
|
||||
GetStorageKeyCallback did_get_storage_key_callback,
|
||||
int64_t unused_usage,
|
||||
int64_t unused_unlimited_usage);
|
||||
void DidBootstrapDatabase(GetStorageKeyCallback did_get_storage_key_callback,
|
||||
bool success);
|
||||
|
||||
// Called by clients via proxy.
|
||||
@ -419,26 +425,27 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
UsageTracker* GetUsageTracker(blink::mojom::StorageType type) const;
|
||||
|
||||
// Extract cached origins list from the usage tracker.
|
||||
// (Might return empty list if no origin is tracked by the tracker.)
|
||||
std::set<url::Origin> GetCachedOrigins(blink::mojom::StorageType type);
|
||||
// Extract cached storage keys list from the usage tracker.
|
||||
// (Might return empty list if no storage key is tracked by the tracker.)
|
||||
std::set<blink::StorageKey> GetCachedStorageKeys(
|
||||
blink::mojom::StorageType type);
|
||||
|
||||
void DumpQuotaTable(DumpQuotaTableCallback callback);
|
||||
void DumpBucketTable(DumpBucketTableCallback callback);
|
||||
|
||||
void DeleteOriginDataInternal(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
bool is_eviction,
|
||||
StatusCallback callback);
|
||||
void DeleteStorageKeyDataInternal(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
bool is_eviction,
|
||||
StatusCallback callback);
|
||||
|
||||
// Methods for eviction logic.
|
||||
void StartEviction();
|
||||
void DeleteOriginFromDatabase(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
bool is_eviction);
|
||||
void DeleteStorageKeyFromDatabase(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
bool is_eviction);
|
||||
|
||||
void DidOriginDataEvicted(blink::mojom::QuotaStatusCode status);
|
||||
void DidStorageKeyDataEvicted(blink::mojom::QuotaStatusCode status);
|
||||
|
||||
void ReportHistogram();
|
||||
void DidGetTemporaryGlobalUsageForHistogram(int64_t usage,
|
||||
@ -450,20 +457,22 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
int64_t unlimited_usage);
|
||||
void DidDumpBucketTableForHistogram(const BucketTableEntries& entries);
|
||||
|
||||
std::set<url::Origin> GetEvictionOriginExceptions();
|
||||
void DidGetEvictionOrigin(GetOriginCallback callback,
|
||||
const absl::optional<url::Origin>& origin);
|
||||
std::set<blink::StorageKey> GetEvictionStorageKeyExceptions();
|
||||
void DidGetEvictionStorageKey(
|
||||
GetStorageKeyCallback callback,
|
||||
const absl::optional<blink::StorageKey>& storage_key);
|
||||
|
||||
// QuotaEvictionHandler.
|
||||
void GetEvictionOrigin(blink::mojom::StorageType type,
|
||||
int64_t global_quota,
|
||||
GetOriginCallback callback) override;
|
||||
void EvictOriginData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
StatusCallback callback) override;
|
||||
void GetEvictionStorageKey(blink::mojom::StorageType type,
|
||||
int64_t global_quota,
|
||||
GetStorageKeyCallback callback) override;
|
||||
void EvictStorageKeyData(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
StatusCallback callback) override;
|
||||
void GetEvictionRoundInfo(EvictionRoundInfoCallback callback) override;
|
||||
|
||||
void GetLRUOrigin(blink::mojom::StorageType type, GetOriginCallback callback);
|
||||
void GetLRUStorageKey(blink::mojom::StorageType type,
|
||||
GetStorageKeyCallback callback);
|
||||
|
||||
void DidGetPersistentHostQuota(const std::string& host,
|
||||
const int64_t* quota,
|
||||
@ -472,8 +481,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
QuotaCallback callback,
|
||||
const int64_t* new_quota,
|
||||
bool success);
|
||||
void DidGetLRUOrigin(std::unique_ptr<absl::optional<url::Origin>> origin,
|
||||
bool success);
|
||||
void DidGetLRUStorageKey(
|
||||
std::unique_ptr<absl::optional<blink::StorageKey>> storage_key,
|
||||
bool success);
|
||||
void GetQuotaSettings(QuotaSettingsCallback callback);
|
||||
void DidGetSettings(absl::optional<QuotaSettings> settings);
|
||||
void GetStorageCapacity(StorageCapacityCallback callback);
|
||||
@ -488,12 +498,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
void DeleteOnCorrectThread() const;
|
||||
|
||||
void MaybeRunStoragePressureCallback(const url::Origin& origin,
|
||||
void MaybeRunStoragePressureCallback(const blink::StorageKey& storage_key,
|
||||
int64_t total_space,
|
||||
int64_t available_space);
|
||||
// Used from quota-internals page to test behavior of the storage pressure
|
||||
// callback.
|
||||
void SimulateStoragePressure(const url::Origin origin);
|
||||
void SimulateStoragePressure(const blink::StorageKey& storage_key);
|
||||
|
||||
// Evaluates disk statistics to identify storage pressure
|
||||
// (low disk space availability) and starts the storage
|
||||
@ -503,7 +513,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
// TODO(crbug.com/1102433): Define and explain StoragePressure in the README.
|
||||
void DetermineStoragePressure(int64_t free_space, int64_t total_space);
|
||||
|
||||
absl::optional<int64_t> GetQuotaOverrideForOrigin(const url::Origin&);
|
||||
absl::optional<int64_t> GetQuotaOverrideForStorageKey(
|
||||
const blink::StorageKey&);
|
||||
|
||||
// TODO(ayui): Replace instances to use result with QuotaErrorOr.
|
||||
void PostTaskAndReplyWithResultForDBThread(
|
||||
@ -531,7 +542,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
bool db_disabled_;
|
||||
bool eviction_disabled_;
|
||||
absl::optional<url::Origin> origin_for_pending_storage_pressure_callback_;
|
||||
absl::optional<blink::StorageKey>
|
||||
storage_key_for_pending_storage_pressure_callback_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> io_thread_;
|
||||
scoped_refptr<base::SequencedTaskRunner> db_runner_;
|
||||
mutable std::unique_ptr<QuotaDatabase> database_;
|
||||
@ -539,7 +551,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
GetQuotaSettingsFunc get_settings_function_;
|
||||
scoped_refptr<base::TaskRunner> get_settings_task_runner_;
|
||||
base::RepeatingCallback<void(url::Origin)> storage_pressure_callback_;
|
||||
base::RepeatingCallback<void(blink::StorageKey)> storage_pressure_callback_;
|
||||
base::RepeatingClosure quota_change_callback_;
|
||||
QuotaSettings settings_;
|
||||
base::TimeTicks settings_timestamp_;
|
||||
@ -550,10 +562,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
CallbackQueue<StorageCapacityCallback, int64_t, int64_t>
|
||||
storage_capacity_callbacks_;
|
||||
|
||||
GetOriginCallback lru_origin_callback_;
|
||||
std::set<url::Origin> access_notified_origins_;
|
||||
GetStorageKeyCallback lru_storage_key_callback_;
|
||||
std::set<blink::StorageKey> access_notified_storage_keys_;
|
||||
|
||||
std::map<url::Origin, QuotaOverride> devtools_overrides_;
|
||||
std::map<blink::StorageKey, QuotaOverride> devtools_overrides_;
|
||||
int next_override_handle_id_ = 0;
|
||||
|
||||
// Owns the QuotaClient remotes registered via RegisterClient().
|
||||
@ -581,7 +593,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
|
||||
std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_;
|
||||
EvictionContext eviction_context_;
|
||||
bool is_getting_eviction_origin_;
|
||||
bool is_getting_eviction_storage_key_;
|
||||
|
||||
CallbackQueueMap<QuotaCallback,
|
||||
std::string,
|
||||
@ -589,10 +601,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl
|
||||
int64_t>
|
||||
persistent_host_quota_callbacks_;
|
||||
|
||||
// Map from origin to count.
|
||||
std::map<url::Origin, int> origins_in_use_;
|
||||
// Map from origin to error count.
|
||||
std::map<url::Origin, int> origins_in_error_;
|
||||
// Map from storage key to count.
|
||||
std::map<blink::StorageKey, int> storage_keys_in_use_;
|
||||
// Map from storage key to error count.
|
||||
std::map<blink::StorageKey, int> storage_keys_in_error_;
|
||||
|
||||
scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
|
||||
|
||||
|
@ -23,9 +23,12 @@
|
||||
#include "storage/browser/quota/quota_client_type.h"
|
||||
#include "storage/browser/quota/quota_manager_impl.h"
|
||||
#include "storage/browser/quota/quota_override_handle.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
using ::blink::StorageKey;
|
||||
|
||||
namespace storage {
|
||||
|
||||
namespace {
|
||||
@ -95,7 +98,7 @@ void QuotaManagerProxy::CreateBucket(
|
||||
}
|
||||
|
||||
quota_manager_impl_->CreateBucket(
|
||||
origin, bucket_name,
|
||||
StorageKey(origin), bucket_name,
|
||||
base::BindOnce(&DidGetBucket, std::move(callback_task_runner),
|
||||
std::move(callback)));
|
||||
}
|
||||
@ -121,7 +124,7 @@ void QuotaManagerProxy::GetBucket(
|
||||
}
|
||||
|
||||
quota_manager_impl_->GetBucket(
|
||||
origin, bucket_name,
|
||||
StorageKey(origin), bucket_name,
|
||||
base::BindOnce(&DidGetBucket, std::move(callback_task_runner),
|
||||
std::move(callback)));
|
||||
}
|
||||
@ -138,7 +141,8 @@ void QuotaManagerProxy::NotifyStorageAccessed(const url::Origin& origin,
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->NotifyStorageAccessed(origin, type, access_time);
|
||||
quota_manager_impl_->NotifyStorageAccessed(StorageKey(origin), type,
|
||||
access_time);
|
||||
}
|
||||
|
||||
void QuotaManagerProxy::NotifyStorageModified(
|
||||
@ -174,8 +178,8 @@ void QuotaManagerProxy::NotifyStorageModified(
|
||||
},
|
||||
std::move(callback_task_runner), std::move(callback));
|
||||
}
|
||||
quota_manager_impl_->NotifyStorageModified(client_id, origin, type, delta,
|
||||
modification_time,
|
||||
quota_manager_impl_->NotifyStorageModified(client_id, StorageKey(origin),
|
||||
type, delta, modification_time,
|
||||
std::move(manager_callback));
|
||||
}
|
||||
}
|
||||
@ -190,7 +194,7 @@ void QuotaManagerProxy::NotifyOriginInUse(const url::Origin& origin) {
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->NotifyOriginInUse(origin);
|
||||
quota_manager_impl_->NotifyStorageKeyInUse(StorageKey(origin));
|
||||
}
|
||||
|
||||
void QuotaManagerProxy::NotifyOriginNoLongerInUse(const url::Origin& origin) {
|
||||
@ -203,7 +207,7 @@ void QuotaManagerProxy::NotifyOriginNoLongerInUse(const url::Origin& origin) {
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->NotifyOriginNoLongerInUse(origin);
|
||||
quota_manager_impl_->NotifyStorageKeyNoLongerInUse(StorageKey(origin));
|
||||
}
|
||||
|
||||
void QuotaManagerProxy::NotifyWriteFailed(const url::Origin& origin) {
|
||||
@ -216,7 +220,7 @@ void QuotaManagerProxy::NotifyWriteFailed(const url::Origin& origin) {
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->NotifyWriteFailed(origin);
|
||||
quota_manager_impl_->NotifyWriteFailed(StorageKey(origin));
|
||||
}
|
||||
|
||||
void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClientType client_id,
|
||||
@ -232,7 +236,8 @@ void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClientType client_id,
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->SetUsageCacheEnabled(client_id, origin, type, enabled);
|
||||
quota_manager_impl_->SetUsageCacheEnabled(client_id, StorageKey(origin),
|
||||
type, enabled);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@ -274,7 +279,7 @@ void QuotaManagerProxy::GetUsageAndQuota(
|
||||
}
|
||||
|
||||
quota_manager_impl_->GetUsageAndQuota(
|
||||
origin, type,
|
||||
StorageKey(origin), type,
|
||||
base::BindOnce(&DidGetUsageAndQuota, std::move(callback_task_runner),
|
||||
std::move(callback)));
|
||||
}
|
||||
@ -295,7 +300,7 @@ void QuotaManagerProxy::IsStorageUnlimited(
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
bool is_storage_unlimited =
|
||||
quota_manager_impl_
|
||||
? quota_manager_impl_->IsStorageUnlimited(origin, type)
|
||||
? quota_manager_impl_->IsStorageUnlimited(StorageKey(origin), type)
|
||||
: false;
|
||||
|
||||
if (callback_task_runner->RunsTasksInCurrentSequence()) {
|
||||
@ -328,7 +333,8 @@ void QuotaManagerProxy::OverrideQuotaForOrigin(
|
||||
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(quota_manager_impl_sequence_checker_);
|
||||
if (quota_manager_impl_)
|
||||
quota_manager_impl_->OverrideQuotaForOrigin(handle_id, origin, quota_size);
|
||||
quota_manager_impl_->OverrideQuotaForStorageKey(
|
||||
handle_id, StorageKey(origin), quota_size);
|
||||
|
||||
if (callback_task_runner->RunsTasksInCurrentSequence()) {
|
||||
std::move(callback).Run();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,7 @@
|
||||
#include "base/bind.h"
|
||||
#include "storage/browser/quota/quota_macros.h"
|
||||
#include "storage/browser/quota/quota_manager_impl.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
@ -31,15 +32,6 @@ constexpr double kDiskSpaceShortageAllowanceRatio = 0.5;
|
||||
|
||||
namespace storage {
|
||||
|
||||
QuotaTemporaryStorageEvictor::EvictionRoundStatistics::EvictionRoundStatistics()
|
||||
: in_round(false),
|
||||
is_initialized(false),
|
||||
diskspace_shortage_at_round(-1),
|
||||
usage_on_beginning_of_round(-1),
|
||||
usage_on_end_of_round(-1),
|
||||
num_evicted_origins_in_round(0) {
|
||||
}
|
||||
|
||||
QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
|
||||
QuotaEvictionHandler* quota_eviction_handler,
|
||||
int64_t interval_ms)
|
||||
@ -60,8 +52,7 @@ void QuotaTemporaryStorageEvictor::GetStatistics(
|
||||
|
||||
(*statistics)["errors-on-getting-usage-and-quota"] =
|
||||
statistics_.num_errors_on_getting_usage_and_quota;
|
||||
(*statistics)["evicted-origins"] =
|
||||
statistics_.num_evicted_origins;
|
||||
(*statistics)["evicted-storage-keys"] = statistics_.num_evicted_storage_keys;
|
||||
(*statistics)["eviction-rounds"] =
|
||||
statistics_.num_eviction_rounds;
|
||||
(*statistics)["skipped-eviction-rounds"] =
|
||||
@ -87,8 +78,9 @@ void QuotaTemporaryStorageEvictor::ReportPerRoundHistogram() {
|
||||
UMA_HISTOGRAM_MBYTES("Quota.EvictedBytesPerRound",
|
||||
round_statistics_.usage_on_beginning_of_round -
|
||||
round_statistics_.usage_on_end_of_round);
|
||||
// TODO(crbug.com/1215208): Change to NumberOfEvictedStorageKeysPerRound.
|
||||
UMA_HISTOGRAM_COUNTS_1M("Quota.NumberOfEvictedOriginsPerRound",
|
||||
round_statistics_.num_evicted_origins_in_round);
|
||||
round_statistics_.num_evicted_storage_keys_in_round);
|
||||
}
|
||||
|
||||
void QuotaTemporaryStorageEvictor::ReportPerHourHistogram() {
|
||||
@ -97,8 +89,11 @@ void QuotaTemporaryStorageEvictor::ReportPerHourHistogram() {
|
||||
stats_in_hour.subtract_assign(previous_statistics_);
|
||||
previous_statistics_ = statistics_;
|
||||
|
||||
// Even though the metric now captures the number of evicted storage keys
|
||||
// (instead of origins), we keep the metric identifier
|
||||
// Quota.EvictedOriginsPerHour so we don't lose historical data.
|
||||
UMA_HISTOGRAM_COUNTS_1M("Quota.EvictedOriginsPerHour",
|
||||
stats_in_hour.num_evicted_origins);
|
||||
stats_in_hour.num_evicted_storage_keys);
|
||||
UMA_HISTOGRAM_COUNTS_1M("Quota.EvictionRoundsPerHour",
|
||||
stats_in_hour.num_eviction_rounds);
|
||||
UMA_HISTOGRAM_COUNTS_1M("Quota.SkippedEvictionRoundsPerHour",
|
||||
@ -118,7 +113,7 @@ void QuotaTemporaryStorageEvictor::OnEvictionRoundFinished() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
// Check if skipped round
|
||||
if (round_statistics_.num_evicted_origins_in_round) {
|
||||
if (round_statistics_.num_evicted_storage_keys_in_round) {
|
||||
ReportPerRoundHistogram();
|
||||
time_of_end_of_last_nonskipped_round_ = base::Time::Now();
|
||||
} else {
|
||||
@ -200,12 +195,13 @@ void QuotaTemporaryStorageEvictor::OnGotEvictionRoundInfo(
|
||||
|
||||
int64_t amount_to_evict = std::max(usage_overage, diskspace_shortage);
|
||||
if (status == blink::mojom::QuotaStatusCode::kOk && amount_to_evict > 0) {
|
||||
// Space is getting tight. Get the least recently used origin and continue.
|
||||
// Space is getting tight. Get the least recently used storage key and
|
||||
// continue.
|
||||
// TODO(michaeln): if the reason for eviction is low physical disk space,
|
||||
// make 'unlimited' origins subject to eviction too.
|
||||
quota_eviction_handler_->GetEvictionOrigin(
|
||||
// make 'unlimited' storage keys subject to eviction too.
|
||||
quota_eviction_handler_->GetEvictionStorageKey(
|
||||
blink::mojom::StorageType::kTemporary, settings.pool_size,
|
||||
base::BindOnce(&QuotaTemporaryStorageEvictor::OnGotEvictionOrigin,
|
||||
base::BindOnce(&QuotaTemporaryStorageEvictor::OnGotEvictionStorageKey,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
return;
|
||||
}
|
||||
@ -223,20 +219,20 @@ void QuotaTemporaryStorageEvictor::OnGotEvictionRoundInfo(
|
||||
OnEvictionRoundFinished();
|
||||
}
|
||||
|
||||
void QuotaTemporaryStorageEvictor::OnGotEvictionOrigin(
|
||||
const absl::optional<url::Origin>& origin) {
|
||||
void QuotaTemporaryStorageEvictor::OnGotEvictionStorageKey(
|
||||
const absl::optional<blink::StorageKey>& storage_key) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
if (!origin.has_value()) {
|
||||
if (!storage_key.has_value()) {
|
||||
StartEvictionTimerWithDelay(interval_ms_);
|
||||
OnEvictionRoundFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(!origin->GetURL().is_empty());
|
||||
DCHECK(!storage_key->origin().GetURL().is_empty());
|
||||
|
||||
quota_eviction_handler_->EvictOriginData(
|
||||
*origin, blink::mojom::StorageType::kTemporary,
|
||||
quota_eviction_handler_->EvictStorageKeyData(
|
||||
*storage_key, blink::mojom::StorageType::kTemporary,
|
||||
base::BindOnce(&QuotaTemporaryStorageEvictor::OnEvictionComplete,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
@ -247,13 +243,13 @@ void QuotaTemporaryStorageEvictor::OnEvictionComplete(
|
||||
|
||||
// Just calling ConsiderEviction() or StartEvictionTimerWithDelay() here is
|
||||
// ok. No need to deal with the case that all of the Delete operations fail
|
||||
// for a certain origin. It doesn't result in trying to evict the same
|
||||
// origin permanently. The evictor skips origins which had deletion errors
|
||||
// a few times.
|
||||
// for a certain storage key. It doesn't result in trying to evict the same
|
||||
// storage key permanently. The evictor skips storage keys which had deletion
|
||||
// errors a few times.
|
||||
|
||||
if (status == blink::mojom::QuotaStatusCode::kOk) {
|
||||
++statistics_.num_evicted_origins;
|
||||
++round_statistics_.num_evicted_origins_in_round;
|
||||
++statistics_.num_evicted_storage_keys;
|
||||
++round_statistics_.num_evicted_storage_keys_in_round;
|
||||
// We many need to get rid of more space so reconsider immediately.
|
||||
ConsiderEviction();
|
||||
} else {
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
|
||||
namespace url {
|
||||
class Origin;
|
||||
namespace blink {
|
||||
class StorageKey;
|
||||
}
|
||||
|
||||
namespace storage {
|
||||
@ -31,37 +31,30 @@ struct QuotaSettings;
|
||||
class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaTemporaryStorageEvictor {
|
||||
public:
|
||||
struct Statistics {
|
||||
Statistics()
|
||||
: num_errors_on_getting_usage_and_quota(0),
|
||||
num_evicted_origins(0),
|
||||
num_eviction_rounds(0),
|
||||
num_skipped_eviction_rounds(0) {}
|
||||
int64_t num_errors_on_getting_usage_and_quota;
|
||||
int64_t num_evicted_origins;
|
||||
int64_t num_eviction_rounds;
|
||||
int64_t num_skipped_eviction_rounds;
|
||||
int64_t num_errors_on_getting_usage_and_quota = 0;
|
||||
int64_t num_evicted_storage_keys = 0;
|
||||
int64_t num_eviction_rounds = 0;
|
||||
int64_t num_skipped_eviction_rounds = 0;
|
||||
|
||||
void subtract_assign(const Statistics& rhs) {
|
||||
num_errors_on_getting_usage_and_quota -=
|
||||
rhs.num_errors_on_getting_usage_and_quota;
|
||||
num_evicted_origins -= rhs.num_evicted_origins;
|
||||
num_evicted_storage_keys -= rhs.num_evicted_storage_keys;
|
||||
num_eviction_rounds -= rhs.num_eviction_rounds;
|
||||
num_skipped_eviction_rounds -= rhs.num_skipped_eviction_rounds;
|
||||
}
|
||||
};
|
||||
|
||||
struct EvictionRoundStatistics {
|
||||
EvictionRoundStatistics();
|
||||
|
||||
bool in_round;
|
||||
bool is_initialized;
|
||||
bool in_round = false;
|
||||
bool is_initialized = false;
|
||||
|
||||
base::Time start_time;
|
||||
int64_t diskspace_shortage_at_round;
|
||||
int64_t diskspace_shortage_at_round = -1;
|
||||
|
||||
int64_t usage_on_beginning_of_round;
|
||||
int64_t usage_on_end_of_round;
|
||||
int64_t num_evicted_origins_in_round;
|
||||
int64_t usage_on_beginning_of_round = -1;
|
||||
int64_t usage_on_end_of_round = -1;
|
||||
int64_t num_evicted_storage_keys_in_round = 0;
|
||||
};
|
||||
|
||||
QuotaTemporaryStorageEvictor(QuotaEvictionHandler* quota_eviction_handler,
|
||||
@ -84,7 +77,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaTemporaryStorageEvictor {
|
||||
int64_t total_space,
|
||||
int64_t current_usage,
|
||||
bool current_usage_is_complete);
|
||||
void OnGotEvictionOrigin(const absl::optional<url::Origin>& origin);
|
||||
void OnGotEvictionStorageKey(
|
||||
const absl::optional<blink::StorageKey>& storage_key);
|
||||
void OnEvictionComplete(blink::mojom::QuotaStatusCode status);
|
||||
|
||||
void OnEvictionRoundStarted();
|
||||
|
@ -19,9 +19,10 @@
|
||||
#include "storage/browser/quota/quota_manager_impl.h"
|
||||
#include "storage/browser/quota/quota_temporary_storage_evictor.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "url/gurl.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
|
||||
using blink::mojom::StorageType;
|
||||
using ::blink::StorageKey;
|
||||
using ::blink::mojom::StorageType;
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -29,29 +30,28 @@ class QuotaTemporaryStorageEvictorTest;
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO(crbug.com/889590): Replace with common converter.
|
||||
url::Origin ToOrigin(const std::string& url) {
|
||||
return url::Origin::Create(GURL(url));
|
||||
StorageKey ToStorageKey(const std::string& url) {
|
||||
return StorageKey::CreateFromStringForTesting(url);
|
||||
}
|
||||
|
||||
class MockQuotaEvictionHandler : public QuotaEvictionHandler {
|
||||
public:
|
||||
explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest* test)
|
||||
: available_space_(0),
|
||||
error_on_evict_origin_data_(false),
|
||||
error_on_evict_storage_key_data_(false),
|
||||
error_on_get_usage_and_quota_(false) {}
|
||||
|
||||
void EvictOriginData(const url::Origin& origin,
|
||||
StorageType type,
|
||||
StatusCallback callback) override {
|
||||
if (error_on_evict_origin_data_) {
|
||||
void EvictStorageKeyData(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
StatusCallback callback) override {
|
||||
if (error_on_evict_storage_key_data_) {
|
||||
std::move(callback).Run(
|
||||
blink::mojom::QuotaStatusCode::kErrorInvalidModification);
|
||||
return;
|
||||
}
|
||||
int64_t origin_usage = EnsureOriginRemoved(origin);
|
||||
if (origin_usage >= 0)
|
||||
available_space_ += origin_usage;
|
||||
int64_t storage_key_usage = EnsureStorageKeyRemoved(storage_key);
|
||||
if (storage_key_usage >= 0)
|
||||
available_space_ += storage_key_usage;
|
||||
std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk);
|
||||
}
|
||||
|
||||
@ -68,19 +68,19 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler {
|
||||
true);
|
||||
}
|
||||
|
||||
void GetEvictionOrigin(StorageType type,
|
||||
int64_t global_quota,
|
||||
GetOriginCallback callback) override {
|
||||
if (origin_order_.empty())
|
||||
void GetEvictionStorageKey(StorageType type,
|
||||
int64_t global_quota,
|
||||
GetStorageKeyCallback callback) override {
|
||||
if (storage_key_order_.empty())
|
||||
std::move(callback).Run(absl::nullopt);
|
||||
else
|
||||
std::move(callback).Run(origin_order_.front());
|
||||
std::move(callback).Run(storage_key_order_.front());
|
||||
}
|
||||
|
||||
int64_t GetUsage() const {
|
||||
int64_t total_usage = 0;
|
||||
for (const auto& origin_usage_pair : origins_)
|
||||
total_usage += origin_usage_pair.second;
|
||||
for (const auto& storage_key_usage_pair : storage_keys_)
|
||||
total_usage += storage_key_usage_pair.second;
|
||||
return total_usage;
|
||||
}
|
||||
|
||||
@ -98,48 +98,49 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler {
|
||||
void set_task_for_get_usage_and_quota(base::RepeatingClosure task) {
|
||||
task_for_get_usage_and_quota_ = std::move(task);
|
||||
}
|
||||
void set_error_on_evict_origin_data(bool error_on_evict_origin_data) {
|
||||
error_on_evict_origin_data_ = error_on_evict_origin_data;
|
||||
void set_error_on_evict_storage_key_data(
|
||||
bool error_on_evict_storage_key_data) {
|
||||
error_on_evict_storage_key_data_ = error_on_evict_storage_key_data;
|
||||
}
|
||||
void set_error_on_get_usage_and_quota(bool error_on_get_usage_and_quota) {
|
||||
error_on_get_usage_and_quota_ = error_on_get_usage_and_quota;
|
||||
}
|
||||
|
||||
// Simulates an access to |origin|. It reorders the internal LRU list.
|
||||
// It internally uses AddOrigin().
|
||||
void AccessOrigin(const url::Origin& origin) {
|
||||
const auto& it = origins_.find(origin);
|
||||
EXPECT_TRUE(origins_.end() != it);
|
||||
AddOrigin(origin, it->second);
|
||||
// Simulates an access to `storage_key`. It reorders the internal LRU list.
|
||||
// It internally uses AddStorageKey().
|
||||
void AccessStorageKey(const StorageKey& storage_key) {
|
||||
const auto& it = storage_keys_.find(storage_key);
|
||||
EXPECT_TRUE(storage_keys_.end() != it);
|
||||
AddStorageKey(storage_key, it->second);
|
||||
}
|
||||
|
||||
// Simulates adding or overwriting the |origin| to the internal origin set
|
||||
// with the |usage|. It also adds or moves the |origin| to the end of the
|
||||
// LRU list.
|
||||
void AddOrigin(const url::Origin& origin, int64_t usage) {
|
||||
EnsureOriginRemoved(origin);
|
||||
origin_order_.push_back(origin);
|
||||
origins_[origin] = usage;
|
||||
// Simulates adding or overwriting the `storage_key` to the internal storage
|
||||
// key set with the `usage`. It also adds or moves the `storage_key` to the
|
||||
// end of the LRU list.
|
||||
void AddStorageKey(const StorageKey& storage_key, int64_t usage) {
|
||||
EnsureStorageKeyRemoved(storage_key);
|
||||
storage_key_order_.push_back(storage_key);
|
||||
storage_keys_[storage_key] = usage;
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t EnsureOriginRemoved(const url::Origin& origin) {
|
||||
int64_t origin_usage;
|
||||
if (!base::Contains(origins_, origin))
|
||||
int64_t EnsureStorageKeyRemoved(const StorageKey& storage_key) {
|
||||
int64_t storage_key_usage;
|
||||
if (!base::Contains(storage_keys_, storage_key))
|
||||
return -1;
|
||||
else
|
||||
origin_usage = origins_[origin];
|
||||
storage_key_usage = storage_keys_[storage_key];
|
||||
|
||||
origins_.erase(origin);
|
||||
origin_order_.remove(origin);
|
||||
return origin_usage;
|
||||
storage_keys_.erase(storage_key);
|
||||
storage_key_order_.remove(storage_key);
|
||||
return storage_key_usage;
|
||||
}
|
||||
|
||||
QuotaSettings settings_;
|
||||
int64_t available_space_;
|
||||
std::list<url::Origin> origin_order_;
|
||||
std::map<url::Origin, int64_t> origins_;
|
||||
bool error_on_evict_origin_data_;
|
||||
std::list<StorageKey> storage_key_order_;
|
||||
std::map<StorageKey, int64_t> storage_keys_;
|
||||
bool error_on_evict_storage_key_data_;
|
||||
bool error_on_get_usage_and_quota_;
|
||||
|
||||
base::RepeatingClosure task_for_get_usage_and_quota_;
|
||||
@ -167,8 +168,9 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
||||
}
|
||||
|
||||
void TaskForRepeatedEvictionTest(
|
||||
const std::pair<absl::optional<url::Origin>, int64_t>& origin_to_be_added,
|
||||
const absl::optional<url::Origin>& origin_to_be_accessed,
|
||||
const std::pair<absl::optional<StorageKey>, int64_t>&
|
||||
storage_key_to_be_added,
|
||||
const absl::optional<StorageKey>& storage_key_to_be_accessed,
|
||||
int expected_usage_after_first,
|
||||
int expected_usage_after_second) {
|
||||
EXPECT_GE(4, num_get_usage_and_quota_for_eviction_);
|
||||
@ -176,11 +178,12 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
||||
case 2:
|
||||
EXPECT_EQ(expected_usage_after_first,
|
||||
quota_eviction_handler()->GetUsage());
|
||||
if (origin_to_be_added.first.has_value())
|
||||
quota_eviction_handler()->AddOrigin(*origin_to_be_added.first,
|
||||
origin_to_be_added.second);
|
||||
if (origin_to_be_accessed.has_value())
|
||||
quota_eviction_handler()->AccessOrigin(*origin_to_be_accessed);
|
||||
if (storage_key_to_be_added.first.has_value())
|
||||
quota_eviction_handler()->AddStorageKey(
|
||||
*storage_key_to_be_added.first, storage_key_to_be_added.second);
|
||||
if (storage_key_to_be_accessed.has_value())
|
||||
quota_eviction_handler()->AccessStorageKey(
|
||||
*storage_key_to_be_accessed);
|
||||
break;
|
||||
case 3:
|
||||
EXPECT_EQ(expected_usage_after_second,
|
||||
@ -222,9 +225,12 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) {
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.z.com"), 3000);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.y.com"), 200);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.x.com"), 500);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.z.com"),
|
||||
3000);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.y.com"),
|
||||
200);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.x.com"),
|
||||
500);
|
||||
quota_eviction_handler()->SetPoolSize(4000);
|
||||
quota_eviction_handler()->set_available_space(1000000000);
|
||||
EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage());
|
||||
@ -234,16 +240,19 @@ TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) {
|
||||
EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(1, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(1, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(1, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) {
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.z.com"), 20);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.y.com"), 2900);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.x.com"), 450);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.w.com"), 400);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.z.com"), 20);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.y.com"),
|
||||
2900);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.x.com"),
|
||||
450);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.w.com"),
|
||||
400);
|
||||
quota_eviction_handler()->SetPoolSize(4000);
|
||||
quota_eviction_handler()->set_available_space(1000000000);
|
||||
EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage());
|
||||
@ -253,7 +262,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) {
|
||||
EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(2, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(2, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(1, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
@ -266,18 +275,22 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
|
||||
const int64_t initial_total_size = a_size + b_size + c_size + d_size;
|
||||
const int64_t e_size = 275;
|
||||
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.d.com"), d_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.c.com"), c_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.b.com"), b_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.a.com"), a_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.d.com"),
|
||||
d_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.c.com"),
|
||||
c_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.b.com"),
|
||||
b_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.a.com"),
|
||||
a_size);
|
||||
quota_eviction_handler()->SetPoolSize(1000);
|
||||
quota_eviction_handler()->set_available_space(1000000000);
|
||||
quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
||||
base::BindRepeating(
|
||||
&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
|
||||
weak_factory_.GetWeakPtr(),
|
||||
std::make_pair(ToOrigin("http://www.e.com"), e_size), absl::nullopt,
|
||||
initial_total_size - d_size,
|
||||
std::make_pair(ToStorageKey("http://www.e.com"), e_size),
|
||||
absl::nullopt, initial_total_size - d_size,
|
||||
initial_total_size - d_size + e_size - c_size));
|
||||
EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
|
||||
temporary_storage_evictor()->Start();
|
||||
@ -287,7 +300,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
|
||||
EXPECT_EQ(5, num_get_usage_and_quota_for_eviction());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(3, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(3, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(2, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
@ -299,10 +312,14 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionSkippedTest) {
|
||||
const int64_t d_size = 292;
|
||||
const int64_t initial_total_size = a_size + b_size + c_size + d_size;
|
||||
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.d.com"), d_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.c.com"), c_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.b.com"), b_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.a.com"), a_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.d.com"),
|
||||
d_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.c.com"),
|
||||
c_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.b.com"),
|
||||
b_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.a.com"),
|
||||
a_size);
|
||||
quota_eviction_handler()->SetPoolSize(1000);
|
||||
quota_eviction_handler()->set_available_space(1000000000);
|
||||
quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
||||
@ -319,12 +336,13 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionSkippedTest) {
|
||||
EXPECT_EQ(4, num_get_usage_and_quota_for_eviction());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(1, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(1, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(3, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(2, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest,
|
||||
RepeatedEvictionWithAccessStorageKeyTest) {
|
||||
const int64_t a_size = 400;
|
||||
const int64_t b_size = 150;
|
||||
const int64_t c_size = 120;
|
||||
@ -332,18 +350,22 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
||||
const int64_t initial_total_size = a_size + b_size + c_size + d_size;
|
||||
const int64_t e_size = 275;
|
||||
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.d.com"), d_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.c.com"), c_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.b.com"), b_size);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.a.com"), a_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.d.com"),
|
||||
d_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.c.com"),
|
||||
c_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.b.com"),
|
||||
b_size);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.a.com"),
|
||||
a_size);
|
||||
quota_eviction_handler()->SetPoolSize(1000);
|
||||
quota_eviction_handler()->set_available_space(1000000000);
|
||||
quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
||||
base::BindRepeating(
|
||||
&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
|
||||
weak_factory_.GetWeakPtr(),
|
||||
std::make_pair(ToOrigin("http://www.e.com"), e_size),
|
||||
ToOrigin("http://www.c.com"), initial_total_size - d_size,
|
||||
std::make_pair(ToStorageKey("http://www.e.com"), e_size),
|
||||
ToStorageKey("http://www.c.com"), initial_total_size - d_size,
|
||||
initial_total_size - d_size + e_size - b_size));
|
||||
EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
|
||||
temporary_storage_evictor()->Start();
|
||||
@ -353,7 +375,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
||||
EXPECT_EQ(5, num_get_usage_and_quota_for_eviction());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(3, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(3, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(2, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(0, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
@ -361,8 +383,8 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) {
|
||||
// If we're using so little that evicting all of it wouldn't
|
||||
// do enough to alleviate a diskspace shortage, we don't evict.
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.z.com"), 10);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.x.com"), 20);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.z.com"), 10);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.x.com"), 20);
|
||||
quota_eviction_handler()->SetPoolSize(10000);
|
||||
quota_eviction_handler()->set_available_space(
|
||||
quota_eviction_handler()->settings().should_remain_available - 350);
|
||||
@ -373,16 +395,20 @@ TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) {
|
||||
EXPECT_EQ(10 + 20, quota_eviction_handler()->GetUsage());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(0, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(0, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(1, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(1, statistics().num_skipped_eviction_rounds);
|
||||
}
|
||||
|
||||
TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) {
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.z.com"), 294);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.y.com"), 120);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.x.com"), 150);
|
||||
quota_eviction_handler()->AddOrigin(ToOrigin("http://www.w.com"), 300);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.z.com"),
|
||||
294);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.y.com"),
|
||||
120);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.x.com"),
|
||||
150);
|
||||
quota_eviction_handler()->AddStorageKey(ToStorageKey("http://www.w.com"),
|
||||
300);
|
||||
quota_eviction_handler()->SetPoolSize(10000);
|
||||
quota_eviction_handler()->set_available_space(
|
||||
quota_eviction_handler()->settings().should_remain_available - 350);
|
||||
@ -393,7 +419,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) {
|
||||
EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage());
|
||||
|
||||
EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
||||
EXPECT_EQ(2, statistics().num_evicted_origins);
|
||||
EXPECT_EQ(2, statistics().num_evicted_storage_keys);
|
||||
EXPECT_EQ(1, statistics().num_eviction_rounds);
|
||||
EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); // FIXME?
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "storage/common/file_system/file_system_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -307,7 +308,7 @@ blink::mojom::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota(
|
||||
blink::mojom::QuotaStatusCode::kUnknown;
|
||||
base::RunLoop run_loop;
|
||||
quota_manager->GetUsageAndQuota(
|
||||
origin, FileSystemTypeToQuotaStorageType(type),
|
||||
blink::StorageKey(origin), FileSystemTypeToQuotaStorageType(type),
|
||||
base::BindOnce(&DidGetUsageAndQuota, &status, usage, quota,
|
||||
run_loop.QuitWhenIdleClosure()));
|
||||
run_loop.Run();
|
||||
|
@ -28,6 +28,7 @@ namespace storage {
|
||||
|
||||
class QuotaManagerProxy;
|
||||
|
||||
// TODO(crbug.com/1215208): Change to MockStorageKeyData.
|
||||
struct MockOriginData {
|
||||
const char* origin;
|
||||
blink::mojom::StorageType type;
|
||||
|
@ -15,25 +15,28 @@
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "storage/browser/quota/quota_client_type.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using ::blink::StorageKey;
|
||||
using ::blink::mojom::StorageType;
|
||||
|
||||
namespace storage {
|
||||
|
||||
MockQuotaManager::OriginInfo::OriginInfo(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified)
|
||||
: origin(origin),
|
||||
MockQuotaManager::StorageKeyInfo::StorageKeyInfo(
|
||||
const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified)
|
||||
: storage_key(storage_key),
|
||||
type(type),
|
||||
quota_client_types(std::move(quota_client_types)),
|
||||
modified(modified) {}
|
||||
|
||||
MockQuotaManager::OriginInfo::~OriginInfo() = default;
|
||||
MockQuotaManager::StorageKeyInfo::~StorageKeyInfo() = default;
|
||||
|
||||
MockQuotaManager::OriginInfo::OriginInfo(MockQuotaManager::OriginInfo&&) =
|
||||
default;
|
||||
MockQuotaManager::OriginInfo& MockQuotaManager::OriginInfo::operator=(
|
||||
MockQuotaManager::OriginInfo&&) = default;
|
||||
MockQuotaManager::StorageKeyInfo::StorageKeyInfo(
|
||||
MockQuotaManager::StorageKeyInfo&&) = default;
|
||||
MockQuotaManager::StorageKeyInfo& MockQuotaManager::StorageKeyInfo::operator=(
|
||||
MockQuotaManager::StorageKeyInfo&&) = default;
|
||||
|
||||
MockQuotaManager::StorageInfo::StorageInfo()
|
||||
: usage(0), quota(std::numeric_limits<int64_t>::max()) {}
|
||||
@ -51,99 +54,102 @@ MockQuotaManager::MockQuotaManager(
|
||||
std::move(special_storage_policy),
|
||||
GetQuotaSettingsFunc()) {}
|
||||
|
||||
void MockQuotaManager::GetUsageAndQuota(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
void MockQuotaManager::GetUsageAndQuota(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
UsageAndQuotaCallback callback) {
|
||||
StorageInfo& info = usage_and_quota_map_[std::make_pair(origin, type)];
|
||||
StorageInfo& info = usage_and_quota_map_[std::make_pair(storage_key, type)];
|
||||
std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk, info.usage,
|
||||
info.quota);
|
||||
}
|
||||
|
||||
void MockQuotaManager::SetQuota(const url::Origin& origin,
|
||||
void MockQuotaManager::SetQuota(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
int64_t quota) {
|
||||
usage_and_quota_map_[std::make_pair(origin, type)].quota = quota;
|
||||
usage_and_quota_map_[std::make_pair(storage_key, type)].quota = quota;
|
||||
}
|
||||
|
||||
bool MockQuotaManager::AddOrigin(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified) {
|
||||
origins_.push_back(
|
||||
OriginInfo(origin, type, std::move(quota_client_types), modified));
|
||||
bool MockQuotaManager::AddStorageKey(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified) {
|
||||
storage_keys_.emplace_back(StorageKeyInfo(
|
||||
storage_key, type, std::move(quota_client_types), modified));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MockQuotaManager::OriginHasData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientType quota_client) const {
|
||||
for (const auto& info : origins_) {
|
||||
if (info.origin == origin && info.type == type &&
|
||||
bool MockQuotaManager::StorageKeyHasData(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
QuotaClientType quota_client) const {
|
||||
for (const auto& info : storage_keys_) {
|
||||
if (info.storage_key == storage_key && info.type == type &&
|
||||
info.quota_client_types.contains(quota_client))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MockQuotaManager::GetOriginsModifiedBetween(blink::mojom::StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetOriginsCallback callback) {
|
||||
auto origins_to_return = std::make_unique<std::set<url::Origin>>();
|
||||
for (const auto& info : origins_) {
|
||||
void MockQuotaManager::GetStorageKeysModifiedBetween(
|
||||
StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetStorageKeysCallback callback) {
|
||||
auto storage_keys_to_return = std::make_unique<std::set<StorageKey>>();
|
||||
for (const auto& info : storage_keys_) {
|
||||
if (info.type == type && info.modified >= begin && info.modified < end)
|
||||
origins_to_return->insert(info.origin);
|
||||
storage_keys_to_return->insert(info.storage_key);
|
||||
}
|
||||
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&MockQuotaManager::DidGetModifiedInTimeRange,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback),
|
||||
std::move(origins_to_return), type));
|
||||
std::move(storage_keys_to_return), type));
|
||||
}
|
||||
|
||||
void MockQuotaManager::DeleteOriginData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback) {
|
||||
for (auto current = origins_.begin(); current != origins_.end(); ++current) {
|
||||
if (current->origin == origin && current->type == type) {
|
||||
// Modify the mask: if it's 0 after "deletion", remove the origin.
|
||||
void MockQuotaManager::DeleteStorageKeyData(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback) {
|
||||
for (auto current = storage_keys_.begin(); current != storage_keys_.end();
|
||||
++current) {
|
||||
if (current->storage_key == storage_key && current->type == type) {
|
||||
// Modify the mask: if it's 0 after "deletion", remove the storage key.
|
||||
for (QuotaClientType type : quota_client_types)
|
||||
current->quota_client_types.erase(type);
|
||||
if (current->quota_client_types.empty())
|
||||
origins_.erase(current);
|
||||
storage_keys_.erase(current);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&MockQuotaManager::DidDeleteOriginData,
|
||||
FROM_HERE, base::BindOnce(&MockQuotaManager::DidDeleteStorageKeyData,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback),
|
||||
blink::mojom::QuotaStatusCode::kOk));
|
||||
}
|
||||
|
||||
void MockQuotaManager::NotifyWriteFailed(const url::Origin& origin) {
|
||||
auto origin_error_log =
|
||||
write_error_tracker_.insert(std::pair<url::Origin, int>(origin, 0)).first;
|
||||
++origin_error_log->second;
|
||||
void MockQuotaManager::NotifyWriteFailed(const StorageKey& storage_key) {
|
||||
auto storage_key_error_log =
|
||||
write_error_tracker_.insert(std::pair<StorageKey, int>(storage_key, 0))
|
||||
.first;
|
||||
++storage_key_error_log->second;
|
||||
}
|
||||
|
||||
MockQuotaManager::~MockQuotaManager() = default;
|
||||
|
||||
void MockQuotaManager::UpdateUsage(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
void MockQuotaManager::UpdateUsage(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
int64_t delta) {
|
||||
usage_and_quota_map_[std::make_pair(origin, type)].usage += delta;
|
||||
usage_and_quota_map_[std::make_pair(storage_key, type)].usage += delta;
|
||||
}
|
||||
|
||||
void MockQuotaManager::DidGetModifiedInTimeRange(
|
||||
GetOriginsCallback callback,
|
||||
std::unique_ptr<std::set<url::Origin>> origins,
|
||||
blink::mojom::StorageType storage_type) {
|
||||
std::move(callback).Run(*origins, storage_type);
|
||||
GetStorageKeysCallback callback,
|
||||
std::unique_ptr<std::set<StorageKey>> storage_keys,
|
||||
StorageType storage_type) {
|
||||
std::move(callback).Run(*storage_keys, storage_type);
|
||||
}
|
||||
|
||||
void MockQuotaManager::DidDeleteOriginData(
|
||||
void MockQuotaManager::DidDeleteStorageKeyData(
|
||||
StatusCallback callback,
|
||||
blink::mojom::QuotaStatusCode status) {
|
||||
std::move(callback).Run(status);
|
||||
|
@ -18,10 +18,8 @@
|
||||
#include "storage/browser/quota/quota_client_type.h"
|
||||
#include "storage/browser/quota/quota_manager.h"
|
||||
#include "storage/browser/quota/quota_task.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
using blink::mojom::StorageType;
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -32,10 +30,10 @@ namespace storage {
|
||||
// methods: SetQuota() and UpdateUsage().
|
||||
//
|
||||
// For time-based deletion test:
|
||||
// Origins can be added to the mock by calling AddOrigin, and that list of
|
||||
// origins is then searched through in GetOriginsModifiedBetween.
|
||||
// Neither GetOriginsModifiedBetween nor DeleteOriginData touches the actual
|
||||
// origin data stored in the profile.
|
||||
// Storage keys can be added to the mock by calling AddStorageKey, and that list
|
||||
// of storage keys is then searched through in GetStorageKeysModifiedBetween.
|
||||
// Neither GetStorageKeysModifiedBetween nor DeleteStorageKeyData touches the
|
||||
// actual storage key data stored in the profile.
|
||||
class MockQuotaManager : public QuotaManager {
|
||||
public:
|
||||
MockQuotaManager(bool is_incognito,
|
||||
@ -47,54 +45,58 @@ class MockQuotaManager : public QuotaManager {
|
||||
// updated when MockQuotaManagerProxy::NotifyStorageModified() is
|
||||
// called. The internal quota value can be updated by calling
|
||||
// a helper method MockQuotaManagerProxy::SetQuota().
|
||||
void GetUsageAndQuota(const url::Origin& origin,
|
||||
void GetUsageAndQuota(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
UsageAndQuotaCallback callback) override;
|
||||
|
||||
// Overrides QuotaManager's implementation with a canned implementation that
|
||||
// allows clients to set up the origin database that should be queried. This
|
||||
// method will only search through the origins added explicitly via AddOrigin.
|
||||
void GetOriginsModifiedBetween(blink::mojom::StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetOriginsCallback callback) override;
|
||||
// allows clients to set up the storage key database that should be queried.
|
||||
// This method will only search through the storage keys added explicitly via
|
||||
// AddStorageKey.
|
||||
void GetStorageKeysModifiedBetween(blink::mojom::StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end,
|
||||
GetStorageKeysCallback callback) override;
|
||||
|
||||
// Removes an origin from the canned list of origins, but doesn't touch
|
||||
// anything on disk. The caller must provide |quota_client_types| which
|
||||
// Removes an storage key from the canned list of storage keys, but doesn't
|
||||
// touch anything on disk. The caller must provide `quota_client_types` which
|
||||
// specifies the types of QuotaClients which should be removed from this
|
||||
// origin. Setting the mask to AllQuotaClientTypes() will remove all clients
|
||||
// from the origin, regardless of type.
|
||||
void DeleteOriginData(const url::Origin& origin,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback) override;
|
||||
// storage key. Setting the mask to AllQuotaClientTypes() will remove all
|
||||
// clients from the storage key, regardless of type.
|
||||
void DeleteStorageKeyData(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
StatusCallback callback) override;
|
||||
|
||||
// Overrides QuotaManager's implementation so that tests can observe
|
||||
// calls to this function.
|
||||
void NotifyWriteFailed(const url::Origin& origin) override;
|
||||
void NotifyWriteFailed(const blink::StorageKey& storage_key) override;
|
||||
|
||||
// Helper method for updating internal quota info.
|
||||
void SetQuota(const url::Origin& origin, StorageType type, int64_t quota);
|
||||
void SetQuota(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
int64_t quota);
|
||||
|
||||
// Helper methods for timed-deletion testing:
|
||||
// Adds an origin to the canned list that will be searched through via
|
||||
// GetOriginsModifiedBetween.
|
||||
// |quota_clients| specified the types of QuotaClients this canned origin
|
||||
// Adds a storage key to the canned list that will be searched through via
|
||||
// GetStorageKeysModifiedBetween.
|
||||
// `quota_clients` specified the types of QuotaClients this canned storage key
|
||||
// contains.
|
||||
bool AddOrigin(const url::Origin& origin,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified);
|
||||
bool AddStorageKey(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_client_types,
|
||||
base::Time modified);
|
||||
|
||||
// Helper methods for timed-deletion testing:
|
||||
// Checks an origin and type against the origins that have been added via
|
||||
// AddOrigin and removed via DeleteOriginData. If the origin exists in the
|
||||
// canned list with the proper StorageType and client, returns true.
|
||||
bool OriginHasData(const url::Origin& origin,
|
||||
StorageType type,
|
||||
QuotaClientType quota_client_type) const;
|
||||
// Checks an storage key and type against the storage keys that have been
|
||||
// added via AddStorageKey and removed via DeleteStorageKeyData. If the
|
||||
// storage key exists in the canned list with the proper StorageType and
|
||||
// client, returns true.
|
||||
bool StorageKeyHasData(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientType quota_client_type) const;
|
||||
|
||||
std::map<const url::Origin, int> write_error_tracker() const {
|
||||
std::map<const blink::StorageKey, int> write_error_tracker() const {
|
||||
return write_error_tracker_;
|
||||
}
|
||||
|
||||
@ -104,32 +106,32 @@ class MockQuotaManager : public QuotaManager {
|
||||
private:
|
||||
friend class MockQuotaManagerProxy;
|
||||
|
||||
// Contains the essential bits of information about an origin that the
|
||||
// Contains the essential bits of information about an storage key that the
|
||||
// MockQuotaManager needs to understand for time-based deletion:
|
||||
// the origin itself, the StorageType and its modification time.
|
||||
struct OriginInfo {
|
||||
OriginInfo(const url::Origin& origin,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_clients,
|
||||
base::Time modified);
|
||||
~OriginInfo();
|
||||
// the storage key itself, the StorageType and its modification time.
|
||||
struct StorageKeyInfo {
|
||||
StorageKeyInfo(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
QuotaClientTypes quota_clients,
|
||||
base::Time modified);
|
||||
~StorageKeyInfo();
|
||||
|
||||
OriginInfo(const OriginInfo&) = delete;
|
||||
OriginInfo& operator=(const OriginInfo&) = delete;
|
||||
StorageKeyInfo(const StorageKeyInfo&) = delete;
|
||||
StorageKeyInfo& operator=(const StorageKeyInfo&) = delete;
|
||||
|
||||
OriginInfo(OriginInfo&&);
|
||||
OriginInfo& operator=(OriginInfo&&);
|
||||
StorageKeyInfo(StorageKeyInfo&&);
|
||||
StorageKeyInfo& operator=(StorageKeyInfo&&);
|
||||
|
||||
url::Origin origin;
|
||||
StorageType type;
|
||||
blink::StorageKey storage_key;
|
||||
blink::mojom::StorageType type;
|
||||
QuotaClientTypes quota_client_types;
|
||||
base::Time modified;
|
||||
};
|
||||
|
||||
// Contains the essential information for each origin for usage/quota testing.
|
||||
// (Ideally this should probably merged into the above struct, but for
|
||||
// regular usage/quota testing we hardly need modified time but only
|
||||
// want to keep usage and quota information, so this struct exists.
|
||||
// Contains the essential information for each storage key for usage/quota
|
||||
// testing. (Ideally this should probably merged into the above struct, but
|
||||
// for regular usage/quota testing we hardly need modified time but only want
|
||||
// to keep usage and quota information, so this struct exists.
|
||||
struct StorageInfo {
|
||||
StorageInfo();
|
||||
~StorageInfo();
|
||||
@ -139,20 +141,23 @@ class MockQuotaManager : public QuotaManager {
|
||||
};
|
||||
|
||||
// This must be called via MockQuotaManagerProxy.
|
||||
void UpdateUsage(const url::Origin& origin, StorageType type, int64_t delta);
|
||||
void DidGetModifiedInTimeRange(GetOriginsCallback callback,
|
||||
std::unique_ptr<std::set<url::Origin>> origins,
|
||||
StorageType storage_type);
|
||||
void DidDeleteOriginData(StatusCallback callback,
|
||||
blink::mojom::QuotaStatusCode status);
|
||||
void UpdateUsage(const blink::StorageKey& storage_key,
|
||||
blink::mojom::StorageType type,
|
||||
int64_t delta);
|
||||
void DidGetModifiedInTimeRange(
|
||||
GetStorageKeysCallback callback,
|
||||
std::unique_ptr<std::set<blink::StorageKey>> storage_keys,
|
||||
blink::mojom::StorageType storage_type);
|
||||
void DidDeleteStorageKeyData(StatusCallback callback,
|
||||
blink::mojom::QuotaStatusCode status);
|
||||
|
||||
// The list of stored origins that have been added via AddOrigin.
|
||||
std::vector<OriginInfo> origins_;
|
||||
std::map<std::pair<url::Origin, StorageType>, StorageInfo>
|
||||
// The list of stored storage keys that have been added via AddStorageKey.
|
||||
std::vector<StorageKeyInfo> storage_keys_;
|
||||
std::map<std::pair<blink::StorageKey, blink::mojom::StorageType>, StorageInfo>
|
||||
usage_and_quota_map_;
|
||||
|
||||
// Tracks number of times NotifyFailedWrite has been called per origin.
|
||||
std::map<const url::Origin, int> write_error_tracker_;
|
||||
// Tracks number of times NotifyFailedWrite has been called per storage key.
|
||||
std::map<const blink::StorageKey, int> write_error_tracker_;
|
||||
|
||||
base::WeakPtrFactory<MockQuotaManager> weak_factory_{this};
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "components/services/storage/public/mojom/quota_client.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -36,7 +37,8 @@ void MockQuotaManagerProxy::GetUsageAndQuota(
|
||||
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
|
||||
QuotaManager::UsageAndQuotaCallback callback) {
|
||||
if (mock_quota_manager_) {
|
||||
mock_quota_manager_->GetUsageAndQuota(origin, type, std::move(callback));
|
||||
mock_quota_manager_->GetUsageAndQuota(blink::StorageKey(origin), type,
|
||||
std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +64,7 @@ void MockQuotaManagerProxy::NotifyStorageModified(
|
||||
last_notified_type_ = type;
|
||||
last_notified_delta_ = delta;
|
||||
if (mock_quota_manager_) {
|
||||
mock_quota_manager_->UpdateUsage(origin, type, delta);
|
||||
mock_quota_manager_->UpdateUsage(blink::StorageKey(origin), type, delta);
|
||||
}
|
||||
if (callback)
|
||||
callback_task_runner->PostTask(FROM_HERE, std::move(callback));
|
||||
|
@ -19,7 +19,8 @@
|
||||
#include "storage/browser/test/mock_special_storage_policy.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
using blink::mojom::StorageType;
|
||||
using ::blink::StorageKey;
|
||||
using ::blink::mojom::StorageType;
|
||||
|
||||
namespace storage {
|
||||
|
||||
@ -51,29 +52,31 @@ class MockQuotaManagerTest : public testing::Test {
|
||||
base::RunLoop().RunUntilIdle();
|
||||
}
|
||||
|
||||
void GetModifiedOrigins(StorageType type, base::Time begin, base::Time end) {
|
||||
manager_->GetOriginsModifiedBetween(
|
||||
void GetModifiedStorageKeys(StorageType type,
|
||||
base::Time begin,
|
||||
base::Time end) {
|
||||
manager_->GetStorageKeysModifiedBetween(
|
||||
type, begin, end,
|
||||
base::BindOnce(&MockQuotaManagerTest::GotModifiedOrigins,
|
||||
base::BindOnce(&MockQuotaManagerTest::GotModifiedStorageKeys,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void GotModifiedOrigins(const std::set<url::Origin>& origins,
|
||||
StorageType type) {
|
||||
origins_ = origins;
|
||||
void GotModifiedStorageKeys(const std::set<StorageKey>& storage_keys,
|
||||
StorageType type) {
|
||||
storage_keys_ = storage_keys;
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
void DeleteOriginData(const url::Origin& origin,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types) {
|
||||
manager_->DeleteOriginData(
|
||||
origin, type, std::move(quota_client_types),
|
||||
base::BindOnce(&MockQuotaManagerTest::DeletedOriginData,
|
||||
void DeleteStorageKeyData(const StorageKey& storage_key,
|
||||
StorageType type,
|
||||
QuotaClientTypes quota_client_types) {
|
||||
manager_->DeleteStorageKeyData(
|
||||
storage_key, type, std::move(quota_client_types),
|
||||
base::BindOnce(&MockQuotaManagerTest::DeletedStorageKeyData,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void DeletedOriginData(blink::mojom::QuotaStatusCode status) {
|
||||
void DeletedStorageKeyData(blink::mojom::QuotaStatusCode status) {
|
||||
++deletion_callback_count_;
|
||||
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, status);
|
||||
}
|
||||
@ -86,7 +89,7 @@ class MockQuotaManagerTest : public testing::Test {
|
||||
return manager_.get();
|
||||
}
|
||||
|
||||
const std::set<url::Origin>& origins() const { return origins_; }
|
||||
const std::set<StorageKey>& storage_keys() const { return storage_keys_; }
|
||||
|
||||
const StorageType& type() const {
|
||||
return type_;
|
||||
@ -100,7 +103,7 @@ class MockQuotaManagerTest : public testing::Test {
|
||||
|
||||
int deletion_callback_count_;
|
||||
|
||||
std::set<url::Origin> origins_;
|
||||
std::set<StorageKey> storage_keys_;
|
||||
StorageType type_;
|
||||
|
||||
base::WeakPtrFactory<MockQuotaManagerTest> weak_factory_{this};
|
||||
@ -108,130 +111,183 @@ class MockQuotaManagerTest : public testing::Test {
|
||||
DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerTest);
|
||||
};
|
||||
|
||||
TEST_F(MockQuotaManagerTest, BasicOriginManipulation) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
TEST_F(MockQuotaManagerTest, BasicStorageKeyManipulation) {
|
||||
const StorageKey kStorageKey1 =
|
||||
StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const StorageKey kStorageKey2 =
|
||||
StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientDB));
|
||||
|
||||
manager()->AddOrigin(kOrigin1, kTemporary, {kClientFile}, base::Time::Now());
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientDB));
|
||||
manager()->AddStorageKey(kStorageKey1, kTemporary, {kClientFile},
|
||||
base::Time::Now());
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientDB));
|
||||
|
||||
manager()->AddOrigin(kOrigin1, kPersistent, {kClientFile}, base::Time::Now());
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientDB));
|
||||
manager()->AddStorageKey(kStorageKey1, kPersistent, {kClientFile},
|
||||
base::Time::Now());
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientDB));
|
||||
|
||||
manager()->AddOrigin(kOrigin2, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin1, kPersistent, kClientDB));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kPersistent, kClientDB));
|
||||
manager()->AddStorageKey(kStorageKey2, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kPersistent, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kPersistent, kClientDB));
|
||||
}
|
||||
|
||||
TEST_F(MockQuotaManagerTest, OriginDeletion) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
const url::Origin kOrigin3 = url::Origin::Create(GURL("http://host3:1/"));
|
||||
TEST_F(MockQuotaManagerTest, StorageKeyDeletion) {
|
||||
const StorageKey kStorageKey1 =
|
||||
StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const StorageKey kStorageKey2 =
|
||||
StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
const StorageKey kStorageKey3 =
|
||||
StorageKey::CreateFromStringForTesting("http://host3:1/");
|
||||
|
||||
manager()->AddOrigin(kOrigin1, kTemporary, {kClientFile}, base::Time::Now());
|
||||
manager()->AddOrigin(kOrigin2, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
manager()->AddOrigin(kOrigin3, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
manager()->AddStorageKey(kStorageKey1, kTemporary, {kClientFile},
|
||||
base::Time::Now());
|
||||
manager()->AddStorageKey(kStorageKey2, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
manager()->AddStorageKey(kStorageKey3, kTemporary, {kClientFile, kClientDB},
|
||||
base::Time::Now());
|
||||
|
||||
DeleteOriginData(kOrigin2, kTemporary, {kClientFile});
|
||||
DeleteStorageKeyData(kStorageKey2, kTemporary, {kClientFile});
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(1, deletion_callback_count());
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin3, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey3, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey3, kTemporary, kClientDB));
|
||||
|
||||
DeleteOriginData(kOrigin3, kTemporary, {kClientFile, kClientDB});
|
||||
DeleteStorageKeyData(kStorageKey3, kTemporary, {kClientFile, kClientDB});
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(2, deletion_callback_count());
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(manager()->OriginHasData(kOrigin2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(manager()->OriginHasData(kOrigin3, kTemporary, kClientDB));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey1, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientFile));
|
||||
EXPECT_TRUE(
|
||||
manager()->StorageKeyHasData(kStorageKey2, kTemporary, kClientDB));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey3, kTemporary, kClientFile));
|
||||
EXPECT_FALSE(
|
||||
manager()->StorageKeyHasData(kStorageKey3, kTemporary, kClientDB));
|
||||
}
|
||||
|
||||
TEST_F(MockQuotaManagerTest, ModifiedOrigins) {
|
||||
const url::Origin kOrigin1 = url::Origin::Create(GURL("http://host1:1/"));
|
||||
const url::Origin kOrigin2 = url::Origin::Create(GURL("http://host2:1/"));
|
||||
TEST_F(MockQuotaManagerTest, ModifiedStorageKeys) {
|
||||
const StorageKey kStorageKey1 =
|
||||
StorageKey::CreateFromStringForTesting("http://host1:1/");
|
||||
const StorageKey kStorageKey2 =
|
||||
StorageKey::CreateFromStringForTesting("http://host2:1/");
|
||||
|
||||
base::Time now = base::Time::Now();
|
||||
base::Time then = base::Time();
|
||||
base::TimeDelta an_hour = base::TimeDelta::FromMilliseconds(3600000);
|
||||
base::TimeDelta a_minute = base::TimeDelta::FromMilliseconds(60000);
|
||||
|
||||
GetModifiedOrigins(kTemporary, then, base::Time::Max());
|
||||
GetModifiedStorageKeys(kTemporary, then, base::Time::Max());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
EXPECT_TRUE(origins().empty());
|
||||
EXPECT_TRUE(storage_keys().empty());
|
||||
|
||||
manager()->AddOrigin(kOrigin1, kTemporary, {kClientFile}, now - an_hour);
|
||||
manager()->AddStorageKey(kStorageKey1, kTemporary, {kClientFile},
|
||||
now - an_hour);
|
||||
|
||||
GetModifiedOrigins(kTemporary, then, base::Time::Max());
|
||||
GetModifiedStorageKeys(kTemporary, then, base::Time::Max());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(kTemporary, type());
|
||||
EXPECT_EQ(1UL, origins().size());
|
||||
EXPECT_EQ(1UL, origins().count(kOrigin1));
|
||||
EXPECT_EQ(0UL, origins().count(kOrigin2));
|
||||
EXPECT_EQ(1UL, storage_keys().size());
|
||||
EXPECT_EQ(1UL, storage_keys().count(kStorageKey1));
|
||||
EXPECT_EQ(0UL, storage_keys().count(kStorageKey2));
|
||||
|
||||
manager()->AddOrigin(kOrigin2, kTemporary, {kClientFile}, now);
|
||||
manager()->AddStorageKey(kStorageKey2, kTemporary, {kClientFile}, now);
|
||||
|
||||
GetModifiedOrigins(kTemporary, then, base::Time::Max());
|
||||
GetModifiedStorageKeys(kTemporary, then, base::Time::Max());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(kTemporary, type());
|
||||
EXPECT_EQ(2UL, origins().size());
|
||||
EXPECT_EQ(1UL, origins().count(kOrigin1));
|
||||
EXPECT_EQ(1UL, origins().count(kOrigin2));
|
||||
EXPECT_EQ(2UL, storage_keys().size());
|
||||
EXPECT_EQ(1UL, storage_keys().count(kStorageKey1));
|
||||
EXPECT_EQ(1UL, storage_keys().count(kStorageKey2));
|
||||
|
||||
GetModifiedOrigins(kTemporary, then, now);
|
||||
GetModifiedStorageKeys(kTemporary, then, now);
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(kTemporary, type());
|
||||
EXPECT_EQ(1UL, origins().size());
|
||||
EXPECT_EQ(1UL, origins().count(kOrigin1));
|
||||
EXPECT_EQ(0UL, origins().count(kOrigin2));
|
||||
EXPECT_EQ(1UL, storage_keys().size());
|
||||
EXPECT_EQ(1UL, storage_keys().count(kStorageKey1));
|
||||
EXPECT_EQ(0UL, storage_keys().count(kStorageKey2));
|
||||
|
||||
GetModifiedOrigins(kTemporary, now - a_minute, now + a_minute);
|
||||
GetModifiedStorageKeys(kTemporary, now - a_minute, now + a_minute);
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(kTemporary, type());
|
||||
EXPECT_EQ(1UL, origins().size());
|
||||
EXPECT_EQ(0UL, origins().count(kOrigin1));
|
||||
EXPECT_EQ(1UL, origins().count(kOrigin2));
|
||||
EXPECT_EQ(1UL, storage_keys().size());
|
||||
EXPECT_EQ(0UL, storage_keys().count(kStorageKey1));
|
||||
EXPECT_EQ(1UL, storage_keys().count(kStorageKey2));
|
||||
}
|
||||
} // namespace storage
|
||||
|
Reference in New Issue
Block a user