Don't preload rarely seen large images
[chromium-blink-merge.git] / storage / browser / quota / quota_manager_proxy.cc
blobc8ccefc1ad230051422591af0953856a990e86c9
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"
7 #include "base/bind.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"
14 namespace storage {
16 namespace {
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(
24 FROM_HERE,
25 base::Bind(&DidGetUsageAndQuota,
26 make_scoped_refptr(original_task_runner),
27 callback, status, usage, quota));
28 return;
30 callback.Run(status, usage, quota);
33 } // namespace
35 void QuotaManagerProxy::RegisterClient(QuotaClient* client) {
36 if (!io_thread_->BelongsToCurrentThread() &&
37 io_thread_->PostTask(
38 FROM_HERE,
39 base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) {
40 return;
43 if (manager_)
44 manager_->RegisterClient(client);
45 else
46 client->OnQuotaManagerDestroyed();
49 void QuotaManagerProxy::NotifyStorageAccessed(
50 QuotaClient::ID client_id,
51 const GURL& origin,
52 StorageType type) {
53 if (!io_thread_->BelongsToCurrentThread()) {
54 io_thread_->PostTask(
55 FROM_HERE,
56 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id,
57 origin, type));
58 return;
61 if (manager_)
62 manager_->NotifyStorageAccessed(client_id, origin, type);
65 void QuotaManagerProxy::NotifyStorageModified(
66 QuotaClient::ID client_id,
67 const GURL& origin,
68 StorageType type,
69 int64 delta) {
70 if (!io_thread_->BelongsToCurrentThread()) {
71 io_thread_->PostTask(
72 FROM_HERE,
73 base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id,
74 origin, type, delta));
75 return;
78 if (manager_)
79 manager_->NotifyStorageModified(client_id, origin, type, delta);
82 void QuotaManagerProxy::NotifyOriginInUse(
83 const GURL& origin) {
84 if (!io_thread_->BelongsToCurrentThread()) {
85 io_thread_->PostTask(
86 FROM_HERE,
87 base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin));
88 return;
91 if (manager_)
92 manager_->NotifyOriginInUse(origin);
95 void QuotaManagerProxy::NotifyOriginNoLongerInUse(
96 const GURL& origin) {
97 if (!io_thread_->BelongsToCurrentThread()) {
98 io_thread_->PostTask(
99 FROM_HERE,
100 base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this,
101 origin));
102 return;
104 if (manager_)
105 manager_->NotifyOriginNoLongerInUse(origin);
108 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id,
109 const GURL& origin,
110 StorageType type,
111 bool enabled) {
112 if (!io_thread_->BelongsToCurrentThread()) {
113 io_thread_->PostTask(
114 FROM_HERE,
115 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this,
116 client_id, origin, type, enabled));
117 return;
119 if (manager_)
120 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled);
123 void QuotaManagerProxy::GetUsageAndQuota(
124 base::SequencedTaskRunner* original_task_runner,
125 const GURL& origin,
126 StorageType type,
127 const GetUsageAndQuotaCallback& callback) {
128 if (!io_thread_->BelongsToCurrentThread()) {
129 io_thread_->PostTask(
130 FROM_HERE,
131 base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this,
132 make_scoped_refptr(original_task_runner),
133 origin, type, callback));
134 return;
136 if (!manager_) {
137 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0);
138 return;
140 manager_->GetUsageAndQuota(
141 origin, type,
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());
148 return manager_;
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