OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_system_quota_client.h" | 5 #include "webkit/fileapi/file_system_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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop_proxy.h" | 14 #include "base/task_runner.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
18 #include "webkit/fileapi/file_system_quota_util.h" | 18 #include "webkit/fileapi/file_system_quota_util.h" |
19 #include "webkit/fileapi/file_system_usage_cache.h" | 19 #include "webkit/fileapi/file_system_usage_cache.h" |
20 #include "webkit/fileapi/file_system_util.h" | 20 #include "webkit/fileapi/file_system_util.h" |
21 | 21 |
22 using base::MessageLoopProxy; | 22 using base::TaskRunner; |
23 using quota::QuotaThreadTask; | 23 using quota::QuotaThreadTask; |
24 using quota::StorageType; | 24 using quota::StorageType; |
25 | 25 |
26 namespace fileapi { | 26 namespace fileapi { |
27 | 27 |
28 class FileSystemQuotaClient::GetOriginUsageTask : public QuotaThreadTask { | 28 class FileSystemQuotaClient::GetOriginUsageTask : public QuotaThreadTask { |
29 public: | 29 public: |
30 GetOriginUsageTask( | 30 GetOriginUsageTask( |
31 FileSystemQuotaClient* quota_client, | 31 FileSystemQuotaClient* quota_client, |
32 scoped_refptr<MessageLoopProxy> file_message_loop, | 32 TaskRunner* file_task_runner, |
33 const GURL& origin_url, | 33 const GURL& origin_url, |
34 FileSystemType type) | 34 FileSystemType type) |
35 : QuotaThreadTask(quota_client, file_message_loop), | 35 : QuotaThreadTask(quota_client, file_task_runner), |
36 quota_client_(quota_client), | 36 quota_client_(quota_client), |
37 origin_url_(origin_url), | 37 origin_url_(origin_url), |
38 type_(type), | 38 type_(type), |
39 fs_usage_(0) { | 39 fs_usage_(0) { |
40 DCHECK(quota_client_); | 40 DCHECK(quota_client_); |
41 file_system_context_ = quota_client_->file_system_context_; | 41 file_system_context_ = quota_client_->file_system_context_; |
42 } | 42 } |
43 | 43 |
44 virtual ~GetOriginUsageTask() {} | 44 virtual ~GetOriginUsageTask() {} |
45 | 45 |
(...skipping 12 matching lines...) Expand all Loading... |
58 scoped_refptr<FileSystemContext> file_system_context_; | 58 scoped_refptr<FileSystemContext> file_system_context_; |
59 GURL origin_url_; | 59 GURL origin_url_; |
60 FileSystemType type_; | 60 FileSystemType type_; |
61 int64 fs_usage_; | 61 int64 fs_usage_; |
62 }; | 62 }; |
63 | 63 |
64 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { | 64 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { |
65 public: | 65 public: |
66 GetOriginsForTypeTask( | 66 GetOriginsForTypeTask( |
67 FileSystemQuotaClient* quota_client, | 67 FileSystemQuotaClient* quota_client, |
68 scoped_refptr<MessageLoopProxy> file_message_loop, | 68 TaskRunner* file_task_runner, |
69 FileSystemType type) | 69 FileSystemType type) |
70 : QuotaThreadTask(quota_client, file_message_loop), | 70 : QuotaThreadTask(quota_client, file_task_runner), |
71 quota_client_(quota_client), | 71 quota_client_(quota_client), |
72 type_(type) { | 72 type_(type) { |
73 DCHECK(quota_client_); | 73 DCHECK(quota_client_); |
74 file_system_context_ = quota_client_->file_system_context_; | 74 file_system_context_ = quota_client_->file_system_context_; |
75 } | 75 } |
76 virtual ~GetOriginsForTypeTask() {} | 76 virtual ~GetOriginsForTypeTask() {} |
77 | 77 |
78 protected: | 78 protected: |
79 virtual void RunOnTargetThread() OVERRIDE { | 79 virtual void RunOnTargetThread() OVERRIDE { |
80 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); | 80 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); |
81 if (quota_util) | 81 if (quota_util) |
82 quota_util->GetOriginsForTypeOnFileThread(type_, &origins_); | 82 quota_util->GetOriginsForTypeOnFileThread(type_, &origins_); |
83 } | 83 } |
84 | 84 |
85 virtual void Completed() OVERRIDE { | 85 virtual void Completed() OVERRIDE { |
86 quota_client_->DidGetOriginsForType(type_, origins_); | 86 quota_client_->DidGetOriginsForType(type_, origins_); |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 FileSystemQuotaClient* quota_client_; | 90 FileSystemQuotaClient* quota_client_; |
91 scoped_refptr<FileSystemContext> file_system_context_; | 91 scoped_refptr<FileSystemContext> file_system_context_; |
92 std::set<GURL> origins_; | 92 std::set<GURL> origins_; |
93 FileSystemType type_; | 93 FileSystemType type_; |
94 }; | 94 }; |
95 | 95 |
96 class FileSystemQuotaClient::GetOriginsForHostTask : public QuotaThreadTask { | 96 class FileSystemQuotaClient::GetOriginsForHostTask : public QuotaThreadTask { |
97 public: | 97 public: |
98 GetOriginsForHostTask( | 98 GetOriginsForHostTask( |
99 FileSystemQuotaClient* quota_client, | 99 FileSystemQuotaClient* quota_client, |
100 scoped_refptr<MessageLoopProxy> file_message_loop, | 100 TaskRunner* file_task_runner, |
101 FileSystemType type, | 101 FileSystemType type, |
102 const std::string& host) | 102 const std::string& host) |
103 : QuotaThreadTask(quota_client, file_message_loop), | 103 : QuotaThreadTask(quota_client, file_task_runner), |
104 quota_client_(quota_client), | 104 quota_client_(quota_client), |
105 type_(type), | 105 type_(type), |
106 host_(host) { | 106 host_(host) { |
107 DCHECK(quota_client_); | 107 DCHECK(quota_client_); |
108 file_system_context_ = quota_client_->file_system_context_; | 108 file_system_context_ = quota_client_->file_system_context_; |
109 } | 109 } |
110 virtual ~GetOriginsForHostTask() {} | 110 virtual ~GetOriginsForHostTask() {} |
111 | 111 |
112 protected: | 112 protected: |
113 virtual void RunOnTargetThread() OVERRIDE { | 113 virtual void RunOnTargetThread() OVERRIDE { |
(...skipping 12 matching lines...) Expand all Loading... |
126 std::set<GURL> origins_; | 126 std::set<GURL> origins_; |
127 FileSystemType type_; | 127 FileSystemType type_; |
128 std::string host_; | 128 std::string host_; |
129 }; | 129 }; |
130 | 130 |
131 class FileSystemQuotaClient::DeleteOriginTask | 131 class FileSystemQuotaClient::DeleteOriginTask |
132 : public QuotaThreadTask { | 132 : public QuotaThreadTask { |
133 public: | 133 public: |
134 DeleteOriginTask( | 134 DeleteOriginTask( |
135 FileSystemQuotaClient* quota_client, | 135 FileSystemQuotaClient* quota_client, |
136 scoped_refptr<MessageLoopProxy> file_message_loop, | 136 TaskRunner* file_task_runner, |
137 const GURL& origin, | 137 const GURL& origin, |
138 FileSystemType type, | 138 FileSystemType type, |
139 const DeletionCallback& callback) | 139 const DeletionCallback& callback) |
140 : QuotaThreadTask(quota_client, file_message_loop), | 140 : QuotaThreadTask(quota_client, file_task_runner), |
141 file_system_context_(quota_client->file_system_context_), | 141 file_system_context_(quota_client->file_system_context_), |
142 origin_(origin), | 142 origin_(origin), |
143 type_(type), | 143 type_(type), |
144 status_(quota::kQuotaStatusUnknown), | 144 status_(quota::kQuotaStatusUnknown), |
145 callback_(callback) { | 145 callback_(callback) { |
146 } | 146 } |
147 | 147 |
148 virtual ~DeleteOriginTask() {} | 148 virtual ~DeleteOriginTask() {} |
149 | 149 |
150 virtual void RunOnTargetThread() OVERRIDE { | 150 virtual void RunOnTargetThread() OVERRIDE { |
151 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( | 151 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( |
152 origin_, type_)) | 152 origin_, type_)) |
153 status_ = quota::kQuotaStatusOk; | 153 status_ = quota::kQuotaStatusOk; |
154 else | 154 else |
155 status_ = quota::kQuotaErrorInvalidModification; | 155 status_ = quota::kQuotaErrorInvalidModification; |
156 } | 156 } |
157 | 157 |
158 virtual void Completed() OVERRIDE { | 158 virtual void Completed() OVERRIDE { |
159 callback_.Run(status_); | 159 callback_.Run(status_); |
160 } | 160 } |
161 private: | 161 private: |
162 FileSystemContext* file_system_context_; | 162 FileSystemContext* file_system_context_; |
163 GURL origin_; | 163 GURL origin_; |
164 FileSystemType type_; | 164 FileSystemType type_; |
165 quota::QuotaStatusCode status_; | 165 quota::QuotaStatusCode status_; |
166 DeletionCallback callback_; | 166 DeletionCallback callback_; |
167 }; | 167 }; |
168 | 168 |
169 FileSystemQuotaClient::FileSystemQuotaClient( | 169 FileSystemQuotaClient::FileSystemQuotaClient( |
170 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 170 base::TaskRunner* file_task_runner, |
171 FileSystemContext* file_system_context, | 171 FileSystemContext* file_system_context, |
172 bool is_incognito) | 172 bool is_incognito) |
173 : file_message_loop_(file_message_loop), | 173 : file_task_runner_(file_task_runner), |
174 file_system_context_(file_system_context), | 174 file_system_context_(file_system_context), |
175 is_incognito_(is_incognito) { | 175 is_incognito_(is_incognito) { |
176 DCHECK(file_message_loop); | 176 DCHECK(file_task_runner); |
177 } | 177 } |
178 | 178 |
179 FileSystemQuotaClient::~FileSystemQuotaClient() { | 179 FileSystemQuotaClient::~FileSystemQuotaClient() { |
180 } | 180 } |
181 | 181 |
182 quota::QuotaClient::ID FileSystemQuotaClient::id() const { | 182 quota::QuotaClient::ID FileSystemQuotaClient::id() const { |
183 return quota::QuotaClient::kFileSystem; | 183 return quota::QuotaClient::kFileSystem; |
184 } | 184 } |
185 | 185 |
186 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { | 186 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { |
(...skipping 11 matching lines...) Expand all Loading... |
198 callback.Run(0); | 198 callback.Run(0); |
199 return; | 199 return; |
200 } | 200 } |
201 | 201 |
202 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 202 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
203 DCHECK(type != kFileSystemTypeUnknown); | 203 DCHECK(type != kFileSystemTypeUnknown); |
204 | 204 |
205 if (pending_usage_callbacks_.Add( | 205 if (pending_usage_callbacks_.Add( |
206 std::make_pair(type, origin_url.spec()), callback)) { | 206 std::make_pair(type, origin_url.spec()), callback)) { |
207 scoped_refptr<GetOriginUsageTask> task( | 207 scoped_refptr<GetOriginUsageTask> task( |
208 new GetOriginUsageTask(this, file_message_loop_, origin_url, type)); | 208 new GetOriginUsageTask(this, file_task_runner_, origin_url, type)); |
209 task->Start(); | 209 task->Start(); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 void FileSystemQuotaClient::GetOriginsForType( | 213 void FileSystemQuotaClient::GetOriginsForType( |
214 StorageType storage_type, | 214 StorageType storage_type, |
215 const GetOriginsCallback& callback) { | 215 const GetOriginsCallback& callback) { |
216 DCHECK(!callback.is_null()); | 216 DCHECK(!callback.is_null()); |
217 | 217 |
218 std::set<GURL> origins; | 218 std::set<GURL> origins; |
219 if (is_incognito_) { | 219 if (is_incognito_) { |
220 // We don't support FileSystem in incognito mode yet. | 220 // We don't support FileSystem in incognito mode yet. |
221 callback.Run(origins, storage_type); | 221 callback.Run(origins, storage_type); |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 225 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
226 DCHECK(type != kFileSystemTypeUnknown); | 226 DCHECK(type != kFileSystemTypeUnknown); |
227 | 227 |
228 if (pending_origins_for_type_callbacks_.Add(type, callback)) { | 228 if (pending_origins_for_type_callbacks_.Add(type, callback)) { |
229 scoped_refptr<GetOriginsForTypeTask> task( | 229 scoped_refptr<GetOriginsForTypeTask> task( |
230 new GetOriginsForTypeTask(this, file_message_loop_, type)); | 230 new GetOriginsForTypeTask(this, file_task_runner_, type)); |
231 task->Start(); | 231 task->Start(); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 void FileSystemQuotaClient::GetOriginsForHost( | 235 void FileSystemQuotaClient::GetOriginsForHost( |
236 StorageType storage_type, | 236 StorageType storage_type, |
237 const std::string& host, | 237 const std::string& host, |
238 const GetOriginsCallback& callback) { | 238 const GetOriginsCallback& callback) { |
239 DCHECK(!callback.is_null()); | 239 DCHECK(!callback.is_null()); |
240 | 240 |
241 std::set<GURL> origins; | 241 std::set<GURL> origins; |
242 if (is_incognito_) { | 242 if (is_incognito_) { |
243 // We don't support FileSystem in incognito mode yet. | 243 // We don't support FileSystem in incognito mode yet. |
244 callback.Run(origins, storage_type); | 244 callback.Run(origins, storage_type); |
245 return; | 245 return; |
246 } | 246 } |
247 | 247 |
248 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 248 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
249 DCHECK(type != kFileSystemTypeUnknown); | 249 DCHECK(type != kFileSystemTypeUnknown); |
250 | 250 |
251 if (pending_origins_for_host_callbacks_.Add( | 251 if (pending_origins_for_host_callbacks_.Add( |
252 std::make_pair(type, host), callback)) { | 252 std::make_pair(type, host), callback)) { |
253 scoped_refptr<GetOriginsForHostTask> task( | 253 scoped_refptr<GetOriginsForHostTask> task( |
254 new GetOriginsForHostTask(this, file_message_loop_, | 254 new GetOriginsForHostTask(this, file_task_runner_, |
255 type, host)); | 255 type, host)); |
256 task->Start(); | 256 task->Start(); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, | 260 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, |
261 StorageType type, | 261 StorageType type, |
262 const DeletionCallback& callback) { | 262 const DeletionCallback& callback) { |
263 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 263 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
264 DCHECK(fs_type != kFileSystemTypeUnknown); | 264 DCHECK(fs_type != kFileSystemTypeUnknown); |
265 scoped_refptr<DeleteOriginTask> task( | 265 scoped_refptr<DeleteOriginTask> task( |
266 new DeleteOriginTask(this, file_message_loop_, | 266 new DeleteOriginTask(this, file_task_runner_, |
267 origin, fs_type, callback)); | 267 origin, fs_type, callback)); |
268 task->Start(); | 268 task->Start(); |
269 } | 269 } |
270 | 270 |
271 void FileSystemQuotaClient::DidGetOriginUsage( | 271 void FileSystemQuotaClient::DidGetOriginUsage( |
272 FileSystemType type, const GURL& origin_url, int64 usage) { | 272 FileSystemType type, const GURL& origin_url, int64 usage) { |
273 TypeAndHostOrOrigin type_and_origin(std::make_pair( | 273 TypeAndHostOrOrigin type_and_origin(std::make_pair( |
274 type, origin_url.spec())); | 274 type, origin_url.spec())); |
275 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); | 275 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); |
276 pending_usage_callbacks_.Run(type_and_origin, usage); | 276 pending_usage_callbacks_.Run(type_and_origin, usage); |
277 } | 277 } |
278 | 278 |
279 void FileSystemQuotaClient::DidGetOriginsForType( | 279 void FileSystemQuotaClient::DidGetOriginsForType( |
280 FileSystemType type, const std::set<GURL>& origins) { | 280 FileSystemType type, const std::set<GURL>& origins) { |
281 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); | 281 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); |
282 pending_origins_for_type_callbacks_.Run(type, origins, | 282 pending_origins_for_type_callbacks_.Run(type, origins, |
283 FileSystemTypeToQuotaStorageType(type)); | 283 FileSystemTypeToQuotaStorageType(type)); |
284 } | 284 } |
285 | 285 |
286 void FileSystemQuotaClient::DidGetOriginsForHost( | 286 void FileSystemQuotaClient::DidGetOriginsForHost( |
287 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { | 287 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { |
288 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); | 288 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); |
289 pending_origins_for_host_callbacks_.Run(type_and_host, origins, | 289 pending_origins_for_host_callbacks_.Run(type_and_host, origins, |
290 FileSystemTypeToQuotaStorageType(type_and_host.first)); | 290 FileSystemTypeToQuotaStorageType(type_and_host.first)); |
291 } | 291 } |
292 | 292 |
293 } // namespace fileapi | 293 } // namespace fileapi |
OLD | NEW |