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/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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // The file doesn't exist. | 290 // The file doesn't exist. |
291 if (!(file_flags & (base::PLATFORM_FILE_CREATE | | 291 if (!(file_flags & (base::PLATFORM_FILE_CREATE | |
292 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS))) | 292 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS))) |
293 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 293 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
294 FileId parent_id; | 294 FileId parent_id; |
295 if (!db->GetFileWithPath(virtual_path.internal_path().DirName(), | 295 if (!db->GetFileWithPath(virtual_path.internal_path().DirName(), |
296 &parent_id)) | 296 &parent_id)) |
297 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 297 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
298 FileInfo file_info; | 298 FileInfo file_info; |
299 InitFileInfo(&file_info, parent_id, | 299 InitFileInfo(&file_info, parent_id, |
300 virtual_path.internal_path().BaseName().value()); | 300 VirtualPath::BaseName(virtual_path.internal_path()).value()); |
301 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) | 301 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) |
302 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 302 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
303 PlatformFileError error = CreateFile( | 303 PlatformFileError error = CreateFile( |
304 context, FileSystemPath(), | 304 context, FileSystemPath(), |
305 virtual_path.origin(), virtual_path.type(), &file_info, | 305 virtual_path.origin(), virtual_path.type(), &file_info, |
306 file_flags, file_handle); | 306 file_flags, file_handle); |
307 if (created && base::PLATFORM_FILE_OK == error) | 307 if (created && base::PLATFORM_FILE_OK == error) |
308 *created = true; | 308 *created = true; |
309 return error; | 309 return error; |
310 } | 310 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (created) | 353 if (created) |
354 *created = false; | 354 *created = false; |
355 return base::PLATFORM_FILE_OK; | 355 return base::PLATFORM_FILE_OK; |
356 } | 356 } |
357 FileId parent_id; | 357 FileId parent_id; |
358 if (!db->GetFileWithPath(virtual_path.internal_path().DirName(), &parent_id)) | 358 if (!db->GetFileWithPath(virtual_path.internal_path().DirName(), &parent_id)) |
359 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 359 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
360 | 360 |
361 FileInfo file_info; | 361 FileInfo file_info; |
362 InitFileInfo(&file_info, parent_id, | 362 InitFileInfo(&file_info, parent_id, |
363 virtual_path.internal_path().BaseName().value()); | 363 VirtualPath::BaseName(virtual_path.internal_path()).value()); |
364 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) | 364 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) |
365 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 365 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
366 PlatformFileError error = CreateFile(context, | 366 PlatformFileError error = CreateFile(context, |
367 FileSystemPath(), | 367 FileSystemPath(), |
368 virtual_path.origin(), virtual_path.type(), &file_info, | 368 virtual_path.origin(), virtual_path.type(), &file_info, |
369 0, NULL); | 369 0, NULL); |
370 if (created && base::PLATFORM_FILE_OK == error) | 370 if (created && base::PLATFORM_FILE_OK == error) |
371 *created = true; | 371 *created = true; |
372 return error; | 372 return error; |
373 } | 373 } |
(...skipping 15 matching lines...) Expand all Loading... |
389 if (!db->GetFileInfo(file_id, &file_info)) { | 389 if (!db->GetFileInfo(file_id, &file_info)) { |
390 NOTREACHED(); | 390 NOTREACHED(); |
391 return base::PLATFORM_FILE_ERROR_FAILED; | 391 return base::PLATFORM_FILE_ERROR_FAILED; |
392 } | 392 } |
393 if (!file_info.is_directory()) | 393 if (!file_info.is_directory()) |
394 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 394 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
395 return base::PLATFORM_FILE_OK; | 395 return base::PLATFORM_FILE_OK; |
396 } | 396 } |
397 | 397 |
398 std::vector<FilePath::StringType> components; | 398 std::vector<FilePath::StringType> components; |
399 virtual_path.internal_path().GetComponents(&components); | 399 VirtualPath::GetComponents(virtual_path.internal_path(), &components); |
400 FileId parent_id = 0; | 400 FileId parent_id = 0; |
401 size_t index; | 401 size_t index; |
402 for (index = 0; index < components.size(); ++index) { | 402 for (index = 0; index < components.size(); ++index) { |
403 FilePath::StringType name = components[index]; | 403 FilePath::StringType name = components[index]; |
404 if (name == FILE_PATH_LITERAL("/")) | 404 if (name == FILE_PATH_LITERAL("/")) |
405 continue; | 405 continue; |
406 if (!db->GetChildWithName(parent_id, name, &parent_id)) | 406 if (!db->GetChildWithName(parent_id, name, &parent_id)) |
407 break; | 407 break; |
408 } | 408 } |
409 if (!recursive && components.size() - index > 1) | 409 if (!recursive && components.size() - index > 1) |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 TouchDirectory(db, dest_file_info.parent_id); | 709 TouchDirectory(db, dest_file_info.parent_id); |
710 return error; | 710 return error; |
711 } else { | 711 } else { |
712 FileId dest_parent_id; | 712 FileId dest_parent_id; |
713 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), | 713 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), |
714 &dest_parent_id)) { | 714 &dest_parent_id)) { |
715 NOTREACHED(); // We shouldn't be called in this case. | 715 NOTREACHED(); // We shouldn't be called in this case. |
716 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 716 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
717 } | 717 } |
718 InitFileInfo(&dest_file_info, dest_parent_id, | 718 InitFileInfo(&dest_file_info, dest_parent_id, |
719 dest_path.internal_path().BaseName().value()); | 719 VirtualPath::BaseName(dest_path.internal_path()).value()); |
720 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) | 720 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) |
721 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 721 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
722 return CreateFile(context, src_local_path, | 722 return CreateFile(context, src_local_path, |
723 dest_path.origin(), dest_path.type(), &dest_file_info, | 723 dest_path.origin(), dest_path.type(), &dest_file_info, |
724 0, NULL); | 724 0, NULL); |
725 } | 725 } |
726 } else { // It's a move. | 726 } else { // It's a move. |
727 if (overwrite) { | 727 if (overwrite) { |
728 AllocateQuotaForPath(context, -1, | 728 AllocateQuotaForPath(context, -1, |
729 -static_cast<int64>(src_file_info.name.size())); | 729 -static_cast<int64>(src_file_info.name.size())); |
(...skipping 13 matching lines...) Expand all Loading... |
743 FileId dest_parent_id; | 743 FileId dest_parent_id; |
744 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), | 744 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), |
745 &dest_parent_id)) { | 745 &dest_parent_id)) { |
746 NOTREACHED(); | 746 NOTREACHED(); |
747 return base::PLATFORM_FILE_ERROR_FAILED; | 747 return base::PLATFORM_FILE_ERROR_FAILED; |
748 } | 748 } |
749 FilePath dest_internal_path = dest_path.internal_path(); | 749 FilePath dest_internal_path = dest_path.internal_path(); |
750 FilePath src_internal_path = src_path.internal_path(); | 750 FilePath src_internal_path = src_path.internal_path(); |
751 if (!AllocateQuotaForPath( | 751 if (!AllocateQuotaForPath( |
752 context, 0, | 752 context, 0, |
753 static_cast<int64>(dest_internal_path.BaseName().value().size()) | 753 static_cast<int64>( |
754 -static_cast<int64>(src_file_info.name.size()))) | 754 VirtualPath::BaseName(dest_internal_path).value().size()) - |
| 755 static_cast<int64>(src_file_info.name.size()))) |
755 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 756 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
756 FileId src_parent_id = src_file_info.parent_id; | 757 FileId src_parent_id = src_file_info.parent_id; |
757 src_file_info.parent_id = dest_parent_id; | 758 src_file_info.parent_id = dest_parent_id; |
758 src_file_info.name = dest_path.internal_path().BaseName().value(); | 759 src_file_info.name = |
| 760 VirtualPath::BaseName(dest_path.internal_path()).value(); |
759 if (!db->UpdateFileInfo(src_file_id, src_file_info)) | 761 if (!db->UpdateFileInfo(src_file_id, src_file_info)) |
760 return base::PLATFORM_FILE_ERROR_FAILED; | 762 return base::PLATFORM_FILE_ERROR_FAILED; |
761 UpdatePathQuotaUsage( | 763 UpdatePathQuotaUsage( |
762 context, src_path.origin(), src_path.type(), 0, | 764 context, src_path.origin(), src_path.type(), 0, |
763 static_cast<int64>(dest_internal_path.BaseName().value().size()) - | 765 static_cast<int64>( |
764 static_cast<int64>(src_internal_path.BaseName().value().size())); | 766 VirtualPath::BaseName(dest_internal_path).value().size()) - |
| 767 static_cast<int64>( |
| 768 VirtualPath::BaseName(src_internal_path).value().size())); |
765 TouchDirectory(db, src_parent_id); | 769 TouchDirectory(db, src_parent_id); |
766 TouchDirectory(db, dest_parent_id); | 770 TouchDirectory(db, dest_parent_id); |
767 return base::PLATFORM_FILE_OK; | 771 return base::PLATFORM_FILE_OK; |
768 } | 772 } |
769 } | 773 } |
770 NOTREACHED(); | 774 NOTREACHED(); |
771 return base::PLATFORM_FILE_ERROR_FAILED; | 775 return base::PLATFORM_FILE_ERROR_FAILED; |
772 } | 776 } |
773 | 777 |
774 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( | 778 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( |
(...skipping 20 matching lines...) Expand all Loading... |
795 underlying_src_path, | 799 underlying_src_path, |
796 dest_local_path, true /* copy */); | 800 dest_local_path, true /* copy */); |
797 } else { | 801 } else { |
798 FileId dest_parent_id; | 802 FileId dest_parent_id; |
799 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), | 803 if (!db->GetFileWithPath(dest_path.internal_path().DirName(), |
800 &dest_parent_id)) { | 804 &dest_parent_id)) { |
801 NOTREACHED(); // We shouldn't be called in this case. | 805 NOTREACHED(); // We shouldn't be called in this case. |
802 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 806 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
803 } | 807 } |
804 InitFileInfo(&dest_file_info, dest_parent_id, | 808 InitFileInfo(&dest_file_info, dest_parent_id, |
805 dest_path.internal_path().BaseName().value()); | 809 VirtualPath::BaseName(dest_path.internal_path()).value()); |
806 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) | 810 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) |
807 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 811 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
808 return CreateFile(context, underlying_src_path, | 812 return CreateFile(context, underlying_src_path, |
809 dest_path.origin(), dest_path.type(), &dest_file_info, | 813 dest_path.origin(), dest_path.type(), &dest_file_info, |
810 0, NULL); | 814 0, NULL); |
811 } | 815 } |
812 return base::PLATFORM_FILE_ERROR_FAILED; | 816 return base::PLATFORM_FILE_ERROR_FAILED; |
813 } | 817 } |
814 | 818 |
815 PlatformFileError ObfuscatedFileUtil::DeleteFile( | 819 PlatformFileError ObfuscatedFileUtil::DeleteFile( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (db->GetFileWithPath(relative_virtual_path, &file_id)) { | 950 if (db->GetFileWithPath(relative_virtual_path, &file_id)) { |
947 NOTREACHED(); // File already exists. | 951 NOTREACHED(); // File already exists. |
948 return false; | 952 return false; |
949 } | 953 } |
950 if (!db->GetFileWithPath(relative_virtual_path.DirName(), &file_id)) { | 954 if (!db->GetFileWithPath(relative_virtual_path.DirName(), &file_id)) { |
951 NOTREACHED(); // Parent doesn't exist. | 955 NOTREACHED(); // Parent doesn't exist. |
952 return false; | 956 return false; |
953 } | 957 } |
954 | 958 |
955 FileInfo file_info; | 959 FileInfo file_info; |
956 file_info.name = src_full_path.BaseName().value(); | 960 file_info.name = VirtualPath::BaseName(src_full_path).value(); |
957 if (file_util::FileEnumerator::IsDirectory(info)) { | 961 if (file_util::FileEnumerator::IsDirectory(info)) { |
958 #if defined(OS_WIN) | 962 #if defined(OS_WIN) |
959 file_info.modification_time = | 963 file_info.modification_time = |
960 base::Time::FromFileTime(info.ftLastWriteTime); | 964 base::Time::FromFileTime(info.ftLastWriteTime); |
961 #elif defined(OS_POSIX) | 965 #elif defined(OS_POSIX) |
962 file_info.modification_time = base::Time::FromTimeT(info.stat.st_mtime); | 966 file_info.modification_time = base::Time::FromTimeT(info.stat.st_mtime); |
963 #endif | 967 #endif |
964 } else { | 968 } else { |
965 file_info.data_path = | 969 file_info.data_path = |
966 FilePath(kLegacyDataDirectory).Append(relative_virtual_path); | 970 FilePath(kLegacyDataDirectory).Append(relative_virtual_path); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 if (path.empty()) | 1031 if (path.empty()) |
1028 return true; | 1032 return true; |
1029 if (!file_util::DirectoryExists(path)) | 1033 if (!file_util::DirectoryExists(path)) |
1030 return true; | 1034 return true; |
1031 path = path.AppendASCII(kDirectoryDatabaseName); | 1035 path = path.AppendASCII(kDirectoryDatabaseName); |
1032 return FileSystemDirectoryDatabase::DestroyDatabase(path); | 1036 return FileSystemDirectoryDatabase::DestroyDatabase(path); |
1033 } | 1037 } |
1034 | 1038 |
1035 // static | 1039 // static |
1036 int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) { | 1040 int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) { |
1037 return GetPathQuotaUsage(1, path.BaseName().value().size()); | 1041 return GetPathQuotaUsage(1, VirtualPath::BaseName(path).value().size()); |
1038 } | 1042 } |
1039 | 1043 |
1040 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( | 1044 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( |
1041 FileSystemDirectoryDatabase* db, | 1045 FileSystemDirectoryDatabase* db, |
1042 FileSystemOperationContext* context, | 1046 FileSystemOperationContext* context, |
1043 const GURL& origin, | 1047 const GURL& origin, |
1044 FileSystemType type, | 1048 FileSystemType type, |
1045 FileId file_id, | 1049 FileId file_id, |
1046 FileInfo* local_info, | 1050 FileInfo* local_info, |
1047 base::PlatformFileInfo* file_info, | 1051 base::PlatformFileInfo* file_info, |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 return false; | 1303 return false; |
1300 } | 1304 } |
1301 origin_database_.reset( | 1305 origin_database_.reset( |
1302 new FileSystemOriginDatabase( | 1306 new FileSystemOriginDatabase( |
1303 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1307 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
1304 } | 1308 } |
1305 return true; | 1309 return true; |
1306 } | 1310 } |
1307 | 1311 |
1308 } // namespace fileapi | 1312 } // namespace fileapi |
OLD | NEW |