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

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

Issue 10701094: Don't keep file system directories around if they contain unrelated files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | no next file » | 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) 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 return FilePath(); 901 return FilePath();
902 FilePath::StringType type_string = GetDirectoryNameForType(type); 902 FilePath::StringType type_string = GetDirectoryNameForType(type);
903 if (type_string.empty()) { 903 if (type_string.empty()) {
904 LOG(WARNING) << "Unknown filesystem type requested:" << type; 904 LOG(WARNING) << "Unknown filesystem type requested:" << type;
905 905
906 if (error_code) 906 if (error_code)
907 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; 907 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL;
908 return FilePath(); 908 return FilePath();
909 } 909 }
910 FilePath path = origin_dir.Append(type_string); 910 FilePath path = origin_dir.Append(type_string);
911 base::PlatformFileError error = base::PLATFORM_FILE_OK;
911 if (!file_util::DirectoryExists(path) && 912 if (!file_util::DirectoryExists(path) &&
912 (!create || !file_util::CreateDirectory(path))) { 913 (!create || !file_util::CreateDirectory(path))) {
913 if (error_code) { 914 error = create ?
914 *error_code = create ?
915 base::PLATFORM_FILE_ERROR_FAILED : 915 base::PLATFORM_FILE_ERROR_FAILED :
916 base::PLATFORM_FILE_ERROR_NOT_FOUND; 916 base::PLATFORM_FILE_ERROR_NOT_FOUND;
917 }
918 return FilePath();
919 } 917 }
920 918
921 if (error_code) 919 if (error_code)
922 *error_code = base::PLATFORM_FILE_OK; 920 *error_code = error;
kinuko 2012/07/09 11:47:50 I'm afraid some of the callsites of this method re
Bernhard Bauer 2012/07/09 15:20:28 Good point. Would you prefer updating all callsite
923 return path; 921 return path;
924 } 922 }
925 923
926 bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType( 924 bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
927 const GURL& origin, FileSystemType type) { 925 const GURL& origin, FileSystemType type) {
928 FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, false); 926 base::PlatformFileError error = base::PLATFORM_FILE_OK;
929 if (!file_util::PathExists(origin_type_path)) 927 FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, false,
928 &error);
929 if (origin_type_path.empty())
930 return true; 930 return true;
931 931
932 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. 932 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) {
933 // We ignore its error now since 1) it doesn't matter the final result, and 933 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase.
934 // 2) it always returns false in Windows because of LevelDB's implementation. 934 // We ignore its error now since 1) it doesn't matter the final result, and
935 // Information about failure would be useful for debugging. 935 // 2) it always returns false in Windows because of LevelDB's
936 DestroyDirectoryDatabase(origin, type); 936 // implementation.
937 if (!file_util::Delete(origin_type_path, true /* recursive */)) 937 // Information about failure would be useful for debugging.
938 return false; 938 DestroyDirectoryDatabase(origin, type);
939 if (!file_util::Delete(origin_type_path, true /* recursive */))
940 return false;
941 }
939 942
940 FilePath origin_path = origin_type_path.DirName(); 943 FilePath origin_path = origin_type_path.DirName();
941 DCHECK_EQ(origin_path.value(), 944 DCHECK_EQ(origin_path.value(),
942 GetDirectoryForOrigin(origin, false, NULL).value()); 945 GetDirectoryForOrigin(origin, false, NULL).value());
943 946
944 // Delete the origin directory if the deleted one was the last remaining 947 // Delete the origin directory if the deleted one was the last remaining
945 // type for the origin. 948 // type for the origin, i.e. if the *other* type doesn't exist.
946 if (file_util::Delete(origin_path, false /* recursive */)) { 949 FileSystemType other_type = kFileSystemTypeUnknown;
950 switch (type) {
951 case kFileSystemTypeTemporary:
952 other_type = kFileSystemTypePersistent;
953 break;
954 case kFileSystemTypePersistent:
955 other_type = kFileSystemTypeTemporary;
956 break;
957 // These types shouldn't be used.
958 case kFileSystemTypeUnknown:
959 case kFileSystemTypeIsolated:
960 case kFileSystemTypeExternal:
961 case kFileSystemTypeTest:
962 NOTREACHED();
963 }
964 if (!file_util::DirectoryExists(
965 origin_path.Append(GetDirectoryNameForType(other_type)))) {
kinuko 2012/07/09 07:23:33 Could we instead check if the type directory is th
Bernhard Bauer 2012/07/09 09:03:29 Hmm, I think there can also be garbage directories
kinuko 2012/07/09 11:47:50 Ok...
947 InitOriginDatabase(false); 966 InitOriginDatabase(false);
948 if (origin_database_.get()) 967 if (origin_database_.get())
949 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin)); 968 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin));
969 if (!file_util::Delete(origin_path, true /* recursive */))
970 return false;
950 } 971 }
951 972
952 // At this point we are sure we had successfully deleted the origin/type 973 // At this point we are sure we had successfully deleted the origin/type
953 // directory, so just returning true here. 974 // directory, so just returning true here.
954 return true; 975 return true;
955 } 976 }
956 977
957 bool ObfuscatedFileUtil::MigrateFromOldSandbox( 978 bool ObfuscatedFileUtil::MigrateFromOldSandbox(
958 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { 979 const GURL& origin_url, FileSystemType type, const FilePath& src_root) {
959 if (!DestroyDirectoryDatabase(origin_url, type)) 980 if (!DestroyDirectoryDatabase(origin_url, type))
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 PlatformFileError error = NativeFileUtil::CreateDirectory( 1379 PlatformFileError error = NativeFileUtil::CreateDirectory(
1359 new_local_path, false /* exclusive */, false /* recursive */); 1380 new_local_path, false /* exclusive */, false /* recursive */);
1360 if (error != base::PLATFORM_FILE_OK) 1381 if (error != base::PLATFORM_FILE_OK)
1361 return error; 1382 return error;
1362 1383
1363 *local_path = new_local_path.AppendASCII(StringPrintf("%08" PRId64, number)); 1384 *local_path = new_local_path.AppendASCII(StringPrintf("%08" PRId64, number));
1364 return base::PLATFORM_FILE_OK; 1385 return base::PLATFORM_FILE_OK;
1365 } 1386 }
1366 1387
1367 } // namespace fileapi 1388 } // namespace fileapi
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698