Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webkit/fileapi/obfuscated_file_util.cc

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

Powered by Google App Engine
This is Rietveld 408576698