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/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" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 }; | 131 }; |
132 | 132 |
133 class FileSystemQuotaClient::DeleteOriginTask | 133 class FileSystemQuotaClient::DeleteOriginTask |
134 : public QuotaThreadTask { | 134 : public QuotaThreadTask { |
135 public: | 135 public: |
136 DeleteOriginTask( | 136 DeleteOriginTask( |
137 FileSystemQuotaClient* quota_client, | 137 FileSystemQuotaClient* quota_client, |
138 scoped_refptr<MessageLoopProxy> file_message_loop, | 138 scoped_refptr<MessageLoopProxy> file_message_loop, |
139 const GURL& origin, | 139 const GURL& origin, |
140 FileSystemType type, | 140 FileSystemType type, |
141 DeletionCallback* callback) | 141 const DeletionCallback& callback) |
142 : QuotaThreadTask(quota_client, file_message_loop), | 142 : QuotaThreadTask(quota_client, file_message_loop), |
143 file_system_context_(quota_client->file_system_context_), | 143 file_system_context_(quota_client->file_system_context_), |
144 origin_(origin), | 144 origin_(origin), |
145 type_(type), | 145 type_(type), |
146 status_(quota::kQuotaStatusUnknown), | 146 status_(quota::kQuotaStatusUnknown), |
147 callback_(callback) { | 147 callback_(callback) { |
148 } | 148 } |
149 | 149 |
150 virtual ~DeleteOriginTask() {} | 150 virtual ~DeleteOriginTask() {} |
151 | 151 |
152 virtual void RunOnTargetThread() OVERRIDE { | 152 virtual void RunOnTargetThread() OVERRIDE { |
153 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( | 153 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( |
154 origin_, type_)) | 154 origin_, type_)) |
155 status_ = quota::kQuotaStatusOk; | 155 status_ = quota::kQuotaStatusOk; |
156 else | 156 else |
157 status_ = quota::kQuotaErrorInvalidModification; | 157 status_ = quota::kQuotaErrorInvalidModification; |
158 } | 158 } |
159 | 159 |
160 virtual void Completed() OVERRIDE { | 160 virtual void Completed() OVERRIDE { |
161 callback_->Run(status_); | 161 callback_.Run(status_); |
162 } | 162 } |
163 private: | 163 private: |
164 FileSystemContext* file_system_context_; | 164 FileSystemContext* file_system_context_; |
165 GURL origin_; | 165 GURL origin_; |
166 FileSystemType type_; | 166 FileSystemType type_; |
167 quota::QuotaStatusCode status_; | 167 quota::QuotaStatusCode status_; |
168 scoped_ptr<DeletionCallback> callback_; | 168 DeletionCallback callback_; |
169 }; | 169 }; |
170 | 170 |
171 FileSystemQuotaClient::FileSystemQuotaClient( | 171 FileSystemQuotaClient::FileSystemQuotaClient( |
172 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 172 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
173 FileSystemContext* file_system_context, | 173 FileSystemContext* file_system_context, |
174 bool is_incognito) | 174 bool is_incognito) |
175 : file_message_loop_(file_message_loop), | 175 : file_message_loop_(file_message_loop), |
176 file_system_context_(file_system_context), | 176 file_system_context_(file_system_context), |
177 is_incognito_(is_incognito) { | 177 is_incognito_(is_incognito) { |
178 DCHECK(file_message_loop); | 178 DCHECK(file_message_loop); |
179 } | 179 } |
180 | 180 |
181 FileSystemQuotaClient::~FileSystemQuotaClient() { | 181 FileSystemQuotaClient::~FileSystemQuotaClient() { |
182 } | 182 } |
183 | 183 |
184 quota::QuotaClient::ID FileSystemQuotaClient::id() const { | 184 quota::QuotaClient::ID FileSystemQuotaClient::id() const { |
185 return quota::QuotaClient::kFileSystem; | 185 return quota::QuotaClient::kFileSystem; |
186 } | 186 } |
187 | 187 |
188 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { | 188 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { |
189 delete this; | 189 delete this; |
190 } | 190 } |
191 | 191 |
192 void FileSystemQuotaClient::GetOriginUsage( | 192 void FileSystemQuotaClient::GetOriginUsage( |
193 const GURL& origin_url, | 193 const GURL& origin_url, |
194 StorageType storage_type, | 194 StorageType storage_type, |
195 GetUsageCallback* callback_ptr) { | 195 const GetUsageCallback& callback) { |
196 DCHECK(callback_ptr); | 196 DCHECK(!callback.is_null()); |
197 scoped_ptr<GetUsageCallback> callback(callback_ptr); | |
198 | 197 |
199 if (is_incognito_) { | 198 if (is_incognito_) { |
200 // We don't support FileSystem in incognito mode yet. | 199 // We don't support FileSystem in incognito mode yet. |
201 callback->Run(0); | 200 callback.Run(0); |
202 return; | 201 return; |
203 } | 202 } |
204 | 203 |
205 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 204 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
206 DCHECK(type != kFileSystemTypeUnknown); | 205 DCHECK(type != kFileSystemTypeUnknown); |
207 | 206 |
208 if (pending_usage_callbacks_.Add( | 207 if (pending_usage_callbacks_.Add( |
209 std::make_pair(type, origin_url.spec()), callback.release())) { | 208 std::make_pair(type, origin_url.spec()), callback)) { |
210 scoped_refptr<GetOriginUsageTask> task( | 209 scoped_refptr<GetOriginUsageTask> task( |
211 new GetOriginUsageTask(this, file_message_loop_, origin_url, type)); | 210 new GetOriginUsageTask(this, file_message_loop_, origin_url, type)); |
212 task->Start(); | 211 task->Start(); |
213 } | 212 } |
214 } | 213 } |
215 | 214 |
216 void FileSystemQuotaClient::GetOriginsForType( | 215 void FileSystemQuotaClient::GetOriginsForType( |
217 StorageType storage_type, | 216 StorageType storage_type, |
218 GetOriginsCallback* callback_ptr) { | 217 const GetOriginsCallback& callback) { |
| 218 DCHECK(!callback.is_null()); |
| 219 |
219 std::set<GURL> origins; | 220 std::set<GURL> origins; |
220 scoped_ptr<GetOriginsCallback> callback(callback_ptr); | |
221 if (is_incognito_) { | 221 if (is_incognito_) { |
222 // We don't support FileSystem in incognito mode yet. | 222 // We don't support FileSystem in incognito mode yet. |
223 callback->Run(origins, storage_type); | 223 callback.Run(origins, storage_type); |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 227 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
228 DCHECK(type != kFileSystemTypeUnknown); | 228 DCHECK(type != kFileSystemTypeUnknown); |
229 | 229 |
230 if (pending_origins_for_type_callbacks_.Add(type, callback.release())) { | 230 if (pending_origins_for_type_callbacks_.Add(type, callback)) { |
231 scoped_refptr<GetOriginsForTypeTask> task( | 231 scoped_refptr<GetOriginsForTypeTask> task( |
232 new GetOriginsForTypeTask(this, file_message_loop_, type)); | 232 new GetOriginsForTypeTask(this, file_message_loop_, type)); |
233 task->Start(); | 233 task->Start(); |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 void FileSystemQuotaClient::GetOriginsForHost( | 237 void FileSystemQuotaClient::GetOriginsForHost( |
238 StorageType storage_type, | 238 StorageType storage_type, |
239 const std::string& host, | 239 const std::string& host, |
240 GetOriginsCallback* callback_ptr) { | 240 const GetOriginsCallback& callback) { |
| 241 DCHECK(!callback.is_null()); |
| 242 |
241 std::set<GURL> origins; | 243 std::set<GURL> origins; |
242 scoped_ptr<GetOriginsCallback> callback(callback_ptr); | |
243 if (is_incognito_) { | 244 if (is_incognito_) { |
244 // We don't support FileSystem in incognito mode yet. | 245 // We don't support FileSystem in incognito mode yet. |
245 callback->Run(origins, storage_type); | 246 callback.Run(origins, storage_type); |
246 return; | 247 return; |
247 } | 248 } |
248 | 249 |
249 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 250 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
250 DCHECK(type != kFileSystemTypeUnknown); | 251 DCHECK(type != kFileSystemTypeUnknown); |
251 | 252 |
252 if (pending_origins_for_host_callbacks_.Add( | 253 if (pending_origins_for_host_callbacks_.Add( |
253 std::make_pair(type, host), callback.release())) { | 254 std::make_pair(type, host), callback)) { |
254 scoped_refptr<GetOriginsForHostTask> task( | 255 scoped_refptr<GetOriginsForHostTask> task( |
255 new GetOriginsForHostTask(this, file_message_loop_, | 256 new GetOriginsForHostTask(this, file_message_loop_, |
256 type, host)); | 257 type, host)); |
257 task->Start(); | 258 task->Start(); |
258 } | 259 } |
259 } | 260 } |
260 | 261 |
261 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, | 262 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, |
262 StorageType type, | 263 StorageType type, |
263 DeletionCallback* callback) { | 264 const DeletionCallback& callback) { |
264 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 265 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
265 DCHECK(fs_type != kFileSystemTypeUnknown); | 266 DCHECK(fs_type != kFileSystemTypeUnknown); |
266 scoped_refptr<DeleteOriginTask> task( | 267 scoped_refptr<DeleteOriginTask> task( |
267 new DeleteOriginTask(this, file_message_loop_, | 268 new DeleteOriginTask(this, file_message_loop_, |
268 origin, fs_type, callback)); | 269 origin, fs_type, callback)); |
269 task->Start(); | 270 task->Start(); |
270 } | 271 } |
271 | 272 |
272 void FileSystemQuotaClient::DidGetOriginUsage( | 273 void FileSystemQuotaClient::DidGetOriginUsage( |
273 FileSystemType type, const GURL& origin_url, int64 usage) { | 274 FileSystemType type, const GURL& origin_url, int64 usage) { |
(...skipping 11 matching lines...) Expand all Loading... |
285 } | 286 } |
286 | 287 |
287 void FileSystemQuotaClient::DidGetOriginsForHost( | 288 void FileSystemQuotaClient::DidGetOriginsForHost( |
288 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { | 289 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { |
289 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); | 290 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); |
290 pending_origins_for_host_callbacks_.Run(type_and_host, origins, | 291 pending_origins_for_host_callbacks_.Run(type_and_host, origins, |
291 FileSystemTypeToQuotaStorageType(type_and_host.first)); | 292 FileSystemTypeToQuotaStorageType(type_and_host.first)); |
292 } | 293 } |
293 | 294 |
294 } // namespace fileapi | 295 } // namespace fileapi |
OLD | NEW |