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 "content/browser/in_process_webkit/indexed_db_quota_client.h" | 5 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 IndexedDBQuotaClient* client, | 24 IndexedDBQuotaClient* client, |
25 base::MessageLoopProxy* webkit_thread_message_loop) | 25 base::MessageLoopProxy* webkit_thread_message_loop) |
26 : QuotaThreadTask(client, webkit_thread_message_loop), | 26 : QuotaThreadTask(client, webkit_thread_message_loop), |
27 client_(client), indexed_db_context_(client->indexed_db_context_) { | 27 client_(client), indexed_db_context_(client->indexed_db_context_) { |
28 } | 28 } |
29 | 29 |
30 IndexedDBQuotaClient* client_; | 30 IndexedDBQuotaClient* client_; |
31 scoped_refptr<IndexedDBContext> indexed_db_context_; | 31 scoped_refptr<IndexedDBContext> indexed_db_context_; |
32 }; | 32 }; |
33 | 33 |
34 class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { | |
35 public: | |
36 DeleteOriginTask(IndexedDBQuotaClient* client, | |
37 base::MessageLoopProxy* webkit_thread_message_loop, | |
38 const GURL& origin_url, | |
39 DeletionCallback* callback) | |
40 : HelperTask(client, webkit_thread_message_loop), | |
41 origin_url_(origin_url), callback_(callback) { | |
42 } | |
43 private: | |
44 virtual void RunOnTargetThread() OVERRIDE { | |
45 indexed_db_context_->EvictOriginIfNotInUse(origin_url_); | |
46 } | |
47 virtual void Completed() OVERRIDE { | |
48 callback_->Run(quota::kQuotaStatusOk); | |
49 } | |
50 GURL origin_url_; | |
51 scoped_ptr<DeletionCallback> callback_; | |
michaeln
2011/08/03 03:40:40
It would be good to ensure that this callback obje
dgrogan
2011/08/03 21:45:47
Done.
| |
52 }; | |
53 | |
34 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { | 54 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { |
35 public: | 55 public: |
36 GetOriginUsageTask( | 56 GetOriginUsageTask( |
37 IndexedDBQuotaClient* client, | 57 IndexedDBQuotaClient* client, |
38 base::MessageLoopProxy* webkit_thread_message_loop, | 58 base::MessageLoopProxy* webkit_thread_message_loop, |
39 const GURL& origin_url) | 59 const GURL& origin_url) |
40 : HelperTask(client, webkit_thread_message_loop), | 60 : HelperTask(client, webkit_thread_message_loop), |
41 origin_url_(origin_url), usage_(0) { | 61 origin_url_(origin_url), usage_(0) { |
42 } | 62 } |
43 | 63 |
44 private: | 64 private: |
45 virtual void RunOnTargetThread() OVERRIDE { | 65 virtual void RunOnTargetThread() OVERRIDE { |
46 string16 origin_id = DatabaseUtil::GetOriginIdentifier(origin_url_); | 66 usage_ = indexed_db_context_->InitializeDiskUsage(origin_url_); |
47 FilePath file_path = indexed_db_context_->GetIndexedDBFilePath(origin_id); | |
48 usage_ = 0; | |
49 usage_ = file_util::ComputeDirectorySize(file_path); | |
50 } | 67 } |
51 virtual void Completed() OVERRIDE { | 68 virtual void Completed() OVERRIDE { |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
52 client_->DidGetOriginUsage(origin_url_, usage_); | 70 client_->DidGetOriginUsage(origin_url_, usage_); |
53 } | 71 } |
54 GURL origin_url_; | 72 GURL origin_url_; |
55 int64 usage_; | 73 int64 usage_; |
56 }; | 74 }; |
57 | 75 |
58 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { | 76 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { |
59 protected: | 77 protected: |
60 GetOriginsTaskBase( | 78 GetOriginsTaskBase( |
61 IndexedDBQuotaClient* client, | 79 IndexedDBQuotaClient* client, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 if (origins_for_host_callbacks_.Add(host, callback.release())) { | 213 if (origins_for_host_callbacks_.Add(host, callback.release())) { |
196 scoped_refptr<GetOriginsForHostTask> task( | 214 scoped_refptr<GetOriginsForHostTask> task( |
197 new GetOriginsForHostTask(this, webkit_thread_message_loop_, host)); | 215 new GetOriginsForHostTask(this, webkit_thread_message_loop_, host)); |
198 task->Start(); | 216 task->Start(); |
199 } | 217 } |
200 } | 218 } |
201 | 219 |
202 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, | 220 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, |
203 quota::StorageType type, | 221 quota::StorageType type, |
204 DeletionCallback* callback) { | 222 DeletionCallback* callback) { |
205 // TODO(tzik): implement me | 223 if (type != quota::kStorageTypeTemporary) { |
206 callback->Run(quota::kQuotaErrorNotSupported); | 224 callback->Run(quota::kQuotaErrorNotSupported); |
207 delete callback; | 225 return; |
226 } | |
227 scoped_refptr<DeleteOriginTask> task( | |
228 new DeleteOriginTask(this, | |
229 webkit_thread_message_loop_, | |
230 origin, | |
231 callback)); | |
232 task->Start(); | |
208 } | 233 } |
209 | 234 |
210 void IndexedDBQuotaClient::DidGetOriginUsage( | 235 void IndexedDBQuotaClient::DidGetOriginUsage( |
211 const GURL& origin_url, int64 usage) { | 236 const GURL& origin_url, int64 usage) { |
212 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); | 237 DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url)); |
213 usage_for_origin_callbacks_.Run(origin_url, usage); | 238 usage_for_origin_callbacks_.Run(origin_url, usage); |
214 } | 239 } |
215 | 240 |
216 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) { | 241 void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) { |
217 DCHECK(origins_for_type_callbacks_.HasCallbacks()); | 242 DCHECK(origins_for_type_callbacks_.HasCallbacks()); |
218 origins_for_type_callbacks_.Run(origins); | 243 origins_for_type_callbacks_.Run(origins); |
219 } | 244 } |
220 | 245 |
221 void IndexedDBQuotaClient::DidGetOriginsForHost( | 246 void IndexedDBQuotaClient::DidGetOriginsForHost( |
222 const std::string& host, const std::set<GURL>& origins) { | 247 const std::string& host, const std::set<GURL>& origins) { |
223 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); | 248 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); |
224 origins_for_host_callbacks_.Run(host, origins); | 249 origins_for_host_callbacks_.Run(host, origins); |
225 } | 250 } |
OLD | NEW |