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/callback.h"
10 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/task_runner_util.h"
19 void DidGetUsageAndQuota(
20 base::SequencedTaskRunner
* original_task_runner
,
21 const QuotaManagerProxy::GetUsageAndQuotaCallback
& callback
,
22 QuotaStatusCode status
, int64 usage
, int64 quota
) {
23 if (!original_task_runner
->RunsTasksOnCurrentThread()) {
24 original_task_runner
->PostTask(
26 base::Bind(&DidGetUsageAndQuota
,
27 make_scoped_refptr(original_task_runner
),
28 callback
, status
, usage
, quota
));
31 callback
.Run(status
, usage
, quota
);
36 void QuotaManagerProxy::RegisterClient(QuotaClient
* client
) {
37 if (!io_thread_
->BelongsToCurrentThread() &&
40 base::Bind(&QuotaManagerProxy::RegisterClient
, this, client
))) {
45 manager_
->RegisterClient(client
);
47 client
->OnQuotaManagerDestroyed();
50 void QuotaManagerProxy::NotifyStorageAccessed(
51 QuotaClient::ID client_id
,
54 if (!io_thread_
->BelongsToCurrentThread()) {
57 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed
, this, client_id
,
63 manager_
->NotifyStorageAccessed(client_id
, origin
, type
);
66 void QuotaManagerProxy::NotifyStorageModified(
67 QuotaClient::ID client_id
,
71 if (!io_thread_
->BelongsToCurrentThread()) {
74 base::Bind(&QuotaManagerProxy::NotifyStorageModified
, this, client_id
,
75 origin
, type
, delta
));
80 manager_
->NotifyStorageModified(client_id
, origin
, type
, delta
);
83 void QuotaManagerProxy::NotifyOriginInUse(
85 if (!io_thread_
->BelongsToCurrentThread()) {
88 base::Bind(&QuotaManagerProxy::NotifyOriginInUse
, this, origin
));
93 manager_
->NotifyOriginInUse(origin
);
96 void QuotaManagerProxy::NotifyOriginNoLongerInUse(
98 if (!io_thread_
->BelongsToCurrentThread()) {
101 base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse
, this,
106 manager_
->NotifyOriginNoLongerInUse(origin
);
109 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id
,
113 if (!io_thread_
->BelongsToCurrentThread()) {
114 io_thread_
->PostTask(
116 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled
, this,
117 client_id
, origin
, type
, enabled
));
121 manager_
->SetUsageCacheEnabled(client_id
, origin
, type
, enabled
);
124 void QuotaManagerProxy::GetUsageAndQuota(
125 base::SequencedTaskRunner
* original_task_runner
,
128 const GetUsageAndQuotaCallback
& callback
) {
129 if (!io_thread_
->BelongsToCurrentThread()) {
130 io_thread_
->PostTask(
132 base::Bind(&QuotaManagerProxy::GetUsageAndQuota
, this,
133 make_scoped_refptr(original_task_runner
),
134 origin
, type
, callback
));
138 DidGetUsageAndQuota(original_task_runner
, callback
, kQuotaErrorAbort
, 0, 0);
141 manager_
->GetUsageAndQuota(
143 base::Bind(&DidGetUsageAndQuota
,
144 make_scoped_refptr(original_task_runner
), callback
));
147 QuotaManager
* QuotaManagerProxy::quota_manager() const {
148 DCHECK(!io_thread_
.get() || io_thread_
->BelongsToCurrentThread());
152 QuotaManagerProxy::QuotaManagerProxy(
153 QuotaManager
* manager
,
154 const scoped_refptr
<base::SingleThreadTaskRunner
>& io_thread
)
155 : manager_(manager
), io_thread_(io_thread
) {
158 QuotaManagerProxy::~QuotaManagerProxy() {
161 } // namespace storage