OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "storage/browser/quota/quota_manager_proxy.h" | 5 #include "storage/browser/quota/quota_manager_proxy.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 | 16 |
17 namespace storage { | 17 namespace storage { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void DidGetUsageAndQuota( | 21 void DidGetUsageAndQuota( |
22 base::SequencedTaskRunner* original_task_runner, | 22 base::SequencedTaskRunner* original_task_runner, |
23 const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, | 23 const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, |
24 QuotaStatusCode status, | 24 QuotaStatusCode status, |
25 int64_t usage, | 25 int64_t usage, |
26 int64_t quota) { | 26 int64_t quota) { |
27 if (!original_task_runner->RunsTasksOnCurrentThread()) { | 27 if (!original_task_runner->RunsTasksOnCurrentThread()) { |
28 original_task_runner->PostTask( | 28 original_task_runner->PostTask( |
29 FROM_HERE, | 29 FROM_HERE, base::Bind(&DidGetUsageAndQuota, |
30 base::Bind(&DidGetUsageAndQuota, | 30 base::RetainedRef(original_task_runner), callback, |
31 make_scoped_refptr(original_task_runner), | 31 status, usage, quota)); |
32 callback, status, usage, quota)); | |
33 return; | 32 return; |
34 } | 33 } |
35 | 34 |
36 // crbug.com/349708 | 35 // crbug.com/349708 |
37 TRACE_EVENT0("io", "QuotaManagerProxy DidGetUsageAndQuota"); | 36 TRACE_EVENT0("io", "QuotaManagerProxy DidGetUsageAndQuota"); |
38 callback.Run(status, usage, quota); | 37 callback.Run(status, usage, quota); |
39 } | 38 } |
40 | 39 |
41 } // namespace | 40 } // namespace |
42 | 41 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); | 126 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); |
128 } | 127 } |
129 | 128 |
130 void QuotaManagerProxy::GetUsageAndQuota( | 129 void QuotaManagerProxy::GetUsageAndQuota( |
131 base::SequencedTaskRunner* original_task_runner, | 130 base::SequencedTaskRunner* original_task_runner, |
132 const GURL& origin, | 131 const GURL& origin, |
133 StorageType type, | 132 StorageType type, |
134 const GetUsageAndQuotaCallback& callback) { | 133 const GetUsageAndQuotaCallback& callback) { |
135 if (!io_thread_->BelongsToCurrentThread()) { | 134 if (!io_thread_->BelongsToCurrentThread()) { |
136 io_thread_->PostTask( | 135 io_thread_->PostTask( |
137 FROM_HERE, | 136 FROM_HERE, base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, |
138 base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, | 137 base::RetainedRef(original_task_runner), origin, |
139 make_scoped_refptr(original_task_runner), | 138 type, callback)); |
140 origin, type, callback)); | |
141 return; | 139 return; |
142 } | 140 } |
143 if (!manager_) { | 141 if (!manager_) { |
144 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); | 142 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); |
145 return; | 143 return; |
146 } | 144 } |
147 | 145 |
148 // crbug.com/349708 | 146 // crbug.com/349708 |
149 TRACE_EVENT0("io", "QuotaManagerProxy::GetUsageAndQuota"); | 147 TRACE_EVENT0("io", "QuotaManagerProxy::GetUsageAndQuota"); |
150 | 148 |
151 manager_->GetUsageAndQuota( | 149 manager_->GetUsageAndQuota( |
152 origin, type, | 150 origin, type, |
153 base::Bind(&DidGetUsageAndQuota, | 151 base::Bind(&DidGetUsageAndQuota, base::RetainedRef(original_task_runner), |
154 make_scoped_refptr(original_task_runner), callback)); | 152 callback)); |
155 } | 153 } |
156 | 154 |
157 QuotaManager* QuotaManagerProxy::quota_manager() const { | 155 QuotaManager* QuotaManagerProxy::quota_manager() const { |
158 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); | 156 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); |
159 return manager_; | 157 return manager_; |
160 } | 158 } |
161 | 159 |
162 QuotaManagerProxy::QuotaManagerProxy( | 160 QuotaManagerProxy::QuotaManagerProxy( |
163 QuotaManager* manager, | 161 QuotaManager* manager, |
164 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread) | 162 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread) |
165 : manager_(manager), io_thread_(io_thread) { | 163 : manager_(manager), io_thread_(io_thread) { |
166 } | 164 } |
167 | 165 |
168 QuotaManagerProxy::~QuotaManagerProxy() { | 166 QuotaManagerProxy::~QuotaManagerProxy() { |
169 } | 167 } |
170 | 168 |
171 } // namespace storage | 169 } // namespace storage |
OLD | NEW |