1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include <utility>
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.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 {
MockQuotaManagerProxy::MockQuotaManagerProxy(
MockQuotaManager* quota_manager,
scoped_refptr<base::SequencedTaskRunner> quota_manager_task_runner)
: QuotaManagerProxy(
quota_manager,
std::move(quota_manager_task_runner),
quota_manager ? quota_manager->profile_path() : base::FilePath()),
mock_quota_manager_(quota_manager) {}
void MockQuotaManagerProxy::UpdateOrCreateBucket(
const BucketInitParams& params,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback) {
if (mock_quota_manager_) {
mock_quota_manager_->UpdateOrCreateBucket(params, std::move(callback));
}
}
QuotaErrorOr<BucketInfo> MockQuotaManagerProxy::GetOrCreateBucketSync(
const BucketInitParams& params) {
return (mock_quota_manager_)
? mock_quota_manager_->GetOrCreateBucketSync(params)
: base::unexpected(QuotaError::kUnknownError);
}
void MockQuotaManagerProxy::CreateBucketForTesting(
const blink::StorageKey& storage_key,
const std::string& bucket_name,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback) {
if (mock_quota_manager_) {
mock_quota_manager_->CreateBucketForTesting(storage_key, bucket_name,
std::move(callback));
}
}
void MockQuotaManagerProxy::GetBucketByNameUnsafe(
const blink::StorageKey& storage_key,
const std::string& bucket_name,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback) {
if (mock_quota_manager_) {
mock_quota_manager_->GetBucketByNameUnsafe(storage_key, bucket_name,
std::move(callback));
}
}
void MockQuotaManagerProxy::GetBucketById(
const BucketId& bucket_id,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback) {
if (mock_quota_manager_) {
mock_quota_manager_->GetBucketById(bucket_id, std::move(callback));
}
}
void MockQuotaManagerProxy::GetBucketsForStorageKey(
const blink::StorageKey& storage_key,
bool delete_expired,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceCallback<void(QuotaErrorOr<std::set<BucketInfo>>)> callback) {
if (mock_quota_manager_) {
mock_quota_manager_->GetBucketsForStorageKey(
storage_key, std::move(callback), delete_expired);
} else {
std::move(callback).Run(std::set<BucketInfo>());
}
}
void MockQuotaManagerProxy::GetUsageAndQuota(
const blink::StorageKey& storage_key,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
QuotaManager::UsageAndQuotaCallback callback) {
if (mock_quota_manager_) {
mock_quota_manager_->GetUsageAndQuota(storage_key,
std::move(callback));
}
}
void MockQuotaManagerProxy::NotifyBucketAccessed(const BucketLocator& bucket,
base::Time access_time) {
base::AutoLock locked(lock_);
++bucket_accessed_count_;
last_notified_bucket_id_ = bucket.id;
last_notified_storage_key_ = bucket.storage_key;
}
void MockQuotaManagerProxy::NotifyBucketModified(
QuotaClientType client_id,
const BucketLocator& bucket,
std::optional<int64_t> delta,
base::Time modification_time,
scoped_refptr<base::SequencedTaskRunner> callback_task_runner,
base::OnceClosure callback) {
base::AutoLock locked(lock_);
++bucket_modified_count_;
last_notified_bucket_id_ = bucket.id;
last_notified_bucket_delta_ = delta;
if (mock_quota_manager_) {
mock_quota_manager_->UpdateUsage(bucket, delta);
}
if (callback) {
callback_task_runner->PostTask(FROM_HERE, std::move(callback));
}
}
MockQuotaManagerProxy::~MockQuotaManagerProxy() = default;
} // namespace storage
|