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 "webkit/browser/quota/quota_manager_proxy.h" | 5 #include "storage/browser/quota/quota_manager_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 | 14 |
15 namespace quota { | 15 namespace quota { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 void DidGetUsageAndQuota( | 19 void DidGetUsageAndQuota( |
20 base::SequencedTaskRunner* original_task_runner, | 20 base::SequencedTaskRunner* original_task_runner, |
21 const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, | 21 const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, |
22 QuotaStatusCode status, int64 usage, int64 quota) { | 22 QuotaStatusCode status, |
| 23 int64 usage, |
| 24 int64 quota) { |
23 if (!original_task_runner->RunsTasksOnCurrentThread()) { | 25 if (!original_task_runner->RunsTasksOnCurrentThread()) { |
24 original_task_runner->PostTask( | 26 original_task_runner->PostTask( |
25 FROM_HERE, | 27 FROM_HERE, |
26 base::Bind(&DidGetUsageAndQuota, | 28 base::Bind(&DidGetUsageAndQuota, |
27 make_scoped_refptr(original_task_runner), | 29 make_scoped_refptr(original_task_runner), |
28 callback, status, usage, quota)); | 30 callback, |
| 31 status, |
| 32 usage, |
| 33 quota)); |
29 return; | 34 return; |
30 } | 35 } |
31 callback.Run(status, usage, quota); | 36 callback.Run(status, usage, quota); |
32 } | 37 } |
33 | 38 |
34 } // namespace | 39 } // namespace |
35 | 40 |
36 void QuotaManagerProxy::RegisterClient(QuotaClient* client) { | 41 void QuotaManagerProxy::RegisterClient(QuotaClient* client) { |
37 if (!io_thread_->BelongsToCurrentThread() && | 42 if (!io_thread_->BelongsToCurrentThread() && |
38 io_thread_->PostTask( | 43 io_thread_->PostTask( |
39 FROM_HERE, | 44 FROM_HERE, |
40 base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) { | 45 base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) { |
41 return; | 46 return; |
42 } | 47 } |
43 | 48 |
44 if (manager_) | 49 if (manager_) |
45 manager_->RegisterClient(client); | 50 manager_->RegisterClient(client); |
46 else | 51 else |
47 client->OnQuotaManagerDestroyed(); | 52 client->OnQuotaManagerDestroyed(); |
48 } | 53 } |
49 | 54 |
50 void QuotaManagerProxy::NotifyStorageAccessed( | 55 void QuotaManagerProxy::NotifyStorageAccessed(QuotaClient::ID client_id, |
51 QuotaClient::ID client_id, | 56 const GURL& origin, |
52 const GURL& origin, | 57 StorageType type) { |
53 StorageType type) { | |
54 if (!io_thread_->BelongsToCurrentThread()) { | 58 if (!io_thread_->BelongsToCurrentThread()) { |
55 io_thread_->PostTask( | 59 io_thread_->PostTask(FROM_HERE, |
56 FROM_HERE, | 60 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, |
57 base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id, | 61 this, |
58 origin, type)); | 62 client_id, |
| 63 origin, |
| 64 type)); |
59 return; | 65 return; |
60 } | 66 } |
61 | 67 |
62 if (manager_) | 68 if (manager_) |
63 manager_->NotifyStorageAccessed(client_id, origin, type); | 69 manager_->NotifyStorageAccessed(client_id, origin, type); |
64 } | 70 } |
65 | 71 |
66 void QuotaManagerProxy::NotifyStorageModified( | 72 void QuotaManagerProxy::NotifyStorageModified(QuotaClient::ID client_id, |
67 QuotaClient::ID client_id, | 73 const GURL& origin, |
68 const GURL& origin, | 74 StorageType type, |
69 StorageType type, | 75 int64 delta) { |
70 int64 delta) { | |
71 if (!io_thread_->BelongsToCurrentThread()) { | 76 if (!io_thread_->BelongsToCurrentThread()) { |
72 io_thread_->PostTask( | 77 io_thread_->PostTask(FROM_HERE, |
73 FROM_HERE, | 78 base::Bind(&QuotaManagerProxy::NotifyStorageModified, |
74 base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id, | 79 this, |
75 origin, type, delta)); | 80 client_id, |
| 81 origin, |
| 82 type, |
| 83 delta)); |
76 return; | 84 return; |
77 } | 85 } |
78 | 86 |
79 if (manager_) | 87 if (manager_) |
80 manager_->NotifyStorageModified(client_id, origin, type, delta); | 88 manager_->NotifyStorageModified(client_id, origin, type, delta); |
81 } | 89 } |
82 | 90 |
83 void QuotaManagerProxy::NotifyOriginInUse( | 91 void QuotaManagerProxy::NotifyOriginInUse(const GURL& origin) { |
84 const GURL& origin) { | |
85 if (!io_thread_->BelongsToCurrentThread()) { | 92 if (!io_thread_->BelongsToCurrentThread()) { |
86 io_thread_->PostTask( | 93 io_thread_->PostTask( |
87 FROM_HERE, | 94 FROM_HERE, |
88 base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin)); | 95 base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin)); |
89 return; | 96 return; |
90 } | 97 } |
91 | 98 |
92 if (manager_) | 99 if (manager_) |
93 manager_->NotifyOriginInUse(origin); | 100 manager_->NotifyOriginInUse(origin); |
94 } | 101 } |
95 | 102 |
96 void QuotaManagerProxy::NotifyOriginNoLongerInUse( | 103 void QuotaManagerProxy::NotifyOriginNoLongerInUse(const GURL& origin) { |
97 const GURL& origin) { | |
98 if (!io_thread_->BelongsToCurrentThread()) { | 104 if (!io_thread_->BelongsToCurrentThread()) { |
99 io_thread_->PostTask( | 105 io_thread_->PostTask( |
100 FROM_HERE, | 106 FROM_HERE, |
101 base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this, | 107 base::Bind( |
102 origin)); | 108 &QuotaManagerProxy::NotifyOriginNoLongerInUse, this, origin)); |
103 return; | 109 return; |
104 } | 110 } |
105 if (manager_) | 111 if (manager_) |
106 manager_->NotifyOriginNoLongerInUse(origin); | 112 manager_->NotifyOriginNoLongerInUse(origin); |
107 } | 113 } |
108 | 114 |
109 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id, | 115 void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id, |
110 const GURL& origin, | 116 const GURL& origin, |
111 StorageType type, | 117 StorageType type, |
112 bool enabled) { | 118 bool enabled) { |
113 if (!io_thread_->BelongsToCurrentThread()) { | 119 if (!io_thread_->BelongsToCurrentThread()) { |
114 io_thread_->PostTask( | 120 io_thread_->PostTask(FROM_HERE, |
115 FROM_HERE, | 121 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, |
116 base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, | 122 this, |
117 client_id, origin, type, enabled)); | 123 client_id, |
| 124 origin, |
| 125 type, |
| 126 enabled)); |
118 return; | 127 return; |
119 } | 128 } |
120 if (manager_) | 129 if (manager_) |
121 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); | 130 manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); |
122 } | 131 } |
123 | 132 |
124 void QuotaManagerProxy::GetUsageAndQuota( | 133 void QuotaManagerProxy::GetUsageAndQuota( |
125 base::SequencedTaskRunner* original_task_runner, | 134 base::SequencedTaskRunner* original_task_runner, |
126 const GURL& origin, | 135 const GURL& origin, |
127 StorageType type, | 136 StorageType type, |
128 const GetUsageAndQuotaCallback& callback) { | 137 const GetUsageAndQuotaCallback& callback) { |
129 if (!io_thread_->BelongsToCurrentThread()) { | 138 if (!io_thread_->BelongsToCurrentThread()) { |
130 io_thread_->PostTask( | 139 io_thread_->PostTask(FROM_HERE, |
131 FROM_HERE, | 140 base::Bind(&QuotaManagerProxy::GetUsageAndQuota, |
132 base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, | 141 this, |
133 make_scoped_refptr(original_task_runner), | 142 make_scoped_refptr(original_task_runner), |
134 origin, type, callback)); | 143 origin, |
| 144 type, |
| 145 callback)); |
135 return; | 146 return; |
136 } | 147 } |
137 if (!manager_) { | 148 if (!manager_) { |
138 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); | 149 DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); |
139 return; | 150 return; |
140 } | 151 } |
141 manager_->GetUsageAndQuota( | 152 manager_->GetUsageAndQuota( |
142 origin, type, | 153 origin, |
| 154 type, |
143 base::Bind(&DidGetUsageAndQuota, | 155 base::Bind(&DidGetUsageAndQuota, |
144 make_scoped_refptr(original_task_runner), callback)); | 156 make_scoped_refptr(original_task_runner), |
| 157 callback)); |
145 } | 158 } |
146 | 159 |
147 QuotaManager* QuotaManagerProxy::quota_manager() const { | 160 QuotaManager* QuotaManagerProxy::quota_manager() const { |
148 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); | 161 DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); |
149 return manager_; | 162 return manager_; |
150 } | 163 } |
151 | 164 |
152 QuotaManagerProxy::QuotaManagerProxy( | 165 QuotaManagerProxy::QuotaManagerProxy(QuotaManager* manager, |
153 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) | 166 base::SingleThreadTaskRunner* io_thread) |
154 : manager_(manager), io_thread_(io_thread) { | 167 : manager_(manager), io_thread_(io_thread) { |
155 } | 168 } |
156 | 169 |
157 QuotaManagerProxy::~QuotaManagerProxy() { | 170 QuotaManagerProxy::~QuotaManagerProxy() { |
158 } | 171 } |
159 | 172 |
160 } // namespace quota | 173 } // namespace quota |
OLD | NEW |