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

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

Issue 16950028: Move file_util::Delete to the base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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) 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/browser/fileapi/obfuscated_file_util.h" 5 #include "webkit/browser/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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 if (origin_type_path.empty()) 894 if (origin_type_path.empty())
895 return true; 895 return true;
896 896
897 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { 897 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) {
898 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. 898 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase.
899 // We ignore its error now since 1) it doesn't matter the final result, and 899 // We ignore its error now since 1) it doesn't matter the final result, and
900 // 2) it always returns false in Windows because of LevelDB's 900 // 2) it always returns false in Windows because of LevelDB's
901 // implementation. 901 // implementation.
902 // Information about failure would be useful for debugging. 902 // Information about failure would be useful for debugging.
903 DestroyDirectoryDatabase(origin, type); 903 DestroyDirectoryDatabase(origin, type);
904 if (!file_util::Delete(origin_type_path, true /* recursive */)) 904 if (!base::Delete(origin_type_path, true /* recursive */))
905 return false; 905 return false;
906 } 906 }
907 907
908 base::FilePath origin_path = VirtualPath::DirName(origin_type_path); 908 base::FilePath origin_path = VirtualPath::DirName(origin_type_path);
909 DCHECK_EQ(origin_path.value(), 909 DCHECK_EQ(origin_path.value(),
910 GetDirectoryForOrigin(origin, false, NULL).value()); 910 GetDirectoryForOrigin(origin, false, NULL).value());
911 911
912 // At this point we are sure we had successfully deleted the origin/type 912 // At this point we are sure we had successfully deleted the origin/type
913 // directory (i.e. we're ready to just return true). 913 // directory (i.e. we're ready to just return true).
914 // See if we have other directories in this origin directory. 914 // See if we have other directories in this origin directory.
(...skipping 13 matching lines...) Expand all
928 return true; 928 return true;
929 } 929 }
930 } 930 }
931 931
932 // No other directories seem exist. Try deleting the entire origin directory. 932 // No other directories seem exist. Try deleting the entire origin directory.
933 InitOriginDatabase(false); 933 InitOriginDatabase(false);
934 if (origin_database_) { 934 if (origin_database_) {
935 origin_database_->RemovePathForOrigin( 935 origin_database_->RemovePathForOrigin(
936 webkit_database::GetIdentifierFromOrigin(origin)); 936 webkit_database::GetIdentifierFromOrigin(origin));
937 } 937 }
938 if (!file_util::Delete(origin_path, true /* recursive */)) 938 if (!base::Delete(origin_path, true /* recursive */))
939 return false; 939 return false;
940 940
941 return true; 941 return true;
942 } 942 }
943 943
944 // static 944 // static
945 base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( 945 base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType(
946 FileSystemType type) { 946 FileSystemType type) {
947 switch (type) { 947 switch (type) {
948 case kFileSystemTypeTemporary: 948 case kFileSystemTypeTemporary:
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1097
1098 bool created = false; 1098 bool created = false;
1099 if (!src_file_path.empty()) { 1099 if (!src_file_path.empty()) {
1100 DCHECK(!file_flags); 1100 DCHECK(!file_flags);
1101 DCHECK(!handle); 1101 DCHECK(!handle);
1102 error = NativeFileUtil::CopyOrMoveFile( 1102 error = NativeFileUtil::CopyOrMoveFile(
1103 src_file_path, dest_local_path, true /* copy */); 1103 src_file_path, dest_local_path, true /* copy */);
1104 created = true; 1104 created = true;
1105 } else { 1105 } else {
1106 if (file_util::PathExists(dest_local_path)) { 1106 if (file_util::PathExists(dest_local_path)) {
1107 if (!file_util::Delete(dest_local_path, true /* recursive */)) { 1107 if (!base::Delete(dest_local_path, true /* recursive */)) {
1108 NOTREACHED(); 1108 NOTREACHED();
1109 return base::PLATFORM_FILE_ERROR_FAILED; 1109 return base::PLATFORM_FILE_ERROR_FAILED;
1110 } 1110 }
1111 LOG(WARNING) << "A stray file detected"; 1111 LOG(WARNING) << "A stray file detected";
1112 InvalidateUsageCache(context, dest_origin, dest_type); 1112 InvalidateUsageCache(context, dest_origin, dest_type);
1113 } 1113 }
1114 1114
1115 if (handle) { 1115 if (handle) {
1116 error = NativeFileUtil::CreateOrOpen( 1116 error = NativeFileUtil::CreateOrOpen(
1117 dest_local_path, file_flags, handle, &created); 1117 dest_local_path, file_flags, handle, &created);
1118 // If this succeeds, we must close handle on any subsequent error. 1118 // If this succeeds, we must close handle on any subsequent error.
1119 } else { 1119 } else {
1120 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. 1120 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
1121 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); 1121 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created);
1122 } 1122 }
1123 } 1123 }
1124 if (error != base::PLATFORM_FILE_OK) 1124 if (error != base::PLATFORM_FILE_OK)
1125 return error; 1125 return error;
1126 1126
1127 if (!created) { 1127 if (!created) {
1128 NOTREACHED(); 1128 NOTREACHED();
1129 if (handle) { 1129 if (handle) {
1130 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); 1130 DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
1131 base::ClosePlatformFile(*handle); 1131 base::ClosePlatformFile(*handle);
1132 file_util::Delete(dest_local_path, false /* recursive */); 1132 base::Delete(dest_local_path, false /* recursive */);
1133 } 1133 }
1134 return base::PLATFORM_FILE_ERROR_FAILED; 1134 return base::PLATFORM_FILE_ERROR_FAILED;
1135 } 1135 }
1136 1136
1137 // This removes the root, including the trailing slash, leaving a relative 1137 // This removes the root, including the trailing slash, leaving a relative
1138 // path. 1138 // path.
1139 dest_file_info->data_path = base::FilePath( 1139 dest_file_info->data_path = base::FilePath(
1140 dest_local_path.value().substr(root.value().length() + 1)); 1140 dest_local_path.value().substr(root.value().length() + 1));
1141 1141
1142 FileId file_id; 1142 FileId file_id;
1143 if (!db->AddFileInfo(*dest_file_info, &file_id)) { 1143 if (!db->AddFileInfo(*dest_file_info, &file_id)) {
1144 if (handle) { 1144 if (handle) {
1145 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); 1145 DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
1146 base::ClosePlatformFile(*handle); 1146 base::ClosePlatformFile(*handle);
1147 } 1147 }
1148 file_util::Delete(dest_local_path, false /* recursive */); 1148 base::Delete(dest_local_path, false /* recursive */);
1149 return base::PLATFORM_FILE_ERROR_FAILED; 1149 return base::PLATFORM_FILE_ERROR_FAILED;
1150 } 1150 }
1151 TouchDirectory(db, dest_file_info->parent_id); 1151 TouchDirectory(db, dest_file_info->parent_id);
1152 1152
1153 return base::PLATFORM_FILE_OK; 1153 return base::PLATFORM_FILE_OK;
1154 } 1154 }
1155 1155
1156 base::FilePath ObfuscatedFileUtil::DataPathToLocalPath( 1156 base::FilePath ObfuscatedFileUtil::DataPathToLocalPath(
1157 const GURL& origin, FileSystemType type, const base::FilePath& data_path) { 1157 const GURL& origin, FileSystemType type, const base::FilePath& data_path) {
1158 PlatformFileError error = base::PLATFORM_FILE_OK; 1158 PlatformFileError error = base::PLATFORM_FILE_OK;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 } 1233 }
1234 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { 1234 if (!origin_database_->GetPathForOrigin(id, &directory_name)) {
1235 if (error_code) 1235 if (error_code)
1236 *error_code = base::PLATFORM_FILE_ERROR_FAILED; 1236 *error_code = base::PLATFORM_FILE_ERROR_FAILED;
1237 return base::FilePath(); 1237 return base::FilePath();
1238 } 1238 }
1239 1239
1240 base::FilePath path = file_system_directory_.Append(directory_name); 1240 base::FilePath path = file_system_directory_.Append(directory_name);
1241 bool exists_in_fs = file_util::DirectoryExists(path); 1241 bool exists_in_fs = file_util::DirectoryExists(path);
1242 if (!exists_in_db && exists_in_fs) { 1242 if (!exists_in_db && exists_in_fs) {
1243 if (!file_util::Delete(path, true)) { 1243 if (!base::Delete(path, true)) {
1244 if (error_code) 1244 if (error_code)
1245 *error_code = base::PLATFORM_FILE_ERROR_FAILED; 1245 *error_code = base::PLATFORM_FILE_ERROR_FAILED;
1246 return base::FilePath(); 1246 return base::FilePath();
1247 } 1247 }
1248 exists_in_fs = false; 1248 exists_in_fs = false;
1249 } 1249 }
1250 1250
1251 if (!exists_in_fs) { 1251 if (!exists_in_fs) {
1252 if (!create || !file_util::CreateDirectory(path)) { 1252 if (!create || !file_util::CreateDirectory(path)) {
1253 if (error_code) 1253 if (error_code)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 // special_storage_policy_->HasIsolatedStorage(origin) returns false 1446 // special_storage_policy_->HasIsolatedStorage(origin) returns false
1447 // for the same origin. 1447 // for the same origin.
1448 if (!isolated_origin_.is_empty()) { 1448 if (!isolated_origin_.is_empty()) {
1449 CHECK_EQ(isolated_origin_.spec(), origin.spec()); 1449 CHECK_EQ(isolated_origin_.spec(), origin.spec());
1450 return true; 1450 return true;
1451 } 1451 }
1452 return false; 1452 return false;
1453 } 1453 }
1454 1454
1455 } // namespace fileapi 1455 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/native_file_util.cc ('k') | webkit/browser/fileapi/obfuscated_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698