OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fileapi/sandbox_quota_client.h" | 5 #include "webkit/fileapi/sandbox_quota_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 virtual void Completed() OVERRIDE { | 178 virtual void Completed() OVERRIDE { |
179 quota_client()->DidGetOriginsForHost(std::make_pair(type(), host_), | 179 quota_client()->DidGetOriginsForHost(std::make_pair(type(), host_), |
180 origins()); | 180 origins()); |
181 } | 181 } |
182 | 182 |
183 private: | 183 private: |
184 std::string host_; | 184 std::string host_; |
185 }; | 185 }; |
186 | 186 |
| 187 class SandboxQuotaClient::DeleteOriginTask |
| 188 : public QuotaThreadTask { |
| 189 public: |
| 190 DeleteOriginTask( |
| 191 SandboxQuotaClient* quota_client, |
| 192 scoped_refptr<MessageLoopProxy> file_message_loop, |
| 193 const GURL& origin, |
| 194 FileSystemType type, |
| 195 DeletionCallback* callback) |
| 196 : QuotaThreadTask(quota_client, file_message_loop), |
| 197 file_system_context_(quota_client->file_system_context_), |
| 198 origin_(origin), |
| 199 type_(type), |
| 200 status_(quota::kQuotaStatusUnknown), |
| 201 callback_(callback) { |
| 202 } |
| 203 |
| 204 virtual ~DeleteOriginTask() {} |
| 205 |
| 206 virtual void RunOnTargetThread() OVERRIDE { |
| 207 if (file_system_context_-> |
| 208 DeleteDataForOriginAndTypeOnFileThread(origin_, type_)) |
| 209 status_ = quota::kQuotaStatusOk; |
| 210 else |
| 211 status_ = quota::kQuotaErrorInvalidModification; |
| 212 } |
| 213 |
| 214 virtual void Completed() OVERRIDE { |
| 215 callback_->Run(status_); |
| 216 } |
| 217 private: |
| 218 FileSystemContext* file_system_context_; |
| 219 GURL origin_; |
| 220 FileSystemType type_; |
| 221 quota::QuotaStatusCode status_; |
| 222 scoped_ptr<DeletionCallback> callback_; |
| 223 }; |
| 224 |
187 SandboxQuotaClient::SandboxQuotaClient( | 225 SandboxQuotaClient::SandboxQuotaClient( |
188 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 226 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
189 FileSystemContext* file_system_context, | 227 FileSystemContext* file_system_context, |
190 bool is_incognito) | 228 bool is_incognito) |
191 : file_message_loop_(file_message_loop), | 229 : file_message_loop_(file_message_loop), |
192 file_system_context_(file_system_context), | 230 file_system_context_(file_system_context), |
193 is_incognito_(is_incognito) { | 231 is_incognito_(is_incognito) { |
194 DCHECK(file_message_loop); | 232 DCHECK(file_message_loop); |
195 } | 233 } |
196 | 234 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 297 |
260 if (pending_origins_for_host_callbacks_.Add( | 298 if (pending_origins_for_host_callbacks_.Add( |
261 std::make_pair(type, host), callback.release())) { | 299 std::make_pair(type, host), callback.release())) { |
262 scoped_refptr<GetOriginsForHostTask> task( | 300 scoped_refptr<GetOriginsForHostTask> task( |
263 new GetOriginsForHostTask(this, file_message_loop_, | 301 new GetOriginsForHostTask(this, file_message_loop_, |
264 type, host)); | 302 type, host)); |
265 task->Start(); | 303 task->Start(); |
266 } | 304 } |
267 } | 305 } |
268 | 306 |
| 307 void SandboxQuotaClient::DeleteOriginData(const GURL& origin, |
| 308 StorageType type, |
| 309 DeletionCallback* callback) { |
| 310 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
| 311 DCHECK(fs_type != kFileSystemTypeUnknown); |
| 312 scoped_refptr<DeleteOriginTask> task( |
| 313 new DeleteOriginTask(this, file_message_loop_, |
| 314 origin, fs_type, callback)); |
| 315 task->Start(); |
| 316 } |
| 317 |
269 void SandboxQuotaClient::DidGetOriginUsage( | 318 void SandboxQuotaClient::DidGetOriginUsage( |
270 FileSystemType type, const GURL& origin_url, int64 usage) { | 319 FileSystemType type, const GURL& origin_url, int64 usage) { |
271 visited_origins_.insert(origin_url); | 320 visited_origins_.insert(origin_url); |
272 TypeAndHostOrOrigin type_and_origin(std::make_pair( | 321 TypeAndHostOrOrigin type_and_origin(std::make_pair( |
273 type, origin_url.spec())); | 322 type, origin_url.spec())); |
274 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); | 323 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); |
275 pending_usage_callbacks_.Run(type_and_origin, usage); | 324 pending_usage_callbacks_.Run(type_and_origin, usage); |
276 } | 325 } |
277 | 326 |
278 void SandboxQuotaClient::DidGetOriginsForType( | 327 void SandboxQuotaClient::DidGetOriginsForType( |
279 FileSystemType type, const std::set<GURL>& origins) { | 328 FileSystemType type, const std::set<GURL>& origins) { |
280 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); | 329 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); |
281 pending_origins_for_type_callbacks_.Run(type, origins); | 330 pending_origins_for_type_callbacks_.Run(type, origins); |
282 } | 331 } |
283 | 332 |
284 void SandboxQuotaClient::DidGetOriginsForHost( | 333 void SandboxQuotaClient::DidGetOriginsForHost( |
285 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { | 334 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { |
286 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); | 335 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); |
287 pending_origins_for_host_callbacks_.Run(type_and_host, origins); | 336 pending_origins_for_host_callbacks_.Run(type_and_host, origins); |
288 } | 337 } |
289 | 338 |
290 } // namespace fileapi | 339 } // namespace fileapi |
OLD | NEW |