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/obfuscated_file_system_file_util.h" | 5 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <vector> | |
8 | 9 |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
15 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
16 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 #include "webkit/fileapi/file_system_context.h" | 19 #include "webkit/fileapi/file_system_context.h" |
19 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
20 #include "webkit/fileapi/file_system_path_manager.h" | 21 #include "webkit/fileapi/file_system_path_manager.h" |
22 #include "webkit/fileapi/file_system_util.h" | |
21 #include "webkit/fileapi/quota_file_util.h" | 23 #include "webkit/fileapi/quota_file_util.h" |
22 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
23 | 25 |
24 // TODO(ericu): Every instance of FileSystemFileUtil in this file should switch | 26 // TODO(ericu): Make deleting an origin [or a type under the origin, if it's the |
25 // to QuotaFileUtil as soon as I sort out FileSystemPathManager's and | 27 // last type] remove the origin from origin_database_ as well. |
26 // SandboxMountPointProvider's lookups of the root path for a filesystem. | |
27 namespace { | 28 namespace { |
28 | 29 |
29 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes | 30 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes |
30 | 31 |
31 const char kOriginDatabaseName[] = "Origins"; | 32 const char kOriginDatabaseName[] = "Origins"; |
32 const char kDirectoryDatabaseName[] = "Paths"; | 33 const char kDirectoryDatabaseName[] = "Paths"; |
33 | 34 |
34 void InitFileInfo( | 35 void InitFileInfo( |
35 fileapi::FileSystemDirectoryDatabase::FileInfo* file_info, | 36 fileapi::FileSystemDirectoryDatabase::FileInfo* file_info, |
36 fileapi::FileSystemDirectoryDatabase::FileId parent_id, | 37 fileapi::FileSystemDirectoryDatabase::FileId parent_id, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 96 |
96 FileInfo file_info; | 97 FileInfo file_info; |
97 if (!db->GetFileInfo(file_id, &file_info)) { | 98 if (!db->GetFileInfo(file_id, &file_info)) { |
98 NOTREACHED(); | 99 NOTREACHED(); |
99 return base::PLATFORM_FILE_ERROR_FAILED; | 100 return base::PLATFORM_FILE_ERROR_FAILED; |
100 } | 101 } |
101 if (file_info.is_directory()) | 102 if (file_info.is_directory()) |
102 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 103 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
103 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 104 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
104 context->src_type(), file_info.data_path); | 105 context->src_type(), file_info.data_path); |
105 return FileSystemFileUtil::GetInstance()->CreateOrOpen( | 106 return QuotaFileUtil::GetInstance()->CreateOrOpen( |
106 context, data_path, file_flags, file_handle, created); | 107 context, data_path, file_flags, file_handle, created); |
107 } | 108 } |
108 | 109 |
109 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( | 110 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( |
110 FileSystemOperationContext* context, | 111 FileSystemOperationContext* context, |
111 const FilePath& virtual_path, | 112 const FilePath& virtual_path, |
112 bool* created) { | 113 bool* created) { |
113 FileSystemDirectoryDatabase* db = | 114 FileSystemDirectoryDatabase* db = |
114 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 115 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
115 if (!db) | 116 if (!db) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 file_info->is_symbolic_link = false; | 177 file_info->is_symbolic_link = false; |
177 file_info->last_modified = local_info.modification_time; | 178 file_info->last_modified = local_info.modification_time; |
178 *platform_file_path = FilePath(); | 179 *platform_file_path = FilePath(); |
179 // We don't fill in ctime or atime. | 180 // We don't fill in ctime or atime. |
180 return base::PLATFORM_FILE_OK; | 181 return base::PLATFORM_FILE_OK; |
181 } | 182 } |
182 if (local_info.data_path.empty()) | 183 if (local_info.data_path.empty()) |
183 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 184 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
184 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 185 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
185 context->src_type(), local_info.data_path); | 186 context->src_type(), local_info.data_path); |
186 return FileSystemFileUtil::GetInstance()->GetFileInfo( | 187 return QuotaFileUtil::GetInstance()->GetFileInfo( |
187 context, data_path, file_info, platform_file_path); | 188 context, data_path, file_info, platform_file_path); |
188 } | 189 } |
189 | 190 |
190 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( | 191 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( |
191 FileSystemOperationContext* context, | 192 FileSystemOperationContext* context, |
192 const FilePath& virtual_path, | 193 const FilePath& virtual_path, |
193 std::vector<base::FileUtilProxy::Entry>* entries) { | 194 std::vector<base::FileUtilProxy::Entry>* entries) { |
194 // TODO(kkanetkar): Implement directory read in multiple chunks. | 195 // TODO(kkanetkar): Implement directory read in multiple chunks. |
195 FileSystemDirectoryDatabase* db = | 196 FileSystemDirectoryDatabase* db = |
196 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 197 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 * Delete target entry's old backing file | 324 * Delete target entry's old backing file |
324 * Move-without-overwrite | 325 * Move-without-overwrite |
325 * Just update metadata | 326 * Just update metadata |
326 */ | 327 */ |
327 if (copy) { | 328 if (copy) { |
328 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), | 329 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), |
329 context->src_type(), src_file_info.data_path); | 330 context->src_type(), src_file_info.data_path); |
330 if (overwrite) { | 331 if (overwrite) { |
331 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 332 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
332 context->src_type(), dest_file_info.data_path); | 333 context->src_type(), dest_file_info.data_path); |
333 return FileSystemFileUtil::GetInstance()->CopyOrMoveFile(context, | 334 return QuotaFileUtil::GetInstance()->CopyOrMoveFile(context, |
334 src_data_path, dest_data_path, copy); | 335 src_data_path, dest_data_path, copy); |
335 } else { | 336 } else { |
336 FileId dest_parent_id; | 337 FileId dest_parent_id; |
337 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 338 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
338 NOTREACHED(); // We shouldn't be called in this case. | 339 NOTREACHED(); // We shouldn't be called in this case. |
339 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 340 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
340 } | 341 } |
341 InitFileInfo(&dest_file_info, dest_parent_id, | 342 InitFileInfo(&dest_file_info, dest_parent_id, |
342 dest_file_path.BaseName().value()); | 343 dest_file_path.BaseName().value()); |
343 return CreateFile(context, context->dest_origin_url(), | 344 return CreateFile(context, context->dest_origin_url(), |
344 context->dest_type(), src_data_path, &dest_file_info, 0, | 345 context->dest_type(), src_data_path, &dest_file_info, 0, |
345 NULL); | 346 NULL); |
346 } | 347 } |
347 } else { // It's a move. | 348 } else { // It's a move. |
348 if (overwrite) { | 349 if (overwrite) { |
349 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) | 350 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) |
350 return base::PLATFORM_FILE_ERROR_FAILED; | 351 return base::PLATFORM_FILE_ERROR_FAILED; |
351 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 352 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
352 context->src_type(), dest_file_info.data_path); | 353 context->src_type(), dest_file_info.data_path); |
353 if (base::PLATFORM_FILE_OK != | 354 if (base::PLATFORM_FILE_OK != |
354 FileSystemFileUtil::GetInstance()->DeleteFile( | 355 QuotaFileUtil::GetInstance()->DeleteFile(context, dest_data_path)) |
355 context, dest_data_path)) | |
356 LOG(WARNING) << "Leaked a backing file."; | 356 LOG(WARNING) << "Leaked a backing file."; |
357 return base::PLATFORM_FILE_OK; | 357 return base::PLATFORM_FILE_OK; |
358 } else { | 358 } else { |
359 FileId dest_parent_id; | 359 FileId dest_parent_id; |
360 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 360 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
361 NOTREACHED(); | 361 NOTREACHED(); |
362 return base::PLATFORM_FILE_ERROR_FAILED; | 362 return base::PLATFORM_FILE_ERROR_FAILED; |
363 } | 363 } |
364 src_file_info.parent_id = dest_parent_id; | 364 src_file_info.parent_id = dest_parent_id; |
365 src_file_info.name = dest_file_path.BaseName().value(); | 365 src_file_info.name = dest_file_path.BaseName().value(); |
(...skipping 21 matching lines...) Expand all Loading... | |
387 NOTREACHED(); | 387 NOTREACHED(); |
388 return base::PLATFORM_FILE_ERROR_FAILED; | 388 return base::PLATFORM_FILE_ERROR_FAILED; |
389 } | 389 } |
390 if (!db->RemoveFileInfo(file_id)) { | 390 if (!db->RemoveFileInfo(file_id)) { |
391 NOTREACHED(); | 391 NOTREACHED(); |
392 return base::PLATFORM_FILE_ERROR_FAILED; | 392 return base::PLATFORM_FILE_ERROR_FAILED; |
393 } | 393 } |
394 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 394 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
395 context->src_type(), file_info.data_path); | 395 context->src_type(), file_info.data_path); |
396 if (base::PLATFORM_FILE_OK != | 396 if (base::PLATFORM_FILE_OK != |
397 FileSystemFileUtil::GetInstance()->DeleteFile(context, data_path)) | 397 QuotaFileUtil::GetInstance()->DeleteFile(context, data_path)) |
398 LOG(WARNING) << "Leaked a backing file."; | 398 LOG(WARNING) << "Leaked a backing file."; |
399 return base::PLATFORM_FILE_OK; | 399 return base::PLATFORM_FILE_OK; |
400 } | 400 } |
401 | 401 |
402 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( | 402 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( |
403 FileSystemOperationContext* context, | 403 FileSystemOperationContext* context, |
404 const FilePath& virtual_path) { | 404 const FilePath& virtual_path) { |
405 FileSystemDirectoryDatabase* db = | 405 FileSystemDirectoryDatabase* db = |
406 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 406 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
407 if (!db) | 407 if (!db) |
(...skipping 28 matching lines...) Expand all Loading... | |
436 return base::PLATFORM_FILE_ERROR_FAILED; | 436 return base::PLATFORM_FILE_ERROR_FAILED; |
437 } | 437 } |
438 if (file_info.is_directory()) { | 438 if (file_info.is_directory()) { |
439 file_info.modification_time = last_modified_time; | 439 file_info.modification_time = last_modified_time; |
440 if (!db->UpdateFileInfo(file_id, file_info)) | 440 if (!db->UpdateFileInfo(file_id, file_info)) |
441 return base::PLATFORM_FILE_ERROR_FAILED; | 441 return base::PLATFORM_FILE_ERROR_FAILED; |
442 return base::PLATFORM_FILE_OK; | 442 return base::PLATFORM_FILE_OK; |
443 } | 443 } |
444 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 444 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
445 context->src_type(), file_info.data_path); | 445 context->src_type(), file_info.data_path); |
446 return FileSystemFileUtil::GetInstance()->Touch( | 446 return QuotaFileUtil::GetInstance()->Touch( |
447 context, data_path, last_access_time, last_modified_time); | 447 context, data_path, last_access_time, last_modified_time); |
448 } | 448 } |
449 FileId parent_id; | 449 FileId parent_id; |
450 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) | 450 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) |
451 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 451 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
452 | 452 |
453 FileInfo file_info; | 453 FileInfo file_info; |
454 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); | 454 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); |
455 // In the event of a sporadic underlying failure, we might create a new file, | 455 // In the event of a sporadic underlying failure, we might create a new file, |
456 // but fail to update its mtime + atime. | 456 // but fail to update its mtime + atime. |
457 PlatformFileError error = CreateFile(context, context->src_origin_url(), | 457 PlatformFileError error = CreateFile(context, context->src_origin_url(), |
458 context->src_type(), FilePath(), &file_info, 0, NULL); | 458 context->src_type(), FilePath(), &file_info, 0, NULL); |
459 if (base::PLATFORM_FILE_OK != error) | 459 if (base::PLATFORM_FILE_OK != error) |
460 return error; | 460 return error; |
461 | 461 |
462 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 462 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
463 context->src_type(), file_info.data_path); | 463 context->src_type(), file_info.data_path); |
464 return FileSystemFileUtil::GetInstance()->Touch(context, data_path, | 464 return QuotaFileUtil::GetInstance()->Touch(context, data_path, |
465 last_access_time, last_modified_time); | 465 last_access_time, last_modified_time); |
466 } | 466 } |
467 | 467 |
468 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( | 468 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( |
469 FileSystemOperationContext* context, | 469 FileSystemOperationContext* context, |
470 const FilePath& virtual_path, | 470 const FilePath& virtual_path, |
471 int64 length) { | 471 int64 length) { |
472 FilePath local_path = | 472 FilePath local_path = |
473 GetLocalPath(context->src_origin_url(), context->src_type(), | 473 GetLocalPath(context->src_origin_url(), context->src_type(), |
474 virtual_path); | 474 virtual_path); |
475 if (local_path.empty()) | 475 if (local_path.empty()) |
476 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 476 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
477 return FileSystemFileUtil::GetInstance()->Truncate( | 477 return QuotaFileUtil::GetInstance()->Truncate( |
478 context, local_path, length); | 478 context, local_path, length); |
479 } | 479 } |
480 | 480 |
481 bool ObfuscatedFileSystemFileUtil::PathExists( | 481 bool ObfuscatedFileSystemFileUtil::PathExists( |
482 FileSystemOperationContext* context, | 482 FileSystemOperationContext* context, |
483 const FilePath& virtual_path) { | 483 const FilePath& virtual_path) { |
484 FileSystemDirectoryDatabase* db = | 484 FileSystemDirectoryDatabase* db = |
485 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 485 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
486 if (!db) | 486 if (!db) |
487 return false; | 487 return false; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 } | 596 } |
597 } | 597 } |
598 } | 598 } |
599 | 599 |
600 std::queue<FileRecord> display_queue_; | 600 std::queue<FileRecord> display_queue_; |
601 std::queue<FileRecord> recurse_queue_; | 601 std::queue<FileRecord> recurse_queue_; |
602 FileRecord current_; | 602 FileRecord current_; |
603 FileSystemDirectoryDatabase* db_; | 603 FileSystemDirectoryDatabase* db_; |
604 }; | 604 }; |
605 | 605 |
606 class ObfuscatedFileSystemOriginEnumerator | |
607 : public ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator { | |
608 public: | |
609 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; | |
610 ObfuscatedFileSystemOriginEnumerator( | |
611 const std::vector<OriginRecord>& origins, | |
612 const FilePath& base_path) | |
613 : origins_(origins), base_path_(base_path) { | |
michaeln
2011/05/23 16:15:18
maybe avoid copying the 'origins' vector
ericu
2011/05/23 18:05:01
I could do this by making it swap() with the input
michaeln
2011/05/23 18:20:21
That would be a funky interface. You could pass a
ericu
2011/05/23 18:31:43
Oh, of course. That's a much better idea. Done.
| |
614 } | |
615 | |
616 ~ObfuscatedFileSystemOriginEnumerator() {} | |
617 | |
618 // Returns the next origin. Returns empty if there are no more origins. | |
619 virtual GURL Next() OVERRIDE { | |
620 OriginRecord record; | |
621 if (!origins_.empty()) { | |
622 record = origins_.back(); | |
623 origins_.pop_back(); | |
624 } | |
625 current_ = record; | |
626 return GetOriginURLFromIdentifier(record.first); | |
627 } | |
628 | |
629 // Returns the current origin's information. | |
630 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { | |
631 if (current_.second.empty()) | |
632 return false; | |
633 FilePath::StringType type_string = | |
634 ObfuscatedFileSystemFileUtil::GetDirectoryNameForType(type); | |
635 if (type_string.empty()) { | |
636 NOTREACHED(); | |
637 return false; | |
638 } | |
639 FilePath path = base_path_.Append(current_.second).Append(type_string); | |
640 return file_util::DirectoryExists(path); | |
641 } | |
642 | |
643 private: | |
644 std::vector<OriginRecord> origins_; | |
645 OriginRecord current_; | |
michaeln
2011/05/23 16:15:18
a comment about what .first and .second are would
ericu
2011/05/23 18:05:01
Changed to struct.
| |
646 FilePath base_path_; | |
647 }; | |
648 | |
649 ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator* | |
650 ObfuscatedFileSystemFileUtil::CreateOriginEnumerator() { | |
651 std::vector<FileSystemOriginDatabase::OriginRecord> origins; | |
652 | |
653 if (InitOriginDatabase(false)) | |
654 origin_database_->ListAllOrigins(&origins); | |
655 return new ObfuscatedFileSystemOriginEnumerator( | |
656 origins, file_system_directory_); | |
657 } | |
658 | |
606 FileSystemFileUtil::AbstractFileEnumerator* | 659 FileSystemFileUtil::AbstractFileEnumerator* |
607 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( | 660 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( |
608 FileSystemOperationContext* context, | 661 FileSystemOperationContext* context, |
609 const FilePath& root_path) { | 662 const FilePath& root_path) { |
610 FileSystemDirectoryDatabase* db = | 663 FileSystemDirectoryDatabase* db = |
611 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 664 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
612 if (!db) | 665 if (!db) |
613 return new FileSystemFileUtil::EmptyFileEnumerator(); | 666 return new FileSystemFileUtil::EmptyFileEnumerator(); |
614 return new ObfuscatedFileSystemFileEnumerator(db, root_path); | 667 return new ObfuscatedFileSystemFileEnumerator(db, root_path); |
615 } | 668 } |
(...skipping 10 matching lines...) Expand all Loading... | |
626 return base::PLATFORM_FILE_ERROR_FAILED; | 679 return base::PLATFORM_FILE_ERROR_FAILED; |
627 // We use the third- and fourth-to-last digits as the directory. | 680 // We use the third- and fourth-to-last digits as the directory. |
628 int64 directory_number = number % 10000 / 100; | 681 int64 directory_number = number % 10000 / 100; |
629 FilePath path = | 682 FilePath path = |
630 GetDirectoryForOriginAndType(origin_url, type, false); | 683 GetDirectoryForOriginAndType(origin_url, type, false); |
631 if (path.empty()) | 684 if (path.empty()) |
632 return base::PLATFORM_FILE_ERROR_FAILED; | 685 return base::PLATFORM_FILE_ERROR_FAILED; |
633 | 686 |
634 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number)); | 687 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number)); |
635 PlatformFileError error; | 688 PlatformFileError error; |
636 error = FileSystemFileUtil::GetInstance()->CreateDirectory( | 689 error = QuotaFileUtil::GetInstance()->CreateDirectory( |
637 context, path, false /* exclusive */, false /* recursive */); | 690 context, path, false /* exclusive */, false /* recursive */); |
638 if (base::PLATFORM_FILE_OK != error) | 691 if (base::PLATFORM_FILE_OK != error) |
639 return error; | 692 return error; |
640 path = path.AppendASCII(StringPrintf("%08" PRIu64, number)); | 693 path = path.AppendASCII(StringPrintf("%08" PRIu64, number)); |
641 FilePath data_path = LocalPathToDataPath(origin_url, type, path); | 694 FilePath data_path = LocalPathToDataPath(origin_url, type, path); |
642 if (data_path.empty()) | 695 if (data_path.empty()) |
643 return base::PLATFORM_FILE_ERROR_FAILED; | 696 return base::PLATFORM_FILE_ERROR_FAILED; |
644 bool created = false; | 697 bool created = false; |
645 if (!source_path.empty()) { | 698 if (!source_path.empty()) { |
646 DCHECK(!file_flags); | 699 DCHECK(!file_flags); |
647 DCHECK(!handle); | 700 DCHECK(!handle); |
648 error = FileSystemFileUtil::GetInstance()->CopyOrMoveFile( | 701 error = QuotaFileUtil::GetInstance()->CopyOrMoveFile( |
649 context, source_path, path, true /* copy */); | 702 context, source_path, path, true /* copy */); |
650 created = true; | 703 created = true; |
651 } else { | 704 } else { |
652 if (handle) { | 705 if (handle) { |
653 error = FileSystemFileUtil::GetInstance()->CreateOrOpen( | 706 error = QuotaFileUtil::GetInstance()->CreateOrOpen( |
654 context, path, file_flags, handle, &created); | 707 context, path, file_flags, handle, &created); |
655 // If this succeeds, we must close handle on any subsequent error. | 708 // If this succeeds, we must close handle on any subsequent error. |
656 } else { | 709 } else { |
657 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. | 710 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. |
658 error = FileSystemFileUtil::GetInstance()->EnsureFileExists( | 711 error = QuotaFileUtil::GetInstance()->EnsureFileExists( |
659 context, path, &created); | 712 context, path, &created); |
660 } | 713 } |
661 } | 714 } |
662 if (error != base::PLATFORM_FILE_OK) | 715 if (error != base::PLATFORM_FILE_OK) |
663 return error; | 716 return error; |
664 | 717 |
665 if (!created) { | 718 if (!created) { |
666 NOTREACHED(); | 719 NOTREACHED(); |
667 if (handle) { | 720 if (handle) { |
668 base::ClosePlatformFile(*handle); | 721 base::ClosePlatformFile(*handle); |
669 FileSystemFileUtil::GetInstance()->DeleteFile(context, path); | 722 QuotaFileUtil::GetInstance()->DeleteFile(context, path); |
670 } | 723 } |
671 return base::PLATFORM_FILE_ERROR_FAILED; | 724 return base::PLATFORM_FILE_ERROR_FAILED; |
672 } | 725 } |
673 file_info->data_path = data_path; | 726 file_info->data_path = data_path; |
674 FileId file_id; | 727 FileId file_id; |
675 if (!db->AddFileInfo(*file_info, &file_id)) { | 728 if (!db->AddFileInfo(*file_info, &file_id)) { |
676 if (handle) | 729 if (handle) |
677 base::ClosePlatformFile(*handle); | 730 base::ClosePlatformFile(*handle); |
678 FileSystemFileUtil::GetInstance()->DeleteFile(context, path); | 731 QuotaFileUtil::GetInstance()->DeleteFile(context, path); |
679 return base::PLATFORM_FILE_ERROR_FAILED; | 732 return base::PLATFORM_FILE_ERROR_FAILED; |
680 } | 733 } |
681 | 734 |
682 return base::PLATFORM_FILE_OK; | 735 return base::PLATFORM_FILE_OK; |
683 } | 736 } |
684 | 737 |
685 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( | 738 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( |
686 const GURL& origin_url, | 739 const GURL& origin_url, |
687 FileSystemType type, | 740 FileSystemType type, |
688 const FilePath& virtual_path) { | 741 const FilePath& virtual_path) { |
(...skipping 14 matching lines...) Expand all Loading... | |
703 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOriginAndType( | 756 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOriginAndType( |
704 const GURL& origin, FileSystemType type, bool create) { | 757 const GURL& origin, FileSystemType type, bool create) { |
705 FilePath origin_dir = GetDirectoryForOrigin(origin, create); | 758 FilePath origin_dir = GetDirectoryForOrigin(origin, create); |
706 if (origin_dir.empty()) | 759 if (origin_dir.empty()) |
707 return FilePath(); | 760 return FilePath(); |
708 FilePath::StringType type_string = GetDirectoryNameForType(type); | 761 FilePath::StringType type_string = GetDirectoryNameForType(type); |
709 if (type_string.empty()) { | 762 if (type_string.empty()) { |
710 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 763 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
711 return FilePath(); | 764 return FilePath(); |
712 } | 765 } |
713 return origin_dir.Append(type_string); | 766 FilePath path = origin_dir.Append(type_string); |
767 if (!file_util::DirectoryExists(path) && | |
768 (!create || !file_util::CreateDirectory(path))) | |
769 return FilePath(); | |
770 return path; | |
714 } | 771 } |
715 | 772 |
716 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( | 773 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( |
717 const GURL& origin, bool create) { | 774 const GURL& origin, bool create) { |
718 if (!origin_database_.get()) { | 775 if (!InitOriginDatabase(create)) |
719 if (!create && !file_util::DirectoryExists(file_system_directory_)) { | 776 return FilePath(); |
720 return FilePath(); | |
721 } | |
722 if (!file_util::CreateDirectory(file_system_directory_)) { | |
723 LOG(WARNING) << "Failed to create FileSystem directory: " << | |
724 file_system_directory_.value(); | |
725 return FilePath(); | |
726 } | |
727 origin_database_.reset( | |
728 new FileSystemOriginDatabase( | |
729 file_system_directory_.AppendASCII(kOriginDatabaseName))); | |
730 } | |
731 FilePath directory_name; | 777 FilePath directory_name; |
732 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from | 778 std::string id = GetOriginIdentifierFromURL(origin); |
733 // sandbox_mount_point_provider.cc, instead of just using origin.spec(). | 779 if (!create && !origin_database_->HasOriginPath(id)) |
734 if (!create && !origin_database_->HasOriginPath(origin.spec())) | |
735 return FilePath(); | 780 return FilePath(); |
736 if (!origin_database_->GetPathForOrigin(origin.spec(), &directory_name)) | 781 if (!origin_database_->GetPathForOrigin(id, &directory_name)) |
737 return FilePath(); | 782 return FilePath(); |
738 return file_system_directory_.Append(directory_name); | 783 FilePath path = file_system_directory_.Append(directory_name); |
784 if (!file_util::DirectoryExists(path) && | |
785 (!create || !file_util::CreateDirectory(path))) | |
786 return FilePath(); | |
787 return path; | |
739 } | 788 } |
740 | 789 |
741 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( | 790 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( |
742 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { | 791 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { |
743 if (!DestroyDirectoryDatabase(origin_url, type)) | 792 if (!DestroyDirectoryDatabase(origin_url, type)) |
744 return false; | 793 return false; |
745 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); | 794 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); |
746 if (dest_root.empty()) | 795 if (dest_root.empty()) |
747 return false; | 796 return false; |
748 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); | 797 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 NOTREACHED(); | 842 NOTREACHED(); |
794 return false; | 843 return false; |
795 } | 844 } |
796 } | 845 } |
797 // TODO(ericu): Should we adjust the mtime of the root directory to match as | 846 // TODO(ericu): Should we adjust the mtime of the root directory to match as |
798 // well? | 847 // well? |
799 FilePath legacy_dest_dir = dest_root.Append(kLegacyDataDirectory); | 848 FilePath legacy_dest_dir = dest_root.Append(kLegacyDataDirectory); |
800 return file_util::Move(src_root, legacy_dest_dir); | 849 return file_util::Move(src_root, legacy_dest_dir); |
801 } | 850 } |
802 | 851 |
852 // static | |
803 FilePath::StringType ObfuscatedFileSystemFileUtil::GetDirectoryNameForType( | 853 FilePath::StringType ObfuscatedFileSystemFileUtil::GetDirectoryNameForType( |
804 FileSystemType type) const { | 854 FileSystemType type) { |
805 switch (type) { | 855 switch (type) { |
806 case kFileSystemTypeTemporary: | 856 case kFileSystemTypeTemporary: |
807 return kTemporaryDirectoryName; | 857 return kTemporaryDirectoryName; |
808 case kFileSystemTypePersistent: | 858 case kFileSystemTypePersistent: |
809 return kPersistentDirectoryName; | 859 return kPersistentDirectoryName; |
810 case kFileSystemTypeUnknown: | 860 case kFileSystemTypeUnknown: |
811 default: | 861 default: |
812 return FilePath::StringType(); | 862 return FilePath::StringType(); |
813 } | 863 } |
814 } | 864 } |
(...skipping 22 matching lines...) Expand all Loading... | |
837 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( | 887 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( |
838 const GURL& origin, FileSystemType type) { | 888 const GURL& origin, FileSystemType type) { |
839 | 889 |
840 MarkUsed(); | 890 MarkUsed(); |
841 std::string type_string = | 891 std::string type_string = |
842 FileSystemPathManager::GetFileSystemTypeString(type); | 892 FileSystemPathManager::GetFileSystemTypeString(type); |
843 if (type_string.empty()) { | 893 if (type_string.empty()) { |
844 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 894 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
845 return NULL; | 895 return NULL; |
846 } | 896 } |
847 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from | 897 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
848 // sandbox_mount_point_provider.cc, instead of just using origin.spec(). | |
849 std::string key = origin.spec() + type_string; | |
850 DirectoryMap::iterator iter = directories_.find(key); | 898 DirectoryMap::iterator iter = directories_.find(key); |
851 if (iter != directories_.end()) | 899 if (iter != directories_.end()) |
852 return iter->second; | 900 return iter->second; |
853 | 901 |
854 FilePath path = GetDirectoryForOriginAndType(origin, type, true); | 902 FilePath path = GetDirectoryForOriginAndType(origin, type, true); |
855 if (path.empty()) | 903 if (path.empty()) |
856 return NULL; | 904 return NULL; |
857 if (!file_util::DirectoryExists(path)) { | 905 if (!file_util::DirectoryExists(path)) { |
858 if (!file_util::CreateDirectory(path)) { | 906 if (!file_util::CreateDirectory(path)) { |
859 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); | 907 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); |
(...skipping 22 matching lines...) Expand all Loading... | |
882 } | 930 } |
883 | 931 |
884 bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase( | 932 bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase( |
885 const GURL& origin, FileSystemType type) { | 933 const GURL& origin, FileSystemType type) { |
886 std::string type_string = | 934 std::string type_string = |
887 FileSystemPathManager::GetFileSystemTypeString(type); | 935 FileSystemPathManager::GetFileSystemTypeString(type); |
888 if (type_string.empty()) { | 936 if (type_string.empty()) { |
889 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 937 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
890 return true; | 938 return true; |
891 } | 939 } |
892 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from | 940 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
893 // sandbox_mount_point_provider.cc, instead of just using origin.spec(). | |
894 std::string key = origin.spec() + type_string; | |
895 DirectoryMap::iterator iter = directories_.find(key); | 941 DirectoryMap::iterator iter = directories_.find(key); |
896 if (iter != directories_.end()) | 942 if (iter != directories_.end()) |
897 directories_.erase(iter); | 943 directories_.erase(iter); |
898 | 944 |
899 FilePath path = GetDirectoryForOriginAndType(origin, type, false); | 945 FilePath path = GetDirectoryForOriginAndType(origin, type, false); |
900 if (path.empty()) | 946 if (path.empty()) |
901 return true; | 947 return true; |
902 if (!file_util::DirectoryExists(path)) | 948 if (!file_util::DirectoryExists(path)) |
903 return true; | 949 return true; |
904 path = path.AppendASCII(kDirectoryDatabaseName); | 950 path = path.AppendASCII(kDirectoryDatabaseName); |
905 return FileSystemDirectoryDatabase::DestroyDatabase(path); | 951 return FileSystemDirectoryDatabase::DestroyDatabase(path); |
906 } | 952 } |
907 | 953 |
954 bool ObfuscatedFileSystemFileUtil::InitOriginDatabase(bool create) { | |
955 if (!origin_database_.get()) { | |
956 if (!create && !file_util::DirectoryExists(file_system_directory_)) | |
957 return false; | |
958 if (!file_util::CreateDirectory(file_system_directory_)) { | |
959 LOG(WARNING) << "Failed to create FileSystem directory: " << | |
960 file_system_directory_.value(); | |
961 return false; | |
962 } | |
963 origin_database_.reset( | |
964 new FileSystemOriginDatabase( | |
965 file_system_directory_.AppendASCII(kOriginDatabaseName))); | |
966 } | |
967 return true; | |
968 } | |
969 | |
908 } // namespace fileapi | 970 } // namespace fileapi |
OLD | NEW |