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/sequenced_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::SequencedTaskRunner; |
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, | |
33 const GURL& origin_url, | 32 const GURL& origin_url, |
34 FileSystemType type) | 33 FileSystemType type) |
35 : QuotaThreadTask(quota_client, file_message_loop), | 34 : QuotaThreadTask(quota_client, quota_client->file_task_runner()), |
36 quota_client_(quota_client), | 35 quota_client_(quota_client), |
37 origin_url_(origin_url), | 36 origin_url_(origin_url), |
38 type_(type), | 37 type_(type), |
39 fs_usage_(0) { | 38 fs_usage_(0) { |
40 DCHECK(quota_client_); | 39 DCHECK(quota_client_); |
41 file_system_context_ = quota_client_->file_system_context_; | 40 file_system_context_ = quota_client_->file_system_context_; |
42 } | 41 } |
43 | 42 |
44 protected: | 43 protected: |
45 virtual ~GetOriginUsageTask() {} | 44 virtual ~GetOriginUsageTask() {} |
(...skipping 13 matching lines...) Expand all Loading... |
59 scoped_refptr<FileSystemContext> file_system_context_; | 58 scoped_refptr<FileSystemContext> file_system_context_; |
60 GURL origin_url_; | 59 GURL origin_url_; |
61 FileSystemType type_; | 60 FileSystemType type_; |
62 int64 fs_usage_; | 61 int64 fs_usage_; |
63 }; | 62 }; |
64 | 63 |
65 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { | 64 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { |
66 public: | 65 public: |
67 GetOriginsForTypeTask( | 66 GetOriginsForTypeTask( |
68 FileSystemQuotaClient* quota_client, | 67 FileSystemQuotaClient* quota_client, |
69 scoped_refptr<MessageLoopProxy> file_message_loop, | |
70 FileSystemType type) | 68 FileSystemType type) |
71 : QuotaThreadTask(quota_client, file_message_loop), | 69 : QuotaThreadTask(quota_client, quota_client->file_task_runner()), |
72 quota_client_(quota_client), | 70 quota_client_(quota_client), |
73 type_(type) { | 71 type_(type) { |
74 DCHECK(quota_client_); | 72 DCHECK(quota_client_); |
75 file_system_context_ = quota_client_->file_system_context_; | 73 file_system_context_ = quota_client_->file_system_context_; |
76 } | 74 } |
77 | 75 |
78 protected: | 76 protected: |
79 virtual ~GetOriginsForTypeTask() {} | 77 virtual ~GetOriginsForTypeTask() {} |
80 | 78 |
81 // QuotaThreadTask: | 79 // QuotaThreadTask: |
(...skipping 11 matching lines...) Expand all Loading... |
93 FileSystemQuotaClient* quota_client_; | 91 FileSystemQuotaClient* quota_client_; |
94 scoped_refptr<FileSystemContext> file_system_context_; | 92 scoped_refptr<FileSystemContext> file_system_context_; |
95 std::set<GURL> origins_; | 93 std::set<GURL> origins_; |
96 FileSystemType type_; | 94 FileSystemType type_; |
97 }; | 95 }; |
98 | 96 |
99 class FileSystemQuotaClient::GetOriginsForHostTask : public QuotaThreadTask { | 97 class FileSystemQuotaClient::GetOriginsForHostTask : public QuotaThreadTask { |
100 public: | 98 public: |
101 GetOriginsForHostTask( | 99 GetOriginsForHostTask( |
102 FileSystemQuotaClient* quota_client, | 100 FileSystemQuotaClient* quota_client, |
103 scoped_refptr<MessageLoopProxy> file_message_loop, | |
104 FileSystemType type, | 101 FileSystemType type, |
105 const std::string& host) | 102 const std::string& host) |
106 : QuotaThreadTask(quota_client, file_message_loop), | 103 : QuotaThreadTask(quota_client, quota_client->file_task_runner()), |
107 quota_client_(quota_client), | 104 quota_client_(quota_client), |
108 type_(type), | 105 type_(type), |
109 host_(host) { | 106 host_(host) { |
110 DCHECK(quota_client_); | 107 DCHECK(quota_client_); |
111 file_system_context_ = quota_client_->file_system_context_; | 108 file_system_context_ = quota_client_->file_system_context_; |
112 } | 109 } |
113 | 110 |
114 protected: | 111 protected: |
115 virtual ~GetOriginsForHostTask() {} | 112 virtual ~GetOriginsForHostTask() {} |
116 | 113 |
(...skipping 14 matching lines...) Expand all Loading... |
131 std::set<GURL> origins_; | 128 std::set<GURL> origins_; |
132 FileSystemType type_; | 129 FileSystemType type_; |
133 std::string host_; | 130 std::string host_; |
134 }; | 131 }; |
135 | 132 |
136 class FileSystemQuotaClient::DeleteOriginTask | 133 class FileSystemQuotaClient::DeleteOriginTask |
137 : public QuotaThreadTask { | 134 : public QuotaThreadTask { |
138 public: | 135 public: |
139 DeleteOriginTask( | 136 DeleteOriginTask( |
140 FileSystemQuotaClient* quota_client, | 137 FileSystemQuotaClient* quota_client, |
141 scoped_refptr<MessageLoopProxy> file_message_loop, | |
142 const GURL& origin, | 138 const GURL& origin, |
143 FileSystemType type, | 139 FileSystemType type, |
144 const DeletionCallback& callback) | 140 const DeletionCallback& callback) |
145 : QuotaThreadTask(quota_client, file_message_loop), | 141 : QuotaThreadTask(quota_client, quota_client->file_task_runner()), |
146 file_system_context_(quota_client->file_system_context_), | 142 file_system_context_(quota_client->file_system_context_), |
147 origin_(origin), | 143 origin_(origin), |
148 type_(type), | 144 type_(type), |
149 status_(quota::kQuotaStatusUnknown), | 145 status_(quota::kQuotaStatusUnknown), |
150 callback_(callback) { | 146 callback_(callback) { |
151 } | 147 } |
152 | 148 |
153 protected: | 149 protected: |
154 virtual ~DeleteOriginTask() {} | 150 virtual ~DeleteOriginTask() {} |
155 | 151 |
(...skipping 12 matching lines...) Expand all Loading... |
168 | 164 |
169 private: | 165 private: |
170 FileSystemContext* file_system_context_; | 166 FileSystemContext* file_system_context_; |
171 GURL origin_; | 167 GURL origin_; |
172 FileSystemType type_; | 168 FileSystemType type_; |
173 quota::QuotaStatusCode status_; | 169 quota::QuotaStatusCode status_; |
174 DeletionCallback callback_; | 170 DeletionCallback callback_; |
175 }; | 171 }; |
176 | 172 |
177 FileSystemQuotaClient::FileSystemQuotaClient( | 173 FileSystemQuotaClient::FileSystemQuotaClient( |
178 scoped_refptr<base::MessageLoopProxy> file_message_loop, | |
179 FileSystemContext* file_system_context, | 174 FileSystemContext* file_system_context, |
180 bool is_incognito) | 175 bool is_incognito) |
181 : file_message_loop_(file_message_loop), | 176 : file_system_context_(file_system_context), |
182 file_system_context_(file_system_context), | |
183 is_incognito_(is_incognito) { | 177 is_incognito_(is_incognito) { |
184 DCHECK(file_message_loop); | |
185 } | 178 } |
186 | 179 |
187 FileSystemQuotaClient::~FileSystemQuotaClient() {} | 180 FileSystemQuotaClient::~FileSystemQuotaClient() {} |
188 | 181 |
189 quota::QuotaClient::ID FileSystemQuotaClient::id() const { | 182 quota::QuotaClient::ID FileSystemQuotaClient::id() const { |
190 return quota::QuotaClient::kFileSystem; | 183 return quota::QuotaClient::kFileSystem; |
191 } | 184 } |
192 | 185 |
193 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { | 186 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { |
194 delete this; | 187 delete this; |
(...skipping 10 matching lines...) Expand all Loading... |
205 callback.Run(0); | 198 callback.Run(0); |
206 return; | 199 return; |
207 } | 200 } |
208 | 201 |
209 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 202 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
210 DCHECK(type != kFileSystemTypeUnknown); | 203 DCHECK(type != kFileSystemTypeUnknown); |
211 | 204 |
212 if (pending_usage_callbacks_.Add( | 205 if (pending_usage_callbacks_.Add( |
213 std::make_pair(type, origin_url.spec()), callback)) { | 206 std::make_pair(type, origin_url.spec()), callback)) { |
214 scoped_refptr<GetOriginUsageTask> task( | 207 scoped_refptr<GetOriginUsageTask> task( |
215 new GetOriginUsageTask(this, file_message_loop_, origin_url, type)); | 208 new GetOriginUsageTask(this, origin_url, type)); |
216 task->Start(); | 209 task->Start(); |
217 } | 210 } |
218 } | 211 } |
219 | 212 |
220 void FileSystemQuotaClient::GetOriginsForType( | 213 void FileSystemQuotaClient::GetOriginsForType( |
221 StorageType storage_type, | 214 StorageType storage_type, |
222 const GetOriginsCallback& callback) { | 215 const GetOriginsCallback& callback) { |
223 DCHECK(!callback.is_null()); | 216 DCHECK(!callback.is_null()); |
224 | 217 |
225 std::set<GURL> origins; | 218 std::set<GURL> origins; |
226 if (is_incognito_) { | 219 if (is_incognito_) { |
227 // We don't support FileSystem in incognito mode yet. | 220 // We don't support FileSystem in incognito mode yet. |
228 callback.Run(origins, storage_type); | 221 callback.Run(origins, storage_type); |
229 return; | 222 return; |
230 } | 223 } |
231 | 224 |
232 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 225 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
233 DCHECK(type != kFileSystemTypeUnknown); | 226 DCHECK(type != kFileSystemTypeUnknown); |
234 | 227 |
235 if (pending_origins_for_type_callbacks_.Add(type, callback)) { | 228 if (pending_origins_for_type_callbacks_.Add(type, callback)) { |
236 scoped_refptr<GetOriginsForTypeTask> task( | 229 scoped_refptr<GetOriginsForTypeTask> task( |
237 new GetOriginsForTypeTask(this, file_message_loop_, type)); | 230 new GetOriginsForTypeTask(this, type)); |
238 task->Start(); | 231 task->Start(); |
239 } | 232 } |
240 } | 233 } |
241 | 234 |
242 void FileSystemQuotaClient::GetOriginsForHost( | 235 void FileSystemQuotaClient::GetOriginsForHost( |
243 StorageType storage_type, | 236 StorageType storage_type, |
244 const std::string& host, | 237 const std::string& host, |
245 const GetOriginsCallback& callback) { | 238 const GetOriginsCallback& callback) { |
246 DCHECK(!callback.is_null()); | 239 DCHECK(!callback.is_null()); |
247 | 240 |
248 std::set<GURL> origins; | 241 std::set<GURL> origins; |
249 if (is_incognito_) { | 242 if (is_incognito_) { |
250 // We don't support FileSystem in incognito mode yet. | 243 // We don't support FileSystem in incognito mode yet. |
251 callback.Run(origins, storage_type); | 244 callback.Run(origins, storage_type); |
252 return; | 245 return; |
253 } | 246 } |
254 | 247 |
255 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 248 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
256 DCHECK(type != kFileSystemTypeUnknown); | 249 DCHECK(type != kFileSystemTypeUnknown); |
257 | 250 |
258 if (pending_origins_for_host_callbacks_.Add( | 251 if (pending_origins_for_host_callbacks_.Add( |
259 std::make_pair(type, host), callback)) { | 252 std::make_pair(type, host), callback)) { |
260 scoped_refptr<GetOriginsForHostTask> task( | 253 scoped_refptr<GetOriginsForHostTask> task( |
261 new GetOriginsForHostTask(this, file_message_loop_, | 254 new GetOriginsForHostTask(this, type, host)); |
262 type, host)); | |
263 task->Start(); | 255 task->Start(); |
264 } | 256 } |
265 } | 257 } |
266 | 258 |
267 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, | 259 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, |
268 StorageType type, | 260 StorageType type, |
269 const DeletionCallback& callback) { | 261 const DeletionCallback& callback) { |
270 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 262 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
271 DCHECK(fs_type != kFileSystemTypeUnknown); | 263 DCHECK(fs_type != kFileSystemTypeUnknown); |
272 scoped_refptr<DeleteOriginTask> task( | 264 scoped_refptr<DeleteOriginTask> task( |
273 new DeleteOriginTask(this, file_message_loop_, | 265 new DeleteOriginTask(this, origin, fs_type, callback)); |
274 origin, fs_type, callback)); | |
275 task->Start(); | 266 task->Start(); |
276 } | 267 } |
277 | 268 |
278 void FileSystemQuotaClient::DidGetOriginUsage( | 269 void FileSystemQuotaClient::DidGetOriginUsage( |
279 FileSystemType type, const GURL& origin_url, int64 usage) { | 270 FileSystemType type, const GURL& origin_url, int64 usage) { |
280 TypeAndHostOrOrigin type_and_origin(std::make_pair( | 271 TypeAndHostOrOrigin type_and_origin(std::make_pair( |
281 type, origin_url.spec())); | 272 type, origin_url.spec())); |
282 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); | 273 DCHECK(pending_usage_callbacks_.HasCallbacks(type_and_origin)); |
283 pending_usage_callbacks_.Run(type_and_origin, usage); | 274 pending_usage_callbacks_.Run(type_and_origin, usage); |
284 } | 275 } |
285 | 276 |
286 void FileSystemQuotaClient::DidGetOriginsForType( | 277 void FileSystemQuotaClient::DidGetOriginsForType( |
287 FileSystemType type, const std::set<GURL>& origins) { | 278 FileSystemType type, const std::set<GURL>& origins) { |
288 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); | 279 DCHECK(pending_origins_for_type_callbacks_.HasCallbacks(type)); |
289 pending_origins_for_type_callbacks_.Run(type, origins, | 280 pending_origins_for_type_callbacks_.Run(type, origins, |
290 FileSystemTypeToQuotaStorageType(type)); | 281 FileSystemTypeToQuotaStorageType(type)); |
291 } | 282 } |
292 | 283 |
293 void FileSystemQuotaClient::DidGetOriginsForHost( | 284 void FileSystemQuotaClient::DidGetOriginsForHost( |
294 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { | 285 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { |
295 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); | 286 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); |
296 pending_origins_for_host_callbacks_.Run(type_and_host, origins, | 287 pending_origins_for_host_callbacks_.Run(type_and_host, origins, |
297 FileSystemTypeToQuotaStorageType(type_and_host.first)); | 288 FileSystemTypeToQuotaStorageType(type_and_host.first)); |
298 } | 289 } |
299 | 290 |
| 291 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { |
| 292 return file_system_context_->file_task_runner(); |
| 293 } |
| 294 |
300 } // namespace fileapi | 295 } // namespace fileapi |
OLD | NEW |