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

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: '' 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
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 // Do nothing for root directory.
ericu 2011/11/30 19:16:04 Why do you special-case the root? My Linux box do
tzik 2011/12/01 16:28:46 It is just to keep consistency to current implemen
ericu 2011/12/05 21:43:50 That is incorrect. Look at FileSystemDirectoryDat
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 292 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
285 FileInfo file_info; 293 FileInfo file_info;
286 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); 294 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
287 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) 295 if (!AllocateQuotaForPath(context, 1, file_info.name.size()))
288 return base::PLATFORM_FILE_ERROR_NO_SPACE; 296 return base::PLATFORM_FILE_ERROR_NO_SPACE;
289 PlatformFileError error = CreateFile( 297 PlatformFileError error = CreateFile(
290 context, context->src_origin_url(), context->src_type(), FilePath(), 298 context, context->src_origin_url(), context->src_type(), FilePath(),
291 &file_info, file_flags, file_handle); 299 &file_info, file_flags, file_handle);
292 if (created && base::PLATFORM_FILE_OK == error) 300 if (created && base::PLATFORM_FILE_OK == error)
293 *created = true; 301 *created = true;
302 TouchDirectory(db, parent_id);
ericu 2011/11/30 19:16:04 You don't want to touch the parent if the creation
tzik 2011/12/01 16:28:46 Done.
294 return error; 303 return error;
295 } 304 }
296 if (file_flags & base::PLATFORM_FILE_CREATE) 305 if (file_flags & base::PLATFORM_FILE_CREATE)
297 return base::PLATFORM_FILE_ERROR_EXISTS; 306 return base::PLATFORM_FILE_ERROR_EXISTS;
298 307
299 FileInfo file_info; 308 FileInfo file_info;
300 if (!db->GetFileInfo(file_id, &file_info)) { 309 if (!db->GetFileInfo(file_id, &file_info)) {
301 NOTREACHED(); 310 NOTREACHED();
302 return base::PLATFORM_FILE_ERROR_FAILED; 311 return base::PLATFORM_FILE_ERROR_FAILED;
303 } 312 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 354 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
346 355
347 FileInfo file_info; 356 FileInfo file_info;
348 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); 357 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
349 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) 358 if (!AllocateQuotaForPath(context, 1, file_info.name.size()))
350 return base::PLATFORM_FILE_ERROR_NO_SPACE; 359 return base::PLATFORM_FILE_ERROR_NO_SPACE;
351 PlatformFileError error = CreateFile(context, context->src_origin_url(), 360 PlatformFileError error = CreateFile(context, context->src_origin_url(),
352 context->src_type(), FilePath(), &file_info, 0, NULL); 361 context->src_type(), FilePath(), &file_info, 0, NULL);
353 if (created && base::PLATFORM_FILE_OK == error) 362 if (created && base::PLATFORM_FILE_OK == error)
354 *created = true; 363 *created = true;
364 TouchDirectory(db, parent_id);
ericu 2011/11/30 19:16:04 Perhaps it would be better to put the call inside
tzik 2011/12/01 16:28:46 Done.
355 return error; 365 return error;
356 } 366 }
357 367
358 PlatformFileError ObfuscatedFileUtil::CreateDirectory( 368 PlatformFileError ObfuscatedFileUtil::CreateDirectory(
359 FileSystemOperationContext* context, 369 FileSystemOperationContext* context,
360 const FilePath& virtual_path, 370 const FilePath& virtual_path,
361 bool exclusive, 371 bool exclusive,
362 bool recursive) { 372 bool recursive) {
363 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( 373 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
364 context->src_origin_url(), context->src_type(), true); 374 context->src_origin_url(), context->src_type(), true);
(...skipping 19 matching lines...) Expand all
384 size_t index; 394 size_t index;
385 for (index = 0; index < components.size(); ++index) { 395 for (index = 0; index < components.size(); ++index) {
386 FilePath::StringType name = components[index]; 396 FilePath::StringType name = components[index];
387 if (name == FILE_PATH_LITERAL("/")) 397 if (name == FILE_PATH_LITERAL("/"))
388 continue; 398 continue;
389 if (!db->GetChildWithName(parent_id, name, &parent_id)) 399 if (!db->GetChildWithName(parent_id, name, &parent_id))
390 break; 400 break;
391 } 401 }
392 if (!recursive && components.size() - index > 1) 402 if (!recursive && components.size() - index > 1)
393 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 403 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
404 TouchDirectory(db, parent_id);
394 for (; index < components.size(); ++index) { 405 for (; index < components.size(); ++index) {
395 FileInfo file_info; 406 FileInfo file_info;
396 file_info.name = components[index]; 407 file_info.name = components[index];
397 if (file_info.name == FILE_PATH_LITERAL("/")) 408 if (file_info.name == FILE_PATH_LITERAL("/"))
398 continue; 409 continue;
399 file_info.modification_time = base::Time::Now(); 410 file_info.modification_time = base::Time::Now();
400 file_info.parent_id = parent_id; 411 file_info.parent_id = parent_id;
401 if (!AllocateQuotaForPath(context, 1, file_info.name.size())) 412 if (!AllocateQuotaForPath(context, 1, file_info.name.size()))
402 return base::PLATFORM_FILE_ERROR_NO_SPACE; 413 return base::PLATFORM_FILE_ERROR_NO_SPACE;
403 if (!db->AddFileInfo(file_info, &parent_id)) { 414 if (!db->AddFileInfo(file_info, &parent_id)) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 } else { 698 } else {
688 FileId dest_parent_id; 699 FileId dest_parent_id;
689 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 700 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
690 NOTREACHED(); // We shouldn't be called in this case. 701 NOTREACHED(); // We shouldn't be called in this case.
691 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 702 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
692 } 703 }
693 InitFileInfo(&dest_file_info, dest_parent_id, 704 InitFileInfo(&dest_file_info, dest_parent_id,
694 dest_file_path.BaseName().value()); 705 dest_file_path.BaseName().value());
695 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) 706 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size()))
696 return base::PLATFORM_FILE_ERROR_NO_SPACE; 707 return base::PLATFORM_FILE_ERROR_NO_SPACE;
697 return CreateFile(context, context->dest_origin_url(), 708 PlatformFileError error = CreateFile(context, context->dest_origin_url(),
698 context->dest_type(), src_data_path, &dest_file_info, 0, 709 context->dest_type(), src_data_path, &dest_file_info, 0,
699 NULL); 710 NULL);
711 if (error == base::PLATFORM_FILE_OK)
712 TouchDirectory(db, dest_parent_id);
713 return error;
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);
ericu 2011/11/30 19:16:04 You need to update the destination directory's mti
tzik 2011/12/01 16:28:46 Done.
715 return base::PLATFORM_FILE_OK; 730 return base::PLATFORM_FILE_OK;
716 } else { 731 } else {
717 FileId dest_parent_id; 732 FileId dest_parent_id;
718 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 733 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
719 NOTREACHED(); 734 NOTREACHED();
720 return base::PLATFORM_FILE_ERROR_FAILED; 735 return base::PLATFORM_FILE_ERROR_FAILED;
721 } 736 }
722 if (!AllocateQuotaForPath( 737 if (!AllocateQuotaForPath(
723 context, 0, 738 context, 0,
724 static_cast<int64>(dest_file_path.BaseName().value().size()) 739 static_cast<int64>(dest_file_path.BaseName().value().size())
725 - static_cast<int64>(src_file_info.name.size()))) 740 - static_cast<int64>(src_file_info.name.size())))
726 return base::PLATFORM_FILE_ERROR_NO_SPACE; 741 return base::PLATFORM_FILE_ERROR_NO_SPACE;
742 FileId src_parent_id = src_file_info.parent_id;
727 src_file_info.parent_id = dest_parent_id; 743 src_file_info.parent_id = dest_parent_id;
728 src_file_info.name = dest_file_path.BaseName().value(); 744 src_file_info.name = dest_file_path.BaseName().value();
729 if (!db->UpdateFileInfo(src_file_id, src_file_info)) 745 if (!db->UpdateFileInfo(src_file_id, src_file_info))
730 return base::PLATFORM_FILE_ERROR_FAILED; 746 return base::PLATFORM_FILE_ERROR_FAILED;
747 TouchDirectory(db, src_parent_id);
748 TouchDirectory(db, dest_parent_id);
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()));
735 return base::PLATFORM_FILE_OK; 753 return base::PLATFORM_FILE_OK;
736 } 754 }
737 } 755 }
738 NOTREACHED(); 756 NOTREACHED();
739 return base::PLATFORM_FILE_ERROR_FAILED; 757 return base::PLATFORM_FILE_ERROR_FAILED;
740 } 758 }
(...skipping 22 matching lines...) Expand all
763 } else { 781 } else {
764 FileId dest_parent_id; 782 FileId dest_parent_id;
765 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 783 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
766 NOTREACHED(); // We shouldn't be called in this case. 784 NOTREACHED(); // We shouldn't be called in this case.
767 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 785 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
768 } 786 }
769 InitFileInfo(&dest_file_info, dest_parent_id, 787 InitFileInfo(&dest_file_info, dest_parent_id,
770 dest_file_path.BaseName().value()); 788 dest_file_path.BaseName().value());
771 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size())) 789 if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size()))
772 return base::PLATFORM_FILE_ERROR_NO_SPACE; 790 return base::PLATFORM_FILE_ERROR_NO_SPACE;
773 return CreateFile(context, context->dest_origin_url(), 791 PlatformFileError error = CreateFile(context, context->dest_origin_url(),
774 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); 792 context->dest_type(), src_file_path, &dest_file_info, 0, NULL);
793 TouchDirectory(db, dest_parent_id);
794 return error;
775 } 795 }
776 return base::PLATFORM_FILE_ERROR_FAILED; 796 return base::PLATFORM_FILE_ERROR_FAILED;
777 } 797 }
778 798
779 PlatformFileError ObfuscatedFileUtil::DeleteFile( 799 PlatformFileError ObfuscatedFileUtil::DeleteFile(
780 FileSystemOperationContext* context, 800 FileSystemOperationContext* context,
781 const FilePath& virtual_path) { 801 const FilePath& virtual_path) {
782 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( 802 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
783 context->src_origin_url(), context->src_type(), true); 803 context->src_origin_url(), context->src_type(), true);
784 if (!db) 804 if (!db)
(...skipping 11 matching lines...) Expand all
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 407 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 | « no previous file | webkit/fileapi/obfuscated_file_util_unittest.cc » ('j') | webkit/fileapi/obfuscated_file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698