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

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

Issue 7608018: Handle inconsistency between DB and Files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 4 months 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 | Annotate | Revision Log
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_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 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 FileInfo file_info; 101 FileInfo file_info;
102 if (!db->GetFileInfo(file_id, &file_info)) { 102 if (!db->GetFileInfo(file_id, &file_info)) {
103 NOTREACHED(); 103 NOTREACHED();
104 return base::PLATFORM_FILE_ERROR_FAILED; 104 return base::PLATFORM_FILE_ERROR_FAILED;
105 } 105 }
106 if (file_info.is_directory()) 106 if (file_info.is_directory())
107 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 107 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
108 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 108 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
109 context->src_type(), file_info.data_path); 109 context->src_type(), file_info.data_path);
110 return underlying_file_util_->CreateOrOpen( 110 base::PlatformFileError error = underlying_file_util_->CreateOrOpen(
111 context, data_path, file_flags, file_handle, created); 111 context, data_path, file_flags, file_handle, created);
112 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
113 context->file_system_context()->GetQuotaUtil(context->src_type())->
114 MarkDirtyOriginOnFileThread(context->src_origin_url(),
ericu 2011/08/19 04:05:56 Marking the cache dirty won't help entirely solve
tzik 2011/08/23 04:13:13 Done.
ericu 2011/08/24 03:43:50 I was talking about the entry in the FileSystemDir
tzik 2011/08/24 06:31:59 I see. But, should we delete the database entry si
tzik 2011/08/29 06:54:13 Done.
ericu 2011/08/29 22:48:20 It's really hard to say what will make the user ha
tzik 2011/08/31 02:40:05 I agree that deleting files will work better in mo
ericu 2011/08/31 03:51:14 Yes, of course.
115 context->src_type());
116 LOG(WARNING) << "Lost a backing file.";
117 error = base::PLATFORM_FILE_ERROR_FAILED;
118 }
119 return error;
112 } 120 }
113 121
114 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( 122 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists(
115 FileSystemOperationContext* context, 123 FileSystemOperationContext* context,
116 const FilePath& virtual_path, 124 const FilePath& virtual_path,
117 bool* created) { 125 bool* created) {
118 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( 126 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
119 context->src_origin_url(), context->src_type(), true); 127 context->src_origin_url(), context->src_type(), true);
120 if (!db) 128 if (!db)
121 return base::PLATFORM_FILE_ERROR_FAILED; 129 return base::PLATFORM_FILE_ERROR_FAILED;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 * transaction: 332 * transaction:
325 * Remove source entry. 333 * Remove source entry.
326 * Point target entry to source entry's backing file. 334 * Point target entry to source entry's backing file.
327 * Delete target entry's old backing file 335 * Delete target entry's old backing file
328 * Move-without-overwrite 336 * Move-without-overwrite
329 * Just update metadata 337 * Just update metadata
330 */ 338 */
331 if (copy) { 339 if (copy) {
332 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), 340 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(),
333 context->src_type(), src_file_info.data_path); 341 context->src_type(), src_file_info.data_path);
342 if (!underlying_file_util_->PathExists(context, src_data_path)) {
343 context->file_system_context()->GetQuotaUtil(context->src_type())->
344 MarkDirtyOriginOnFileThread(context->src_origin_url(),
345 context->src_type());
346 LOG(WARNING) << "Lost a backing file.";
347 return base::PLATFORM_FILE_ERROR_FAILED;
348 }
349
334 if (overwrite) { 350 if (overwrite) {
335 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), 351 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
336 context->src_type(), dest_file_info.data_path); 352 context->src_type(), dest_file_info.data_path);
337 return underlying_file_util_->CopyOrMoveFile(context, 353 return underlying_file_util_->CopyOrMoveFile(context,
338 src_data_path, dest_data_path, copy); 354 src_data_path, dest_data_path, copy);
339 } else { 355 } else {
340 FileId dest_parent_id; 356 FileId dest_parent_id;
341 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 357 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
342 NOTREACHED(); // We shouldn't be called in this case. 358 NOTREACHED(); // We shouldn't be called in this case.
343 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 359 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 return base::PLATFORM_FILE_ERROR_FAILED; 796 return base::PLATFORM_FILE_ERROR_FAILED;
781 PlatformFileError error; 797 PlatformFileError error;
782 bool created = false; 798 bool created = false;
783 if (!source_path.empty()) { 799 if (!source_path.empty()) {
784 DCHECK(!file_flags); 800 DCHECK(!file_flags);
785 DCHECK(!handle); 801 DCHECK(!handle);
786 error = underlying_file_util_->CopyOrMoveFile( 802 error = underlying_file_util_->CopyOrMoveFile(
787 context, source_path, path, true /* copy */); 803 context, source_path, path, true /* copy */);
788 created = true; 804 created = true;
789 } else { 805 } else {
806 if (file_util::PathExists(path)) {
807 if (!file_util::Delete(path, false)) {
808 NOTREACHED();
809 return base::PLATFORM_FILE_ERROR_FAILED;
810 }
811 LOG(WARNING) << "A stray file detected";
812 }
813
790 if (handle) { 814 if (handle) {
791 error = underlying_file_util_->CreateOrOpen( 815 error = underlying_file_util_->CreateOrOpen(
792 context, path, file_flags, handle, &created); 816 context, path, file_flags, handle, &created);
793 // If this succeeds, we must close handle on any subsequent error. 817 // If this succeeds, we must close handle on any subsequent error.
794 } else { 818 } else {
795 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. 819 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
796 error = underlying_file_util_->EnsureFileExists( 820 error = underlying_file_util_->EnsureFileExists(
797 context, path, &created); 821 context, path, &created);
798 } 822 }
799 } 823 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 directories_[key] = database; 1049 directories_[key] = database;
1026 return database; 1050 return database;
1027 } 1051 }
1028 1052
1029 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( 1053 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin(
1030 const GURL& origin, bool create) { 1054 const GURL& origin, bool create) {
1031 if (!InitOriginDatabase(create)) 1055 if (!InitOriginDatabase(create))
1032 return FilePath(); 1056 return FilePath();
1033 FilePath directory_name; 1057 FilePath directory_name;
1034 std::string id = GetOriginIdentifierFromURL(origin); 1058 std::string id = GetOriginIdentifierFromURL(origin);
1035 if (!create && !origin_database_->HasOriginPath(id)) 1059
1060 bool exists_in_db = origin_database_->HasOriginPath(id);
1061 if (!exists_in_db && !create)
1036 return FilePath(); 1062 return FilePath();
1037 if (!origin_database_->GetPathForOrigin(id, &directory_name)) 1063 if (!origin_database_->GetPathForOrigin(id, &directory_name))
1038 return FilePath(); 1064 return FilePath();
1065
1039 FilePath path = file_system_directory_.Append(directory_name); 1066 FilePath path = file_system_directory_.Append(directory_name);
1040 if (!file_util::DirectoryExists(path) && 1067 bool exists_in_fs = file_util::DirectoryExists(path);
1041 (!create || !file_util::CreateDirectory(path))) 1068 if (!exists_in_db && exists_in_fs) {
1042 return FilePath(); 1069 if (!file_util::Delete(path, true))
1070 return FilePath();
1071 exists_in_fs = false;
1072 }
1073
1074 if (!exists_in_fs) {
1075 if (!create || !file_util::CreateDirectory(path))
1076 return FilePath();
1077 }
1078
1043 return path; 1079 return path;
1044 } 1080 }
1045 1081
1046 void ObfuscatedFileSystemFileUtil::MarkUsed() { 1082 void ObfuscatedFileSystemFileUtil::MarkUsed() {
1047 if (timer_.IsRunning()) 1083 if (timer_.IsRunning())
1048 timer_.Reset(); 1084 timer_.Reset();
1049 else 1085 else
1050 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this, 1086 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this,
1051 &ObfuscatedFileSystemFileUtil::DropDatabases); 1087 &ObfuscatedFileSystemFileUtil::DropDatabases);
1052 } 1088 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 return false; 1129 return false;
1094 } 1130 }
1095 origin_database_.reset( 1131 origin_database_.reset(
1096 new FileSystemOriginDatabase( 1132 new FileSystemOriginDatabase(
1097 file_system_directory_.AppendASCII(kOriginDatabaseName))); 1133 file_system_directory_.AppendASCII(kOriginDatabaseName)));
1098 } 1134 }
1099 return true; 1135 return true;
1100 } 1136 }
1101 1137
1102 } // namespace fileapi 1138 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698