1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "storage/browser/quota/quota_manager_proxy.h"
8 #include "base/bind_helpers.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/task_runner_util.h"
18 void DidGetUsageAndQuota(
19 base::SequencedTaskRunner
* original_task_runner
,
20 const QuotaManagerProxy::GetUsageAndQuotaCallback
& callback
,
21 QuotaStatusCode status
, int64 usage
, int64 quota
) {
22 if (!original_task_runner
->RunsTasksOnCurrentThread()) {
23 original_task_runner
->PostTask(
25 base::Bind(&DidGetUsageAndQuota
,
26 make_scoped_refptr(original_task_runner
),
27 callback
, status
, usage
, quota
));
30 callback
.Run(status
, usage
, quota
);
35 void QuotaManagerProxy::RegisterClient(QuotaClient
* client
) {
36 if (!io_thread_
->BelongsToCurrentThread() &&
39 base::Bind(&QuotaManagerProxy::RegisterClient
, this, client
))) {
44 manager_
->RegisterClient(client
);
46 client
->OnQuotaManagerDestroyed();
49 void QuotaManagerProxy::NotifyStorageAccessed(
50 QuotaClient::ID client_id
,
53 if (!io_thread_
->BelongsToCurrentThread()) {
56 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed
, this, client_id
,
62 manager_
->NotifyStorageAccessed(client_id
, origin
, type
);
65 void QuotaManagerProxy::NotifyStorageModified(
66 QuotaClient::ID client_id
,
70 if (!io_thread_
->BelongsToCurrentThread()) {
73 base::Bind(&QuotaManagerProxy::NotifyStorageModified
, this, client_id
,
74 origin
, type
, delta
));
79 manager_
->NotifyStorageModified(client_id
, origin
, type
, delta
);
82 void QuotaManagerProxy::NotifyOriginInUse(
84 if (!io_thread_
->BelongsToCurrentThread()) {
87 base::Bind(&QuotaManagerProxy::NotifyOriginInUse
, this, origin
));
92 manager_
->NotifyOriginInUse(origin
);
95 void QuotaManagerProxy::NotifyOriginNoLongerInUse(
97 if (!io_thread_
->BelongsToCurrentThread()) {
100 base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse
, this,
105 manager_
->NotifyOriginNoLongerInUse(origin
);
108 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id
,
112 if (!io_thread_
->BelongsToCurrentThread()) {
113 io_thread_
->PostTask(
115 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled
, this,
116 client_id
, origin
, type
, enabled
));
120 manager_
->SetUsageCacheEnabled(client_id
, origin
, type
, enabled
);
123 void QuotaManagerProxy::GetUsageAndQuota(
124 base::SequencedTaskRunner
* original_task_runner
,
127 const GetUsageAndQuotaCallback
& callback
) {
128 if (!io_thread_
->BelongsToCurrentThread()) {
129 io_thread_
->PostTask(
131 base::Bind(&QuotaManagerProxy::GetUsageAndQuota
, this,
132 make_scoped_refptr(original_task_runner
),
133 origin
, type
, callback
));
137 DidGetUsageAndQuota(original_task_runner
, callback
, kQuotaErrorAbort
, 0, 0);
140 manager_
->GetUsageAndQuota(
142 base::Bind(&DidGetUsageAndQuota
,
143 make_scoped_refptr(original_task_runner
), callback
));
146 QuotaManager
* QuotaManagerProxy::quota_manager() const {
147 DCHECK(!io_thread_
.get() || io_thread_
->BelongsToCurrentThread());
151 QuotaManagerProxy::QuotaManagerProxy(
152 QuotaManager
* manager
,
153 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_thread
)
154 : manager_(manager
), io_thread_(io_thread
) {
157 QuotaManagerProxy::~QuotaManagerProxy() {
160 } // namespace storage