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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
13 #include "webkit/blob/shareable_file_reference.h" | 13 #include "webkit/blob/shareable_file_reference.h" |
14 #include "webkit/fileapi/file_observers.h" | 14 #include "webkit/fileapi/file_observers.h" |
15 #include "webkit/fileapi/file_system_context.h" | 15 #include "webkit/fileapi/file_system_context.h" |
16 #include "webkit/fileapi/file_system_file_util_proxy.h" | 16 #include "webkit/fileapi/file_system_file_util_proxy.h" |
17 #include "webkit/fileapi/file_system_mount_point_provider.h" | 17 #include "webkit/fileapi/file_system_mount_point_provider.h" |
18 #include "webkit/fileapi/file_system_task_runners.h" | 18 #include "webkit/fileapi/file_system_task_runners.h" |
19 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
20 #include "webkit/fileapi/file_system_url.h" | 20 #include "webkit/fileapi/file_system_url.h" |
21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
22 #include "webkit/fileapi/file_writer_delegate.h" | 22 #include "webkit/fileapi/file_writer_delegate.h" |
| 23 #include "webkit/fileapi/remove_operation_delegate.h" |
23 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 24 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
24 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
25 #include "webkit/quota/quota_types.h" | 26 #include "webkit/quota/quota_types.h" |
26 | 27 |
27 using webkit_blob::ShareableFileReference; | 28 using webkit_blob::ShareableFileReference; |
28 | 29 |
29 namespace fileapi { | 30 namespace fileapi { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 bool IsMediaFileSystemType(FileSystemType type) { | 34 bool IsMediaFileSystemType(FileSystemType type) { |
34 return type == kFileSystemTypeNativeMedia || | 35 return type == kFileSystemTypeNativeMedia || |
35 type == kFileSystemTypeDeviceMedia; | 36 type == kFileSystemTypeDeviceMedia; |
36 } | 37 } |
37 | 38 |
38 bool IsCrossOperationAllowed(FileSystemType src_type, | 39 bool IsCrossOperationAllowed(FileSystemType src_type, |
39 FileSystemType dest_type) { | 40 FileSystemType dest_type) { |
40 // If two types are supposed to run on different task runners we should not | 41 // If two types are supposed to run on different task runners we should not |
41 // allow cross FileUtil operations at this layer. | 42 // allow cross FileUtil operations at this layer. |
42 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); | 43 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
| 48 // LocalFileSystemOperation::ScopedUpdateNotifier ----------------------------- |
| 49 |
47 class LocalFileSystemOperation::ScopedUpdateNotifier { | 50 class LocalFileSystemOperation::ScopedUpdateNotifier { |
48 public: | 51 public: |
49 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, | 52 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, |
50 const FileSystemURL& url); | 53 const FileSystemURL& url); |
51 ~ScopedUpdateNotifier(); | 54 ~ScopedUpdateNotifier(); |
52 | 55 |
53 private: | 56 private: |
54 // Not owned; owned by the owner of this instance | 57 // Not owned; owned by the owner of this instance |
55 // (i.e. LocalFileSystemOperation). | 58 // (i.e. LocalFileSystemOperation). |
56 FileSystemOperationContext* operation_context_; | 59 FileSystemOperationContext* operation_context_; |
57 FileSystemURL url_; | 60 FileSystemURL url_; |
58 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier); | 61 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier); |
59 }; | 62 }; |
60 | 63 |
61 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier( | 64 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier( |
62 FileSystemOperationContext* operation_context, | 65 FileSystemOperationContext* operation_context, |
63 const FileSystemURL& url) | 66 const FileSystemURL& url) |
64 : operation_context_(operation_context), url_(url) { | 67 : operation_context_(operation_context), url_(url) { |
65 operation_context_->update_observers()->Notify( | 68 operation_context_->update_observers()->Notify( |
66 &FileUpdateObserver::OnStartUpdate, MakeTuple(url_)); | 69 &FileUpdateObserver::OnStartUpdate, MakeTuple(url_)); |
67 } | 70 } |
68 | 71 |
69 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() { | 72 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() { |
70 operation_context_->update_observers()->Notify( | 73 operation_context_->update_observers()->Notify( |
71 &FileUpdateObserver::OnEndUpdate, MakeTuple(url_)); | 74 &FileUpdateObserver::OnEndUpdate, MakeTuple(url_)); |
72 } | 75 } |
73 | 76 |
| 77 // LocalFileSystemOperation --------------------------------------------------- |
| 78 |
74 LocalFileSystemOperation::~LocalFileSystemOperation() { | 79 LocalFileSystemOperation::~LocalFileSystemOperation() { |
75 } | 80 } |
76 | 81 |
77 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, | 82 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, |
78 bool exclusive, | 83 bool exclusive, |
79 const StatusCallback& callback) { | 84 const StatusCallback& callback) { |
80 DCHECK(SetPendingOperationType(kOperationCreateFile)); | 85 DCHECK(SetPendingOperationType(kOperationCreateFile)); |
81 | 86 |
82 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); | 87 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); |
83 if (result != base::PLATFORM_FILE_OK) { | 88 if (result != base::PLATFORM_FILE_OK) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); | 185 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); |
181 | 186 |
182 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 187 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
183 if (result != base::PLATFORM_FILE_OK) { | 188 if (result != base::PLATFORM_FILE_OK) { |
184 callback.Run(result); | 189 callback.Run(result); |
185 delete this; | 190 delete this; |
186 return; | 191 return; |
187 } | 192 } |
188 | 193 |
189 FileSystemFileUtilProxy::GetFileInfo( | 194 FileSystemFileUtilProxy::GetFileInfo( |
190 operation_context_.get(), src_util_, url, | 195 operation_context(), src_util_, url, |
191 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, | 196 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, |
192 base::Owned(this), callback)); | 197 base::Owned(this), callback)); |
193 } | 198 } |
194 | 199 |
195 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, | 200 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, |
196 const StatusCallback& callback) { | 201 const StatusCallback& callback) { |
197 DCHECK(SetPendingOperationType(kOperationFileExists)); | 202 DCHECK(SetPendingOperationType(kOperationFileExists)); |
198 | 203 |
199 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 204 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
200 if (result != base::PLATFORM_FILE_OK) { | 205 if (result != base::PLATFORM_FILE_OK) { |
201 callback.Run(result); | 206 callback.Run(result); |
202 delete this; | 207 delete this; |
203 return; | 208 return; |
204 } | 209 } |
205 | 210 |
206 FileSystemFileUtilProxy::GetFileInfo( | 211 FileSystemFileUtilProxy::GetFileInfo( |
207 operation_context_.get(), src_util_, url, | 212 operation_context(), src_util_, url, |
208 base::Bind(&LocalFileSystemOperation::DidFileExists, | 213 base::Bind(&LocalFileSystemOperation::DidFileExists, |
209 base::Owned(this), callback)); | 214 base::Owned(this), callback)); |
210 } | 215 } |
211 | 216 |
212 void LocalFileSystemOperation::GetMetadata( | 217 void LocalFileSystemOperation::GetMetadata( |
213 const FileSystemURL& url, const GetMetadataCallback& callback) { | 218 const FileSystemURL& url, const GetMetadataCallback& callback) { |
214 DCHECK(SetPendingOperationType(kOperationGetMetadata)); | 219 DCHECK(SetPendingOperationType(kOperationGetMetadata)); |
215 | 220 |
216 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 221 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
217 if (result != base::PLATFORM_FILE_OK) { | 222 if (result != base::PLATFORM_FILE_OK) { |
218 callback.Run(result, base::PlatformFileInfo(), FilePath()); | 223 callback.Run(result, base::PlatformFileInfo(), FilePath()); |
219 delete this; | 224 delete this; |
220 return; | 225 return; |
221 } | 226 } |
222 | 227 |
223 FileSystemFileUtilProxy::GetFileInfo( | 228 FileSystemFileUtilProxy::GetFileInfo( |
224 operation_context_.get(), src_util_, url, | 229 operation_context(), src_util_, url, |
225 base::Bind(&LocalFileSystemOperation::DidGetMetadata, | 230 base::Bind(&LocalFileSystemOperation::DidGetMetadata, |
226 base::Owned(this), callback)); | 231 base::Owned(this), callback)); |
227 } | 232 } |
228 | 233 |
229 void LocalFileSystemOperation::ReadDirectory( | 234 void LocalFileSystemOperation::ReadDirectory( |
230 const FileSystemURL& url, const ReadDirectoryCallback& callback) { | 235 const FileSystemURL& url, const ReadDirectoryCallback& callback) { |
231 DCHECK(SetPendingOperationType(kOperationReadDirectory)); | 236 DCHECK(SetPendingOperationType(kOperationReadDirectory)); |
232 | 237 |
233 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 238 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
234 if (result != base::PLATFORM_FILE_OK) { | 239 if (result != base::PLATFORM_FILE_OK) { |
235 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); | 240 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); |
236 delete this; | 241 delete this; |
237 return; | 242 return; |
238 } | 243 } |
239 | 244 |
240 FileSystemFileUtilProxy::ReadDirectory( | 245 FileSystemFileUtilProxy::ReadDirectory( |
241 operation_context_.get(), src_util_, url, | 246 operation_context(), src_util_, url, |
242 base::Bind(&LocalFileSystemOperation::DidReadDirectory, | 247 base::Bind(&LocalFileSystemOperation::DidReadDirectory, |
243 base::Owned(this), callback)); | 248 base::Owned(this), callback)); |
244 } | 249 } |
245 | 250 |
246 void LocalFileSystemOperation::Remove(const FileSystemURL& url, | 251 void LocalFileSystemOperation::Remove(const FileSystemURL& url, |
247 bool recursive, | 252 bool recursive, |
248 const StatusCallback& callback) { | 253 const StatusCallback& callback) { |
249 DCHECK(SetPendingOperationType(kOperationRemove)); | 254 DCHECK(SetPendingOperationType(kOperationRemove)); |
250 | 255 DCHECK(!remove_operation_delegate_); |
251 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 256 remove_operation_delegate_.reset(new RemoveOperationDelegate(this, callback)); |
252 if (result != base::PLATFORM_FILE_OK) { | 257 if (recursive) |
253 callback.Run(result); | 258 remove_operation_delegate_->RunRecursively(url); |
254 delete this; | 259 else |
255 return; | 260 remove_operation_delegate_->Run(url); |
256 } | |
257 | |
258 FileSystemFileUtilProxy::Delete( | |
259 operation_context_.get(), src_util_, url, recursive, | |
260 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | |
261 base::Owned(this), callback)); | |
262 } | 261 } |
263 | 262 |
264 void LocalFileSystemOperation::Write( | 263 void LocalFileSystemOperation::Write( |
265 const net::URLRequestContext* url_request_context, | 264 const net::URLRequestContext* url_request_context, |
266 const FileSystemURL& url, | 265 const FileSystemURL& url, |
267 const GURL& blob_url, | 266 const GURL& blob_url, |
268 int64 offset, | 267 int64 offset, |
269 const WriteCallback& callback) { | 268 const WriteCallback& callback) { |
270 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); | 269 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); |
271 } | 270 } |
(...skipping 22 matching lines...) Expand all Loading... |
294 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 293 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
295 | 294 |
296 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 295 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); |
297 if (result != base::PLATFORM_FILE_OK) { | 296 if (result != base::PLATFORM_FILE_OK) { |
298 callback.Run(result); | 297 callback.Run(result); |
299 delete this; | 298 delete this; |
300 return; | 299 return; |
301 } | 300 } |
302 | 301 |
303 FileSystemFileUtilProxy::Touch( | 302 FileSystemFileUtilProxy::Touch( |
304 operation_context_.get(), src_util_, url, | 303 operation_context(), src_util_, url, |
305 last_access_time, last_modified_time, | 304 last_access_time, last_modified_time, |
306 base::Bind(&LocalFileSystemOperation::DidTouchFile, | 305 base::Bind(&LocalFileSystemOperation::DidTouchFile, |
307 base::Owned(this), callback)); | 306 base::Owned(this), callback)); |
308 } | 307 } |
309 | 308 |
310 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, | 309 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, |
311 int file_flags, | 310 int file_flags, |
312 base::ProcessHandle peer_handle, | 311 base::ProcessHandle peer_handle, |
313 const OpenFileCallback& callback) { | 312 const OpenFileCallback& callback) { |
314 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 313 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, | 397 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, |
399 FilePath* platform_path) { | 398 FilePath* platform_path) { |
400 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); | 399 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); |
401 | 400 |
402 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 401 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
403 if (result != base::PLATFORM_FILE_OK) { | 402 if (result != base::PLATFORM_FILE_OK) { |
404 delete this; | 403 delete this; |
405 return; | 404 return; |
406 } | 405 } |
407 | 406 |
408 src_util_->GetLocalFilePath(operation_context_.get(), url, platform_path); | 407 src_util_->GetLocalFilePath(operation_context(), url, platform_path); |
409 | 408 |
410 delete this; | 409 delete this; |
411 } | 410 } |
412 | 411 |
413 void LocalFileSystemOperation::CreateSnapshotFile( | 412 void LocalFileSystemOperation::CreateSnapshotFile( |
414 const FileSystemURL& url, | 413 const FileSystemURL& url, |
415 const SnapshotFileCallback& callback) { | 414 const SnapshotFileCallback& callback) { |
416 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); | 415 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); |
417 | 416 |
418 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 417 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); |
419 if (result != base::PLATFORM_FILE_OK) { | 418 if (result != base::PLATFORM_FILE_OK) { |
420 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); | 419 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); |
421 delete this; | 420 delete this; |
422 return; | 421 return; |
423 } | 422 } |
424 | 423 |
425 FileSystemFileUtilProxy::CreateSnapshotFile( | 424 FileSystemFileUtilProxy::CreateSnapshotFile( |
426 operation_context_.get(), src_util_, url, | 425 operation_context(), src_util_, url, |
427 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, | 426 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, |
428 base::Owned(this), callback)); | 427 base::Owned(this), callback)); |
429 } | 428 } |
430 | 429 |
431 void LocalFileSystemOperation::CopyInForeignFile( | 430 void LocalFileSystemOperation::CopyInForeignFile( |
432 const FilePath& src_local_disk_file_path, | 431 const FilePath& src_local_disk_file_path, |
433 const FileSystemURL& dest_url, | 432 const FileSystemURL& dest_url, |
434 const StatusCallback& callback) { | 433 const StatusCallback& callback) { |
435 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 434 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
436 | 435 |
437 base::PlatformFileError result = SetUp( | 436 base::PlatformFileError result = SetUp( |
438 dest_url, &dest_util_, SETUP_FOR_CREATE); | 437 dest_url, &dest_util_, SETUP_FOR_CREATE); |
439 if (result != base::PLATFORM_FILE_OK) { | 438 if (result != base::PLATFORM_FILE_OK) { |
440 callback.Run(result); | 439 callback.Run(result); |
441 delete this; | 440 delete this; |
442 return; | 441 return; |
443 } | 442 } |
444 | 443 |
445 GetUsageAndQuotaThenRunTask( | 444 GetUsageAndQuotaThenRunTask( |
446 dest_url, | 445 dest_url, |
447 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, | 446 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, |
448 base::Unretained(this), src_local_disk_file_path, dest_url, | 447 base::Unretained(this), src_local_disk_file_path, dest_url, |
449 callback), | 448 callback), |
450 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 449 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
451 } | 450 } |
452 | 451 |
| 452 void LocalFileSystemOperation::RemoveFile( |
| 453 const FileSystemURL& url, |
| 454 const StatusCallback& callback) { |
| 455 DCHECK(SetPendingOperationType(kOperationRemove)); |
| 456 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); |
| 457 if (result != base::PLATFORM_FILE_OK) { |
| 458 callback.Run(result); |
| 459 delete this; |
| 460 return; |
| 461 } |
| 462 |
| 463 FileSystemFileUtilProxy::DeleteFile( |
| 464 operation_context(), src_util_, url, |
| 465 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 466 base::Owned(this), callback)); |
| 467 } |
| 468 |
| 469 void LocalFileSystemOperation::RemoveDirectory( |
| 470 const FileSystemURL& url, |
| 471 const StatusCallback& callback) { |
| 472 DCHECK(SetPendingOperationType(kOperationRemove)); |
| 473 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); |
| 474 if (result != base::PLATFORM_FILE_OK) { |
| 475 callback.Run(result); |
| 476 delete this; |
| 477 return; |
| 478 } |
| 479 |
| 480 FileSystemFileUtilProxy::DeleteDirectory( |
| 481 operation_context(), src_util_, url, |
| 482 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 483 base::Owned(this), callback)); |
| 484 } |
| 485 |
453 LocalFileSystemOperation::LocalFileSystemOperation( | 486 LocalFileSystemOperation::LocalFileSystemOperation( |
454 FileSystemContext* file_system_context, | 487 FileSystemContext* file_system_context, |
455 scoped_ptr<FileSystemOperationContext> operation_context) | 488 scoped_ptr<FileSystemOperationContext> operation_context) |
456 : file_system_context_(file_system_context), | 489 : file_system_context_(file_system_context), |
457 operation_context_(operation_context.Pass()), | 490 operation_context_(operation_context.Pass()), |
458 src_util_(NULL), | 491 src_util_(NULL), |
459 dest_util_(NULL), | 492 dest_util_(NULL), |
| 493 overriding_operation_context_(NULL), |
460 is_cross_operation_(false), | 494 is_cross_operation_(false), |
461 peer_handle_(base::kNullProcessHandle), | 495 peer_handle_(base::kNullProcessHandle), |
462 pending_operation_(kOperationNone), | 496 pending_operation_(kOperationNone), |
463 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 497 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
464 DCHECK(operation_context_.get()); | 498 DCHECK(operation_context_.get()); |
465 } | 499 } |
466 | 500 |
467 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( | 501 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( |
468 const FileSystemURL& url, | 502 const FileSystemURL& url, |
469 const base::Closure& task, | 503 const base::Closure& task, |
470 const base::Closure& error_callback) { | 504 const base::Closure& error_callback) { |
471 quota::QuotaManagerProxy* quota_manager_proxy = | 505 quota::QuotaManagerProxy* quota_manager_proxy = |
472 file_system_context()->quota_manager_proxy(); | 506 file_system_context()->quota_manager_proxy(); |
473 if (!quota_manager_proxy || | 507 if (!quota_manager_proxy || |
474 !file_system_context()->GetQuotaUtil(url.type())) { | 508 !file_system_context()->GetQuotaUtil(url.type())) { |
475 // If we don't have the quota manager or the requested filesystem type | 509 // If we don't have the quota manager or the requested filesystem type |
476 // does not support quota, we should be able to let it go. | 510 // does not support quota, we should be able to let it go. |
477 operation_context_->set_allowed_bytes_growth(kint64max); | 511 operation_context()->set_allowed_bytes_growth(kint64max); |
478 task.Run(); | 512 task.Run(); |
479 return; | 513 return; |
480 } | 514 } |
481 | 515 |
482 DCHECK(quota_manager_proxy); | 516 DCHECK(quota_manager_proxy); |
483 DCHECK(quota_manager_proxy->quota_manager()); | 517 DCHECK(quota_manager_proxy->quota_manager()); |
484 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 518 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
485 url.origin(), | 519 url.origin(), |
486 FileSystemTypeToQuotaStorageType(url.type()), | 520 FileSystemTypeToQuotaStorageType(url.type()), |
487 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask, | 521 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask, |
488 weak_factory_.GetWeakPtr(), task, error_callback)); | 522 weak_factory_.GetWeakPtr(), task, error_callback)); |
489 } | 523 } |
490 | 524 |
491 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask( | 525 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask( |
492 const base::Closure& task, | 526 const base::Closure& task, |
493 const base::Closure& error_callback, | 527 const base::Closure& error_callback, |
494 quota::QuotaStatusCode status, | 528 quota::QuotaStatusCode status, |
495 int64 usage, int64 quota) { | 529 int64 usage, int64 quota) { |
496 if (status != quota::kQuotaStatusOk) { | 530 if (status != quota::kQuotaStatusOk) { |
497 LOG(WARNING) << "Got unexpected quota error : " << status; | 531 LOG(WARNING) << "Got unexpected quota error : " << status; |
498 error_callback.Run(); | 532 error_callback.Run(); |
499 return; | 533 return; |
500 } | 534 } |
501 | 535 |
502 operation_context_->set_allowed_bytes_growth(quota - usage); | 536 operation_context()->set_allowed_bytes_growth(quota - usage); |
503 task.Run(); | 537 task.Run(); |
504 } | 538 } |
505 | 539 |
506 base::Closure LocalFileSystemOperation::GetWriteClosure( | 540 base::Closure LocalFileSystemOperation::GetWriteClosure( |
507 const net::URLRequestContext* url_request_context, | 541 const net::URLRequestContext* url_request_context, |
508 const FileSystemURL& url, | 542 const FileSystemURL& url, |
509 const GURL& blob_url, | 543 const GURL& blob_url, |
510 int64 offset, | 544 int64 offset, |
511 const WriteCallback& callback) { | 545 const WriteCallback& callback) { |
512 DCHECK(SetPendingOperationType(kOperationWrite)); | 546 DCHECK(SetPendingOperationType(kOperationWrite)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 const WriteCallback& callback, | 583 const WriteCallback& callback, |
550 base::PlatformFileError result) { | 584 base::PlatformFileError result) { |
551 callback.Run(result, 0, false); | 585 callback.Run(result, 0, false); |
552 } | 586 } |
553 | 587 |
554 void LocalFileSystemOperation::DoCreateFile( | 588 void LocalFileSystemOperation::DoCreateFile( |
555 const FileSystemURL& url, | 589 const FileSystemURL& url, |
556 const StatusCallback& callback, | 590 const StatusCallback& callback, |
557 bool exclusive) { | 591 bool exclusive) { |
558 FileSystemFileUtilProxy::EnsureFileExists( | 592 FileSystemFileUtilProxy::EnsureFileExists( |
559 operation_context_.get(), | 593 operation_context(), |
560 src_util_, url, | 594 src_util_, url, |
561 base::Bind( | 595 base::Bind( |
562 exclusive ? | 596 exclusive ? |
563 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : | 597 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : |
564 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, | 598 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, |
565 base::Owned(this), callback)); | 599 base::Owned(this), callback)); |
566 } | 600 } |
567 | 601 |
568 void LocalFileSystemOperation::DoCreateDirectory( | 602 void LocalFileSystemOperation::DoCreateDirectory( |
569 const FileSystemURL& url, | 603 const FileSystemURL& url, |
570 const StatusCallback& callback, | 604 const StatusCallback& callback, |
571 bool exclusive, bool recursive) { | 605 bool exclusive, bool recursive) { |
572 FileSystemFileUtilProxy::CreateDirectory( | 606 FileSystemFileUtilProxy::CreateDirectory( |
573 operation_context_.get(), | 607 operation_context(), |
574 src_util_, url, exclusive, recursive, | 608 src_util_, url, exclusive, recursive, |
575 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 609 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
576 base::Owned(this), callback)); | 610 base::Owned(this), callback)); |
577 } | 611 } |
578 | 612 |
579 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url, | 613 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url, |
580 const FileSystemURL& dest_url, | 614 const FileSystemURL& dest_url, |
581 const StatusCallback& callback) { | 615 const StatusCallback& callback) { |
582 FileSystemFileUtilProxy::Copy( | 616 FileSystemFileUtilProxy::Copy( |
583 operation_context_.get(), | 617 operation_context(), |
584 src_util_, dest_util_, | 618 src_util_, dest_util_, |
585 src_url, dest_url, | 619 src_url, dest_url, |
586 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 620 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
587 base::Owned(this), callback)); | 621 base::Owned(this), callback)); |
588 } | 622 } |
589 | 623 |
590 void LocalFileSystemOperation::DoCopyInForeignFile( | 624 void LocalFileSystemOperation::DoCopyInForeignFile( |
591 const FilePath& src_local_disk_file_path, | 625 const FilePath& src_local_disk_file_path, |
592 const FileSystemURL& dest_url, | 626 const FileSystemURL& dest_url, |
593 const StatusCallback& callback) { | 627 const StatusCallback& callback) { |
594 FileSystemFileUtilProxy::CopyInForeignFile( | 628 FileSystemFileUtilProxy::CopyInForeignFile( |
595 operation_context_.get(), | 629 operation_context(), |
596 dest_util_, | 630 dest_util_, |
597 src_local_disk_file_path, dest_url, | 631 src_local_disk_file_path, dest_url, |
598 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 632 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
599 base::Owned(this), callback)); | 633 base::Owned(this), callback)); |
600 } | 634 } |
601 | 635 |
602 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url, | 636 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url, |
603 const FileSystemURL& dest_url, | 637 const FileSystemURL& dest_url, |
604 const StatusCallback& callback) { | 638 const StatusCallback& callback) { |
605 FileSystemFileUtilProxy::Move( | 639 FileSystemFileUtilProxy::Move( |
606 operation_context_.get(), | 640 operation_context(), |
607 src_util_, dest_util_, | 641 src_util_, dest_util_, |
608 src_url, dest_url, | 642 src_url, dest_url, |
609 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 643 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
610 base::Owned(this), callback)); | 644 base::Owned(this), callback)); |
611 } | 645 } |
612 | 646 |
613 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, | 647 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, |
614 const StatusCallback& callback, | 648 const StatusCallback& callback, |
615 int64 length) { | 649 int64 length) { |
616 FileSystemFileUtilProxy::Truncate( | 650 FileSystemFileUtilProxy::Truncate( |
617 operation_context_.get(), src_util_, url, length, | 651 operation_context(), src_util_, url, length, |
618 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 652 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
619 base::Owned(this), callback)); | 653 base::Owned(this), callback)); |
620 } | 654 } |
621 | 655 |
622 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, | 656 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, |
623 const OpenFileCallback& callback, | 657 const OpenFileCallback& callback, |
624 int file_flags) { | 658 int file_flags) { |
625 FileSystemFileUtilProxy::CreateOrOpen( | 659 FileSystemFileUtilProxy::CreateOrOpen( |
626 operation_context_.get(), src_util_, url, file_flags, | 660 operation_context(), src_util_, url, file_flags, |
627 base::Bind(&LocalFileSystemOperation::DidOpenFile, | 661 base::Bind(&LocalFileSystemOperation::DidOpenFile, |
628 base::Owned(this), callback)); | 662 base::Owned(this), callback)); |
629 } | 663 } |
630 | 664 |
631 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( | 665 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( |
632 const StatusCallback& callback, | 666 const StatusCallback& callback, |
633 base::PlatformFileError rv, bool created) { | 667 base::PlatformFileError rv, bool created) { |
634 if (rv == base::PLATFORM_FILE_OK && !created) { | 668 if (rv == base::PLATFORM_FILE_OK && !created) { |
635 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); | 669 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); |
636 } else { | 670 } else { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 if (write_callback_.is_null()) { | 736 if (write_callback_.is_null()) { |
703 // If cancelled, callback is already invoked and set to null in Cancel(). | 737 // If cancelled, callback is already invoked and set to null in Cancel(). |
704 // We must not call it twice. Just shut down this operation object. | 738 // We must not call it twice. Just shut down this operation object. |
705 delete this; | 739 delete this; |
706 return; | 740 return; |
707 } | 741 } |
708 | 742 |
709 const bool complete = ( | 743 const bool complete = ( |
710 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); | 744 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); |
711 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { | 745 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { |
712 operation_context_->change_observers()->Notify( | 746 operation_context()->change_observers()->Notify( |
713 &FileChangeObserver::OnModifyFile, MakeTuple(url)); | 747 &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
714 } | 748 } |
715 | 749 |
716 write_callback_.Run(rv, bytes, complete); | 750 write_callback_.Run(rv, bytes, complete); |
717 if (complete || rv != base::PLATFORM_FILE_OK) | 751 if (complete || rv != base::PLATFORM_FILE_OK) |
718 delete this; | 752 delete this; |
719 } | 753 } |
720 | 754 |
721 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback, | 755 void LocalFileSystemOperation::DidTouchFile(const StatusCallback& callback, |
722 base::PlatformFileError rv) { | 756 base::PlatformFileError rv) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 FileSystemFileUtil** file_util, | 788 FileSystemFileUtil** file_util, |
755 SetUpMode mode) { | 789 SetUpMode mode) { |
756 if (!url.is_valid()) | 790 if (!url.is_valid()) |
757 return base::PLATFORM_FILE_ERROR_INVALID_URL; | 791 return base::PLATFORM_FILE_ERROR_INVALID_URL; |
758 | 792 |
759 // Restricted file system is read-only. | 793 // Restricted file system is read-only. |
760 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal && | 794 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal && |
761 mode != SETUP_FOR_READ) | 795 mode != SETUP_FOR_READ) |
762 return base::PLATFORM_FILE_ERROR_SECURITY; | 796 return base::PLATFORM_FILE_ERROR_SECURITY; |
763 | 797 |
764 if (!file_system_context()->GetMountPointProvider( | |
765 url.type())->IsAccessAllowed(url)) | |
766 return base::PLATFORM_FILE_ERROR_SECURITY; | |
767 | |
768 DCHECK(file_util); | 798 DCHECK(file_util); |
769 if (!*file_util) | 799 if (!*file_util) |
770 *file_util = file_system_context()->GetFileUtil(url.type()); | 800 *file_util = file_system_context()->GetFileUtil(url.type()); |
771 if (!*file_util) | 801 if (!*file_util) |
772 return base::PLATFORM_FILE_ERROR_SECURITY; | 802 return base::PLATFORM_FILE_ERROR_SECURITY; |
773 | 803 |
| 804 // If this operation is created for recursive sub-operations (i.e. |
| 805 // operation context is overridden from another operation) we skip |
| 806 // some duplicated security checks. |
| 807 if (overriding_operation_context_) |
| 808 return base::PLATFORM_FILE_OK; |
| 809 |
| 810 if (!file_system_context()->GetMountPointProvider( |
| 811 url.type())->IsAccessAllowed(url)) |
| 812 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 813 |
774 if (mode == SETUP_FOR_READ) { | 814 if (mode == SETUP_FOR_READ) { |
775 // TODO(kinuko): This doesn't work well for cross-filesystem operation | 815 // TODO(kinuko): This doesn't work well for cross-filesystem operation |
776 // in the current architecture since the operation context (thus the | 816 // in the current architecture since the operation context (thus the |
777 // observers) is configured for the destination URL while this method | 817 // observers) is configured for the destination URL while this method |
778 // could be called for both src and dest URL. | 818 // could be called for both src and dest URL. |
779 if (!is_cross_operation_) { | 819 if (!is_cross_operation_) { |
780 operation_context_->access_observers()->Notify( | 820 operation_context()->access_observers()->Notify( |
781 &FileAccessObserver::OnAccess, MakeTuple(url)); | 821 &FileAccessObserver::OnAccess, MakeTuple(url)); |
782 } | 822 } |
783 return base::PLATFORM_FILE_OK; | 823 return base::PLATFORM_FILE_OK; |
784 } | 824 } |
785 | 825 |
786 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); | 826 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); |
787 | 827 |
788 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( | 828 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( |
789 operation_context_.get(), url)); | 829 operation_context(), url)); |
790 | 830 |
791 // Any write access is disallowed on the root path. | 831 // Any write access is disallowed on the root path. |
792 if (url.path().value().length() == 0 || | 832 if (url.path().value().length() == 0 || |
793 url.path().DirName().value() == url.path().value()) | 833 url.path().DirName().value() == url.path().value()) |
794 return base::PLATFORM_FILE_ERROR_SECURITY; | 834 return base::PLATFORM_FILE_ERROR_SECURITY; |
795 | 835 |
796 if (mode == SETUP_FOR_CREATE) { | 836 if (mode == SETUP_FOR_CREATE) { |
797 FileSystemMountPointProvider* provider = file_system_context()-> | 837 FileSystemMountPointProvider* provider = file_system_context()-> |
798 GetMountPointProvider(url.type()); | 838 GetMountPointProvider(url.type()); |
799 | 839 |
800 // Check if the cracked file name looks good to create. | 840 // Check if the cracked file name looks good to create. |
801 if (provider->IsRestrictedFileName(VirtualPath::BaseName(url.path()))) | 841 if (provider->IsRestrictedFileName(VirtualPath::BaseName(url.path()))) |
802 return base::PLATFORM_FILE_ERROR_SECURITY; | 842 return base::PLATFORM_FILE_ERROR_SECURITY; |
803 } | 843 } |
804 | 844 |
805 return base::PLATFORM_FILE_OK; | 845 return base::PLATFORM_FILE_OK; |
806 } | 846 } |
807 | 847 |
808 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 848 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
809 if (pending_operation_ != kOperationNone) | 849 if (pending_operation_ != kOperationNone) |
810 return false; | 850 return false; |
811 pending_operation_ = type; | 851 pending_operation_ = type; |
812 return true; | 852 return true; |
813 } | 853 } |
814 | 854 |
815 } // namespace fileapi | 855 } // namespace fileapi |
OLD | NEW |