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

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

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (current_.path.empty()) 237 if (current_.path.empty())
238 return false; 238 return false;
239 base::FilePath::StringType type_string = 239 base::FilePath::StringType type_string =
240 ObfuscatedFileUtil::GetDirectoryNameForType(type); 240 ObfuscatedFileUtil::GetDirectoryNameForType(type);
241 if (type_string.empty()) { 241 if (type_string.empty()) {
242 NOTREACHED(); 242 NOTREACHED();
243 return false; 243 return false;
244 } 244 }
245 base::FilePath path = 245 base::FilePath path =
246 base_file_path_.Append(current_.path).Append(type_string); 246 base_file_path_.Append(current_.path).Append(type_string);
247 return file_util::DirectoryExists(path); 247 return base::DirectoryExists(path);
248 } 248 }
249 249
250 private: 250 private:
251 std::vector<OriginRecord> origins_; 251 std::vector<OriginRecord> origins_;
252 OriginRecord current_; 252 OriginRecord current_;
253 base::FilePath base_file_path_; 253 base::FilePath base_file_path_;
254 }; 254 };
255 255
256 ObfuscatedFileUtil::ObfuscatedFileUtil( 256 ObfuscatedFileUtil::ObfuscatedFileUtil(
257 quota::SpecialStoragePolicy* special_storage_policy, 257 quota::SpecialStoragePolicy* special_storage_policy,
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 base::FilePath::StringType type_string = GetDirectoryNameForType(type); 867 base::FilePath::StringType type_string = GetDirectoryNameForType(type);
868 if (type_string.empty()) { 868 if (type_string.empty()) {
869 LOG(WARNING) << "Unknown filesystem type requested:" << type; 869 LOG(WARNING) << "Unknown filesystem type requested:" << type;
870 870
871 if (error_code) 871 if (error_code)
872 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; 872 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL;
873 return base::FilePath(); 873 return base::FilePath();
874 } 874 }
875 base::FilePath path = origin_dir.Append(type_string); 875 base::FilePath path = origin_dir.Append(type_string);
876 base::PlatformFileError error = base::PLATFORM_FILE_OK; 876 base::PlatformFileError error = base::PLATFORM_FILE_OK;
877 if (!file_util::DirectoryExists(path) && 877 if (!base::DirectoryExists(path) &&
878 (!create || !file_util::CreateDirectory(path))) { 878 (!create || !file_util::CreateDirectory(path))) {
879 error = create ? 879 error = create ?
880 base::PLATFORM_FILE_ERROR_FAILED : 880 base::PLATFORM_FILE_ERROR_FAILED :
881 base::PLATFORM_FILE_ERROR_NOT_FOUND; 881 base::PLATFORM_FILE_ERROR_NOT_FOUND;
882 } 882 }
883 883
884 if (error_code) 884 if (error_code)
885 *error_code = error; 885 *error_code = error;
886 return path; 886 return path;
887 } 887 }
(...skipping 27 matching lines...) Expand all
915 std::vector<FileSystemType> other_types; 915 std::vector<FileSystemType> other_types;
916 if (type != kFileSystemTypeTemporary) 916 if (type != kFileSystemTypeTemporary)
917 other_types.push_back(kFileSystemTypeTemporary); 917 other_types.push_back(kFileSystemTypeTemporary);
918 if (type != kFileSystemTypePersistent) 918 if (type != kFileSystemTypePersistent)
919 other_types.push_back(kFileSystemTypePersistent); 919 other_types.push_back(kFileSystemTypePersistent);
920 if (type != kFileSystemTypeSyncable) 920 if (type != kFileSystemTypeSyncable)
921 other_types.push_back(kFileSystemTypeSyncable); 921 other_types.push_back(kFileSystemTypeSyncable);
922 DCHECK(type != kFileSystemTypeSyncableForInternalSync); 922 DCHECK(type != kFileSystemTypeSyncableForInternalSync);
923 923
924 for (size_t i = 0; i < other_types.size(); ++i) { 924 for (size_t i = 0; i < other_types.size(); ++i) {
925 if (file_util::DirectoryExists( 925 if (base::DirectoryExists(
926 origin_path.Append(GetDirectoryNameForType(other_types[i])))) { 926 origin_path.Append(GetDirectoryNameForType(other_types[i])))) {
927 // Other type's directory exists; just return true here. 927 // Other type's directory exists; just return true here.
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(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 } 988 }
989 989
990 // static 990 // static
991 int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) { 991 int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) {
992 return UsageForPath(VirtualPath::BaseName(path).value().size()); 992 return UsageForPath(VirtualPath::BaseName(path).value().size());
993 } 993 }
994 994
995 void ObfuscatedFileUtil::MaybePrepopulateDatabase() { 995 void ObfuscatedFileUtil::MaybePrepopulateDatabase() {
996 base::FilePath isolated_origin_dir = file_system_directory_.Append( 996 base::FilePath isolated_origin_dir = file_system_directory_.Append(
997 SandboxIsolatedOriginDatabase::kOriginDirectory); 997 SandboxIsolatedOriginDatabase::kOriginDirectory);
998 if (!file_util::DirectoryExists(isolated_origin_dir)) 998 if (!base::DirectoryExists(isolated_origin_dir))
999 return; 999 return;
1000 1000
1001 const FileSystemType kPrepopulateTypes[] = { 1001 const FileSystemType kPrepopulateTypes[] = {
1002 kFileSystemTypePersistent, kFileSystemTypeTemporary 1002 kFileSystemTypePersistent, kFileSystemTypeTemporary
1003 }; 1003 };
1004 1004
1005 // Prepulate the directory database(s) if and only if this instance is 1005 // Prepulate the directory database(s) if and only if this instance is
1006 // initialized for isolated storage dedicated for a single origin. 1006 // initialized for isolated storage dedicated for a single origin.
1007 for (size_t i = 0; i < arraysize(kPrepopulateTypes); ++i) { 1007 for (size_t i = 0; i < arraysize(kPrepopulateTypes); ++i) {
1008 const FileSystemType type = kPrepopulateTypes[i]; 1008 const FileSystemType type = kPrepopulateTypes[i];
1009 base::FilePath::StringType type_string = GetDirectoryNameForType(type); 1009 base::FilePath::StringType type_string = GetDirectoryNameForType(type);
1010 DCHECK(!type_string.empty()); 1010 DCHECK(!type_string.empty());
1011 base::FilePath path = isolated_origin_dir.Append(type_string); 1011 base::FilePath path = isolated_origin_dir.Append(type_string);
1012 if (!file_util::DirectoryExists(path)) 1012 if (!base::DirectoryExists(path))
1013 continue; 1013 continue;
1014 scoped_ptr<SandboxDirectoryDatabase> db(new SandboxDirectoryDatabase(path)); 1014 scoped_ptr<SandboxDirectoryDatabase> db(new SandboxDirectoryDatabase(path));
1015 if (db->Init(SandboxDirectoryDatabase::FAIL_ON_CORRUPTION)) { 1015 if (db->Init(SandboxDirectoryDatabase::FAIL_ON_CORRUPTION)) {
1016 directories_[GetFileSystemTypeString(type)] = db.release(); 1016 directories_[GetFileSystemTypeString(type)] = db.release();
1017 MarkUsed(); 1017 MarkUsed();
1018 // Don't populate more than one database, as it may rather hurt 1018 // Don't populate more than one database, as it may rather hurt
1019 // performance. 1019 // performance.
1020 break; 1020 break;
1021 } 1021 }
1022 } 1022 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; 1231 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND;
1232 return base::FilePath(); 1232 return base::FilePath();
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 = base::DirectoryExists(path);
1242 if (!exists_in_db && exists_in_fs) { 1242 if (!exists_in_db && exists_in_fs) {
1243 if (!base::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) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 STLDeleteContainerPairSecondPointers( 1291 STLDeleteContainerPairSecondPointers(
1292 directories_.begin(), directories_.end()); 1292 directories_.begin(), directories_.end());
1293 directories_.clear(); 1293 directories_.clear();
1294 timer_.reset(); 1294 timer_.reset();
1295 } 1295 }
1296 1296
1297 bool ObfuscatedFileUtil::InitOriginDatabase(bool create) { 1297 bool ObfuscatedFileUtil::InitOriginDatabase(bool create) {
1298 if (origin_database_) 1298 if (origin_database_)
1299 return true; 1299 return true;
1300 1300
1301 if (!create && !file_util::DirectoryExists(file_system_directory_)) 1301 if (!create && !base::DirectoryExists(file_system_directory_))
1302 return false; 1302 return false;
1303 if (!file_util::CreateDirectory(file_system_directory_)) { 1303 if (!file_util::CreateDirectory(file_system_directory_)) {
1304 LOG(WARNING) << "Failed to create FileSystem directory: " << 1304 LOG(WARNING) << "Failed to create FileSystem directory: " <<
1305 file_system_directory_.value(); 1305 file_system_directory_.value();
1306 return false; 1306 return false;
1307 } 1307 }
1308 1308
1309 if (!isolated_origin_.is_empty()) { 1309 if (!isolated_origin_.is_empty()) {
1310 origin_database_.reset( 1310 origin_database_.reset(
1311 new SandboxIsolatedOriginDatabase( 1311 new SandboxIsolatedOriginDatabase(
(...skipping 134 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_unittest.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