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_util.h" | 5 #include "webkit/fileapi/obfuscated_file_util.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 int64 growth = GetPathQuotaUsage(growth_in_number_of_paths, | 85 int64 growth = GetPathQuotaUsage(growth_in_number_of_paths, |
86 growth_in_bytes_of_path_length); | 86 growth_in_bytes_of_path_length); |
87 fileapi::FileSystemQuotaUtil* quota_util = | 87 fileapi::FileSystemQuotaUtil* quota_util = |
88 context->file_system_context()->GetQuotaUtil(type); | 88 context->file_system_context()->GetQuotaUtil(type); |
89 quota::QuotaManagerProxy* quota_manager_proxy = | 89 quota::QuotaManagerProxy* quota_manager_proxy = |
90 context->file_system_context()->quota_manager_proxy(); | 90 context->file_system_context()->quota_manager_proxy(); |
91 quota_util->UpdateOriginUsageOnFileThread(quota_manager_proxy, origin_url, | 91 quota_util->UpdateOriginUsageOnFileThread(quota_manager_proxy, origin_url, |
92 type, growth); | 92 type, growth); |
93 } | 93 } |
94 | 94 |
95 void TouchDirectory(fileapi::FileSystemDirectoryDatabase* db, | |
96 fileapi::FileSystemDirectoryDatabase::FileId dir_id) { | |
97 DCHECK(db); | |
98 // Do nothing for root directory. | |
99 if (dir_id && !db->UpdateModificationTime(dir_id, base::Time::Now())) | |
100 NOTREACHED(); | |
101 } | |
102 | |
95 const FilePath::CharType kLegacyDataDirectory[] = FILE_PATH_LITERAL("Legacy"); | 103 const FilePath::CharType kLegacyDataDirectory[] = FILE_PATH_LITERAL("Legacy"); |
96 | 104 |
97 const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); | 105 const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); |
98 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); | 106 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); |
99 | 107 |
100 } // namespace | 108 } // namespace |
101 | 109 |
102 namespace fileapi { | 110 namespace fileapi { |
103 | 111 |
104 using base::PlatformFile; | 112 using base::PlatformFile; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 size_t index; | 392 size_t index; |
385 for (index = 0; index < components.size(); ++index) { | 393 for (index = 0; index < components.size(); ++index) { |
386 FilePath::StringType name = components[index]; | 394 FilePath::StringType name = components[index]; |
387 if (name == FILE_PATH_LITERAL("/")) | 395 if (name == FILE_PATH_LITERAL("/")) |
388 continue; | 396 continue; |
389 if (!db->GetChildWithName(parent_id, name, &parent_id)) | 397 if (!db->GetChildWithName(parent_id, name, &parent_id)) |
390 break; | 398 break; |
391 } | 399 } |
392 if (!recursive && components.size() - index > 1) | 400 if (!recursive && components.size() - index > 1) |
393 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 401 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
402 bool first = true; | |
394 for (; index < components.size(); ++index) { | 403 for (; index < components.size(); ++index) { |
395 FileInfo file_info; | 404 FileInfo file_info; |
396 file_info.name = components[index]; | 405 file_info.name = components[index]; |
397 if (file_info.name == FILE_PATH_LITERAL("/")) | 406 if (file_info.name == FILE_PATH_LITERAL("/")) |
398 continue; | 407 continue; |
399 file_info.modification_time = base::Time::Now(); | 408 file_info.modification_time = base::Time::Now(); |
400 file_info.parent_id = parent_id; | 409 file_info.parent_id = parent_id; |
401 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) | 410 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) |
402 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 411 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
403 if (!db->AddFileInfo(file_info, &parent_id)) { | 412 if (!db->AddFileInfo(file_info, &parent_id)) { |
404 NOTREACHED(); | 413 NOTREACHED(); |
405 return base::PLATFORM_FILE_ERROR_FAILED; | 414 return base::PLATFORM_FILE_ERROR_FAILED; |
406 } | 415 } |
407 UpdatePathQuotaUsage(context, context->src_origin_url(), | 416 UpdatePathQuotaUsage(context, context->src_origin_url(), |
408 context->src_type(), 1, file_info.name.size()); | 417 context->src_type(), 1, file_info.name.size()); |
418 if (first) { | |
419 first = false; | |
420 TouchDirectory(db, file_info.parent_id); | |
421 } | |
409 } | 422 } |
410 return base::PLATFORM_FILE_OK; | 423 return base::PLATFORM_FILE_OK; |
411 } | 424 } |
412 | 425 |
413 PlatformFileError ObfuscatedFileUtil::GetFileInfo( | 426 PlatformFileError ObfuscatedFileUtil::GetFileInfo( |
414 FileSystemOperationContext* context, | 427 FileSystemOperationContext* context, |
415 const FilePath& virtual_path, | 428 const FilePath& virtual_path, |
416 base::PlatformFileInfo* file_info, | 429 base::PlatformFileInfo* file_info, |
417 FilePath* platform_file_path) { | 430 FilePath* platform_file_path) { |
418 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 431 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 FileId file_id; | 539 FileId file_id; |
527 if (!db->GetFileWithPath(virtual_path, &file_id)) | 540 if (!db->GetFileWithPath(virtual_path, &file_id)) |
528 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 541 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
529 | 542 |
530 FileInfo file_info; | 543 FileInfo file_info; |
531 if (!db->GetFileInfo(file_id, &file_info)) { | 544 if (!db->GetFileInfo(file_id, &file_info)) { |
532 NOTREACHED(); | 545 NOTREACHED(); |
533 return base::PLATFORM_FILE_ERROR_FAILED; | 546 return base::PLATFORM_FILE_ERROR_FAILED; |
534 } | 547 } |
535 if (file_info.is_directory()) { | 548 if (file_info.is_directory()) { |
536 file_info.modification_time = last_modified_time; | 549 if (!db->UpdateModificationTime(file_id, last_modified_time)) |
537 if (!db->UpdateFileInfo(file_id, file_info)) | |
tzik
2011/12/01 16:28:46
Calling UpdateFileInfo failed for updating directo
| |
538 return base::PLATFORM_FILE_ERROR_FAILED; | 550 return base::PLATFORM_FILE_ERROR_FAILED; |
539 return base::PLATFORM_FILE_OK; | 551 return base::PLATFORM_FILE_OK; |
540 } | 552 } |
541 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 553 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
542 context->src_type(), file_info.data_path); | 554 context->src_type(), file_info.data_path); |
543 return underlying_file_util()->Touch( | 555 return underlying_file_util()->Touch( |
544 context, data_path, last_access_time, last_modified_time); | 556 context, data_path, last_access_time, last_modified_time); |
545 } | 557 } |
546 | 558 |
547 PlatformFileError ObfuscatedFileUtil::Truncate( | 559 PlatformFileError ObfuscatedFileUtil::Truncate( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 context->file_system_context()->GetQuotaUtil(context->src_type())-> | 687 context->file_system_context()->GetQuotaUtil(context->src_type())-> |
676 InvalidateUsageCache(context->src_origin_url(), | 688 InvalidateUsageCache(context->src_origin_url(), |
677 context->src_type()); | 689 context->src_type()); |
678 LOG(WARNING) << "Lost a backing file."; | 690 LOG(WARNING) << "Lost a backing file."; |
679 return base::PLATFORM_FILE_ERROR_FAILED; | 691 return base::PLATFORM_FILE_ERROR_FAILED; |
680 } | 692 } |
681 | 693 |
682 if (overwrite) { | 694 if (overwrite) { |
683 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 695 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
684 context->src_type(), dest_file_info.data_path); | 696 context->src_type(), dest_file_info.data_path); |
685 return underlying_file_util()->CopyOrMoveFile(context, | 697 PlatformFileError error = underlying_file_util()->CopyOrMoveFile(context, |
686 src_data_path, dest_data_path, copy); | 698 src_data_path, dest_data_path, copy); |
699 if (error == base::PLATFORM_FILE_OK) | |
700 TouchDirectory(db, dest_file_info.parent_id); | |
701 return error; | |
687 } else { | 702 } else { |
688 FileId dest_parent_id; | 703 FileId dest_parent_id; |
689 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 704 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
690 NOTREACHED(); // We shouldn't be called in this case. | 705 NOTREACHED(); // We shouldn't be called in this case. |
691 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 706 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
692 } | 707 } |
693 InitFileInfo(&dest_file_info, dest_parent_id, | 708 InitFileInfo(&dest_file_info, dest_parent_id, |
694 dest_file_path.BaseName().value()); | 709 dest_file_path.BaseName().value()); |
695 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) | 710 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) |
696 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 711 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
697 return CreateFile(context, context->dest_origin_url(), | 712 return CreateFile(context, context->dest_origin_url(), |
698 context->dest_type(), src_data_path, &dest_file_info, 0, | 713 context->dest_type(), src_data_path, &dest_file_info, 0, |
699 NULL); | 714 NULL); |
700 } | 715 } |
701 } else { // It's a move. | 716 } else { // It's a move. |
702 if (overwrite) { | 717 if (overwrite) { |
703 AllocateQuotaForPath(context, -1, | 718 AllocateQuotaForPath(context, -1, |
704 -static_cast<int64>(src_file_info.name.size())); | 719 -static_cast<int64>(src_file_info.name.size())); |
705 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) | 720 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) |
706 return base::PLATFORM_FILE_ERROR_FAILED; | 721 return base::PLATFORM_FILE_ERROR_FAILED; |
707 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 722 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
708 context->src_type(), dest_file_info.data_path); | 723 context->src_type(), dest_file_info.data_path); |
709 if (base::PLATFORM_FILE_OK != | 724 if (base::PLATFORM_FILE_OK != |
710 underlying_file_util()->DeleteFile(context, dest_data_path)) | 725 underlying_file_util()->DeleteFile(context, dest_data_path)) |
711 LOG(WARNING) << "Leaked a backing file."; | 726 LOG(WARNING) << "Leaked a backing file."; |
712 UpdatePathQuotaUsage(context, context->src_origin_url(), | 727 UpdatePathQuotaUsage(context, context->src_origin_url(), |
713 context->src_type(), -1, | 728 context->src_type(), -1, |
714 -static_cast<int64>(src_file_info.name.size())); | 729 -static_cast<int64>(src_file_info.name.size())); |
730 TouchDirectory(db, src_file_info.parent_id); | |
731 TouchDirectory(db, dest_file_info.parent_id); | |
715 return base::PLATFORM_FILE_OK; | 732 return base::PLATFORM_FILE_OK; |
716 } else { | 733 } else { |
717 FileId dest_parent_id; | 734 FileId dest_parent_id; |
718 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 735 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
719 NOTREACHED(); | 736 NOTREACHED(); |
720 return base::PLATFORM_FILE_ERROR_FAILED; | 737 return base::PLATFORM_FILE_ERROR_FAILED; |
721 } | 738 } |
722 if (!AllocateQuotaForPath( | 739 if (!AllocateQuotaForPath( |
723 context, 0, | 740 context, 0, |
724 static_cast<int64>(dest_file_path.BaseName().value().size()) | 741 static_cast<int64>(dest_file_path.BaseName().value().size()) |
725 - static_cast<int64>(src_file_info.name.size()))) | 742 - static_cast<int64>(src_file_info.name.size()))) |
726 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 743 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
744 FileId src_parent_id = src_file_info.parent_id; | |
727 src_file_info.parent_id = dest_parent_id; | 745 src_file_info.parent_id = dest_parent_id; |
728 src_file_info.name = dest_file_path.BaseName().value(); | 746 src_file_info.name = dest_file_path.BaseName().value(); |
729 if (!db->UpdateFileInfo(src_file_id, src_file_info)) | 747 if (!db->UpdateFileInfo(src_file_id, src_file_info)) |
730 return base::PLATFORM_FILE_ERROR_FAILED; | 748 return base::PLATFORM_FILE_ERROR_FAILED; |
731 UpdatePathQuotaUsage( | 749 UpdatePathQuotaUsage( |
732 context, context->src_origin_url(), context->src_type(), 0, | 750 context, context->src_origin_url(), context->src_type(), 0, |
733 static_cast<int64>(dest_file_path.BaseName().value().size()) - | 751 static_cast<int64>(dest_file_path.BaseName().value().size()) - |
734 static_cast<int64>(src_file_path.BaseName().value().size())); | 752 static_cast<int64>(src_file_path.BaseName().value().size())); |
753 TouchDirectory(db, src_parent_id); | |
754 TouchDirectory(db, dest_parent_id); | |
735 return base::PLATFORM_FILE_OK; | 755 return base::PLATFORM_FILE_OK; |
736 } | 756 } |
737 } | 757 } |
738 NOTREACHED(); | 758 NOTREACHED(); |
739 return base::PLATFORM_FILE_ERROR_FAILED; | 759 return base::PLATFORM_FILE_ERROR_FAILED; |
740 } | 760 } |
741 | 761 |
742 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( | 762 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( |
743 FileSystemOperationContext* context, | 763 FileSystemOperationContext* context, |
744 const FilePath& src_file_path, | 764 const FilePath& src_file_path, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 return base::PLATFORM_FILE_ERROR_FAILED; | 816 return base::PLATFORM_FILE_ERROR_FAILED; |
797 } | 817 } |
798 AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size())); | 818 AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size())); |
799 UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(), | 819 UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(), |
800 -1, -static_cast<int64>(file_info.name.size())); | 820 -1, -static_cast<int64>(file_info.name.size())); |
801 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 821 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
802 context->src_type(), file_info.data_path); | 822 context->src_type(), file_info.data_path); |
803 if (base::PLATFORM_FILE_OK != | 823 if (base::PLATFORM_FILE_OK != |
804 underlying_file_util()->DeleteFile(context, data_path)) | 824 underlying_file_util()->DeleteFile(context, data_path)) |
805 LOG(WARNING) << "Leaked a backing file."; | 825 LOG(WARNING) << "Leaked a backing file."; |
826 TouchDirectory(db, file_info.parent_id); | |
806 return base::PLATFORM_FILE_OK; | 827 return base::PLATFORM_FILE_OK; |
807 } | 828 } |
808 | 829 |
809 PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory( | 830 PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory( |
810 FileSystemOperationContext* context, | 831 FileSystemOperationContext* context, |
811 const FilePath& virtual_path) { | 832 const FilePath& virtual_path) { |
812 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 833 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
813 context->src_origin_url(), context->src_type(), true); | 834 context->src_origin_url(), context->src_type(), true); |
814 if (!db) | 835 if (!db) |
815 return base::PLATFORM_FILE_ERROR_FAILED; | 836 return base::PLATFORM_FILE_ERROR_FAILED; |
816 FileId file_id; | 837 FileId file_id; |
817 if (!db->GetFileWithPath(virtual_path, &file_id)) | 838 if (!db->GetFileWithPath(virtual_path, &file_id)) |
818 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 839 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
819 FileInfo file_info; | 840 FileInfo file_info; |
820 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { | 841 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { |
821 NOTREACHED(); | 842 NOTREACHED(); |
822 return base::PLATFORM_FILE_ERROR_FAILED; | 843 return base::PLATFORM_FILE_ERROR_FAILED; |
823 } | 844 } |
824 if (!db->RemoveFileInfo(file_id)) | 845 if (!db->RemoveFileInfo(file_id)) |
825 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 846 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
826 AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size())); | 847 AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size())); |
827 UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(), | 848 UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(), |
828 -1, -static_cast<int64>(file_info.name.size())); | 849 -1, -static_cast<int64>(file_info.name.size())); |
850 TouchDirectory(db, file_info.parent_id); | |
829 return base::PLATFORM_FILE_OK; | 851 return base::PLATFORM_FILE_OK; |
830 } | 852 } |
831 | 853 |
832 FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( | 854 FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( |
833 const GURL& origin, FileSystemType type, bool create) { | 855 const GURL& origin, FileSystemType type, bool create) { |
834 FilePath origin_dir = GetDirectoryForOrigin(origin, create); | 856 FilePath origin_dir = GetDirectoryForOrigin(origin, create); |
835 if (origin_dir.empty()) | 857 if (origin_dir.empty()) |
836 return FilePath(); | 858 return FilePath(); |
837 FilePath::StringType type_string = GetDirectoryNameForType(type); | 859 FilePath::StringType type_string = GetDirectoryNameForType(type); |
838 if (type_string.empty()) { | 860 if (type_string.empty()) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 FileId file_id; | 1132 FileId file_id; |
1111 if (!db->AddFileInfo(*file_info, &file_id)) { | 1133 if (!db->AddFileInfo(*file_info, &file_id)) { |
1112 if (handle) { | 1134 if (handle) { |
1113 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 1135 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
1114 base::ClosePlatformFile(*handle); | 1136 base::ClosePlatformFile(*handle); |
1115 } | 1137 } |
1116 underlying_file_util()->DeleteFile(context, local_path); | 1138 underlying_file_util()->DeleteFile(context, local_path); |
1117 return base::PLATFORM_FILE_ERROR_FAILED; | 1139 return base::PLATFORM_FILE_ERROR_FAILED; |
1118 } | 1140 } |
1119 UpdatePathQuotaUsage(context, origin_url, type, 1, file_info->name.size()); | 1141 UpdatePathQuotaUsage(context, origin_url, type, 1, file_info->name.size()); |
1142 TouchDirectory(db, file_info->parent_id); | |
1120 | 1143 |
1121 return base::PLATFORM_FILE_OK; | 1144 return base::PLATFORM_FILE_OK; |
1122 } | 1145 } |
1123 | 1146 |
1124 FilePath ObfuscatedFileUtil::GetLocalPath( | 1147 FilePath ObfuscatedFileUtil::GetLocalPath( |
1125 const GURL& origin_url, | 1148 const GURL& origin_url, |
1126 FileSystemType type, | 1149 FileSystemType type, |
1127 const FilePath& virtual_path) { | 1150 const FilePath& virtual_path) { |
1128 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 1151 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
1129 origin_url, type, false); | 1152 origin_url, type, false); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1246 return false; | 1269 return false; |
1247 } | 1270 } |
1248 origin_database_.reset( | 1271 origin_database_.reset( |
1249 new FileSystemOriginDatabase( | 1272 new FileSystemOriginDatabase( |
1250 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1273 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
1251 } | 1274 } |
1252 return true; | 1275 return true; |
1253 } | 1276 } |
1254 | 1277 |
1255 } // namespace fileapi | 1278 } // namespace fileapi |
OLD | NEW |