| OLD | NEW |
| 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" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
| 17 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "webkit/fileapi/file_system_context.h" | 19 #include "webkit/fileapi/file_system_context.h" |
| 20 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 21 #include "webkit/fileapi/file_system_path_manager.h" | 21 #include "webkit/fileapi/file_system_path_manager.h" |
| 22 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
| 23 #include "webkit/fileapi/quota_file_util.h" | |
| 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 23 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 25 | 24 |
| 26 // TODO(ericu): Make deleting an origin [or a type under the origin, if it's the | 25 // TODO(ericu): Make deleting an origin [or a type under the origin, if it's the |
| 27 // last type] remove the origin from origin_database_ as well. | 26 // last type] remove the origin from origin_database_ as well. |
| 28 namespace { | 27 namespace { |
| 29 | 28 |
| 30 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes | 29 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes |
| 31 | 30 |
| 32 const char kOriginDatabaseName[] = "Origins"; | 31 const char kOriginDatabaseName[] = "Origins"; |
| 33 const char kDirectoryDatabaseName[] = "Paths"; | 32 const char kDirectoryDatabaseName[] = "Paths"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); | 46 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); |
| 48 | 47 |
| 49 } // namespace | 48 } // namespace |
| 50 | 49 |
| 51 namespace fileapi { | 50 namespace fileapi { |
| 52 | 51 |
| 53 using base::PlatformFile; | 52 using base::PlatformFile; |
| 54 using base::PlatformFileError; | 53 using base::PlatformFileError; |
| 55 | 54 |
| 56 ObfuscatedFileSystemFileUtil::ObfuscatedFileSystemFileUtil( | 55 ObfuscatedFileSystemFileUtil::ObfuscatedFileSystemFileUtil( |
| 57 const FilePath& file_system_directory) | 56 const FilePath& file_system_directory, |
| 58 : file_system_directory_(file_system_directory) { | 57 FileSystemFileUtil* underlying_file_util) |
| 58 : file_system_directory_(file_system_directory), |
| 59 underlying_file_util_(underlying_file_util) { |
| 59 } | 60 } |
| 60 | 61 |
| 61 ObfuscatedFileSystemFileUtil::~ObfuscatedFileSystemFileUtil() { | 62 ObfuscatedFileSystemFileUtil::~ObfuscatedFileSystemFileUtil() { |
| 62 DropDatabases(); | 63 DropDatabases(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen( | 66 PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen( |
| 66 FileSystemOperationContext* context, | 67 FileSystemOperationContext* context, |
| 67 const FilePath& virtual_path, int file_flags, | 68 const FilePath& virtual_path, int file_flags, |
| 68 PlatformFile* file_handle, bool* created) { | 69 PlatformFile* file_handle, bool* created) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 | 97 |
| 97 FileInfo file_info; | 98 FileInfo file_info; |
| 98 if (!db->GetFileInfo(file_id, &file_info)) { | 99 if (!db->GetFileInfo(file_id, &file_info)) { |
| 99 NOTREACHED(); | 100 NOTREACHED(); |
| 100 return base::PLATFORM_FILE_ERROR_FAILED; | 101 return base::PLATFORM_FILE_ERROR_FAILED; |
| 101 } | 102 } |
| 102 if (file_info.is_directory()) | 103 if (file_info.is_directory()) |
| 103 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 104 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 104 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 105 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 105 context->src_type(), file_info.data_path); | 106 context->src_type(), file_info.data_path); |
| 106 return QuotaFileUtil::GetInstance()->CreateOrOpen( | 107 return underlying_file_util_->CreateOrOpen( |
| 107 context, data_path, file_flags, file_handle, created); | 108 context, data_path, file_flags, file_handle, created); |
| 108 } | 109 } |
| 109 | 110 |
| 110 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( | 111 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( |
| 111 FileSystemOperationContext* context, | 112 FileSystemOperationContext* context, |
| 112 const FilePath& virtual_path, | 113 const FilePath& virtual_path, |
| 113 bool* created) { | 114 bool* created) { |
| 114 FileSystemDirectoryDatabase* db = | 115 FileSystemDirectoryDatabase* db = |
| 115 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 116 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
| 116 if (!db) | 117 if (!db) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 file_info->is_symbolic_link = false; | 178 file_info->is_symbolic_link = false; |
| 178 file_info->last_modified = local_info.modification_time; | 179 file_info->last_modified = local_info.modification_time; |
| 179 *platform_file_path = FilePath(); | 180 *platform_file_path = FilePath(); |
| 180 // We don't fill in ctime or atime. | 181 // We don't fill in ctime or atime. |
| 181 return base::PLATFORM_FILE_OK; | 182 return base::PLATFORM_FILE_OK; |
| 182 } | 183 } |
| 183 if (local_info.data_path.empty()) | 184 if (local_info.data_path.empty()) |
| 184 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 185 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 185 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 186 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 186 context->src_type(), local_info.data_path); | 187 context->src_type(), local_info.data_path); |
| 187 return QuotaFileUtil::GetInstance()->GetFileInfo( | 188 return underlying_file_util_->GetFileInfo( |
| 188 context, data_path, file_info, platform_file_path); | 189 context, data_path, file_info, platform_file_path); |
| 189 } | 190 } |
| 190 | 191 |
| 191 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( | 192 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( |
| 192 FileSystemOperationContext* context, | 193 FileSystemOperationContext* context, |
| 193 const FilePath& virtual_path, | 194 const FilePath& virtual_path, |
| 194 std::vector<base::FileUtilProxy::Entry>* entries) { | 195 std::vector<base::FileUtilProxy::Entry>* entries) { |
| 195 // TODO(kkanetkar): Implement directory read in multiple chunks. | 196 // TODO(kkanetkar): Implement directory read in multiple chunks. |
| 196 FileSystemDirectoryDatabase* db = | 197 FileSystemDirectoryDatabase* db = |
| 197 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 198 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 * Delete target entry's old backing file | 321 * Delete target entry's old backing file |
| 321 * Move-without-overwrite | 322 * Move-without-overwrite |
| 322 * Just update metadata | 323 * Just update metadata |
| 323 */ | 324 */ |
| 324 if (copy) { | 325 if (copy) { |
| 325 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), | 326 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), |
| 326 context->src_type(), src_file_info.data_path); | 327 context->src_type(), src_file_info.data_path); |
| 327 if (overwrite) { | 328 if (overwrite) { |
| 328 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 329 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
| 329 context->src_type(), dest_file_info.data_path); | 330 context->src_type(), dest_file_info.data_path); |
| 330 return QuotaFileUtil::GetInstance()->CopyOrMoveFile(context, | 331 return underlying_file_util_->CopyOrMoveFile(context, |
| 331 src_data_path, dest_data_path, copy); | 332 src_data_path, dest_data_path, copy); |
| 332 } else { | 333 } else { |
| 333 FileId dest_parent_id; | 334 FileId dest_parent_id; |
| 334 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 335 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
| 335 NOTREACHED(); // We shouldn't be called in this case. | 336 NOTREACHED(); // We shouldn't be called in this case. |
| 336 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 337 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 337 } | 338 } |
| 338 InitFileInfo(&dest_file_info, dest_parent_id, | 339 InitFileInfo(&dest_file_info, dest_parent_id, |
| 339 dest_file_path.BaseName().value()); | 340 dest_file_path.BaseName().value()); |
| 340 return CreateFile(context, context->dest_origin_url(), | 341 return CreateFile(context, context->dest_origin_url(), |
| 341 context->dest_type(), src_data_path, &dest_file_info, 0, | 342 context->dest_type(), src_data_path, &dest_file_info, 0, |
| 342 NULL); | 343 NULL); |
| 343 } | 344 } |
| 344 } else { // It's a move. | 345 } else { // It's a move. |
| 345 if (overwrite) { | 346 if (overwrite) { |
| 346 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) | 347 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) |
| 347 return base::PLATFORM_FILE_ERROR_FAILED; | 348 return base::PLATFORM_FILE_ERROR_FAILED; |
| 348 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), | 349 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), |
| 349 context->src_type(), dest_file_info.data_path); | 350 context->src_type(), dest_file_info.data_path); |
| 350 if (base::PLATFORM_FILE_OK != | 351 if (base::PLATFORM_FILE_OK != |
| 351 QuotaFileUtil::GetInstance()->DeleteFile(context, dest_data_path)) | 352 underlying_file_util_->DeleteFile(context, dest_data_path)) |
| 352 LOG(WARNING) << "Leaked a backing file."; | 353 LOG(WARNING) << "Leaked a backing file."; |
| 353 return base::PLATFORM_FILE_OK; | 354 return base::PLATFORM_FILE_OK; |
| 354 } else { | 355 } else { |
| 355 FileId dest_parent_id; | 356 FileId dest_parent_id; |
| 356 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 357 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
| 357 NOTREACHED(); | 358 NOTREACHED(); |
| 358 return base::PLATFORM_FILE_ERROR_FAILED; | 359 return base::PLATFORM_FILE_ERROR_FAILED; |
| 359 } | 360 } |
| 360 src_file_info.parent_id = dest_parent_id; | 361 src_file_info.parent_id = dest_parent_id; |
| 361 src_file_info.name = dest_file_path.BaseName().value(); | 362 src_file_info.name = dest_file_path.BaseName().value(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 380 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); | 381 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
| 381 FileInfo dest_file_info; | 382 FileInfo dest_file_info; |
| 382 if (overwrite) { | 383 if (overwrite) { |
| 383 if (!db->GetFileInfo(dest_file_id, &dest_file_info) || | 384 if (!db->GetFileInfo(dest_file_id, &dest_file_info) || |
| 384 dest_file_info.is_directory()) { | 385 dest_file_info.is_directory()) { |
| 385 NOTREACHED(); | 386 NOTREACHED(); |
| 386 return base::PLATFORM_FILE_ERROR_FAILED; | 387 return base::PLATFORM_FILE_ERROR_FAILED; |
| 387 } | 388 } |
| 388 FilePath dest_data_path = DataPathToLocalPath(context->dest_origin_url(), | 389 FilePath dest_data_path = DataPathToLocalPath(context->dest_origin_url(), |
| 389 context->dest_type(), dest_file_info.data_path); | 390 context->dest_type(), dest_file_info.data_path); |
| 390 return QuotaFileUtil::GetInstance()->CopyOrMoveFile(context, | 391 return underlying_file_util_->CopyOrMoveFile(context, |
| 391 src_file_path, dest_data_path, true /* copy */); | 392 src_file_path, dest_data_path, true /* copy */); |
| 392 } else { | 393 } else { |
| 393 FileId dest_parent_id; | 394 FileId dest_parent_id; |
| 394 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { | 395 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
| 395 NOTREACHED(); // We shouldn't be called in this case. | 396 NOTREACHED(); // We shouldn't be called in this case. |
| 396 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 397 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 397 } | 398 } |
| 398 InitFileInfo(&dest_file_info, dest_parent_id, | 399 InitFileInfo(&dest_file_info, dest_parent_id, |
| 399 dest_file_path.BaseName().value()); | 400 dest_file_path.BaseName().value()); |
| 400 return CreateFile(context, context->dest_origin_url(), | 401 return CreateFile(context, context->dest_origin_url(), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 418 NOTREACHED(); | 419 NOTREACHED(); |
| 419 return base::PLATFORM_FILE_ERROR_FAILED; | 420 return base::PLATFORM_FILE_ERROR_FAILED; |
| 420 } | 421 } |
| 421 if (!db->RemoveFileInfo(file_id)) { | 422 if (!db->RemoveFileInfo(file_id)) { |
| 422 NOTREACHED(); | 423 NOTREACHED(); |
| 423 return base::PLATFORM_FILE_ERROR_FAILED; | 424 return base::PLATFORM_FILE_ERROR_FAILED; |
| 424 } | 425 } |
| 425 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 426 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 426 context->src_type(), file_info.data_path); | 427 context->src_type(), file_info.data_path); |
| 427 if (base::PLATFORM_FILE_OK != | 428 if (base::PLATFORM_FILE_OK != |
| 428 QuotaFileUtil::GetInstance()->DeleteFile(context, data_path)) | 429 underlying_file_util_->DeleteFile(context, data_path)) |
| 429 LOG(WARNING) << "Leaked a backing file."; | 430 LOG(WARNING) << "Leaked a backing file."; |
| 430 return base::PLATFORM_FILE_OK; | 431 return base::PLATFORM_FILE_OK; |
| 431 } | 432 } |
| 432 | 433 |
| 433 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( | 434 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( |
| 434 FileSystemOperationContext* context, | 435 FileSystemOperationContext* context, |
| 435 const FilePath& virtual_path) { | 436 const FilePath& virtual_path) { |
| 436 FileSystemDirectoryDatabase* db = | 437 FileSystemDirectoryDatabase* db = |
| 437 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 438 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
| 438 if (!db) | 439 if (!db) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 467 return base::PLATFORM_FILE_ERROR_FAILED; | 468 return base::PLATFORM_FILE_ERROR_FAILED; |
| 468 } | 469 } |
| 469 if (file_info.is_directory()) { | 470 if (file_info.is_directory()) { |
| 470 file_info.modification_time = last_modified_time; | 471 file_info.modification_time = last_modified_time; |
| 471 if (!db->UpdateFileInfo(file_id, file_info)) | 472 if (!db->UpdateFileInfo(file_id, file_info)) |
| 472 return base::PLATFORM_FILE_ERROR_FAILED; | 473 return base::PLATFORM_FILE_ERROR_FAILED; |
| 473 return base::PLATFORM_FILE_OK; | 474 return base::PLATFORM_FILE_OK; |
| 474 } | 475 } |
| 475 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 476 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 476 context->src_type(), file_info.data_path); | 477 context->src_type(), file_info.data_path); |
| 477 return QuotaFileUtil::GetInstance()->Touch( | 478 return underlying_file_util_->Touch( |
| 478 context, data_path, last_access_time, last_modified_time); | 479 context, data_path, last_access_time, last_modified_time); |
| 479 } | 480 } |
| 480 FileId parent_id; | 481 FileId parent_id; |
| 481 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) | 482 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) |
| 482 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 483 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 483 | 484 |
| 484 FileInfo file_info; | 485 FileInfo file_info; |
| 485 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); | 486 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); |
| 486 // In the event of a sporadic underlying failure, we might create a new file, | 487 // In the event of a sporadic underlying failure, we might create a new file, |
| 487 // but fail to update its mtime + atime. | 488 // but fail to update its mtime + atime. |
| 488 PlatformFileError error = CreateFile(context, context->src_origin_url(), | 489 PlatformFileError error = CreateFile(context, context->src_origin_url(), |
| 489 context->src_type(), FilePath(), &file_info, 0, NULL); | 490 context->src_type(), FilePath(), &file_info, 0, NULL); |
| 490 if (base::PLATFORM_FILE_OK != error) | 491 if (base::PLATFORM_FILE_OK != error) |
| 491 return error; | 492 return error; |
| 492 | 493 |
| 493 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 494 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 494 context->src_type(), file_info.data_path); | 495 context->src_type(), file_info.data_path); |
| 495 return QuotaFileUtil::GetInstance()->Touch(context, data_path, | 496 return underlying_file_util_->Touch(context, data_path, |
| 496 last_access_time, last_modified_time); | 497 last_access_time, last_modified_time); |
| 497 } | 498 } |
| 498 | 499 |
| 499 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( | 500 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( |
| 500 FileSystemOperationContext* context, | 501 FileSystemOperationContext* context, |
| 501 const FilePath& virtual_path, | 502 const FilePath& virtual_path, |
| 502 int64 length) { | 503 int64 length) { |
| 503 FilePath local_path = | 504 FilePath local_path = |
| 504 GetLocalPath(context->src_origin_url(), context->src_type(), | 505 GetLocalPath(context->src_origin_url(), context->src_type(), |
| 505 virtual_path); | 506 virtual_path); |
| 506 if (local_path.empty()) | 507 if (local_path.empty()) |
| 507 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 508 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 508 return QuotaFileUtil::GetInstance()->Truncate( | 509 return underlying_file_util_->Truncate( |
| 509 context, local_path, length); | 510 context, local_path, length); |
| 510 } | 511 } |
| 511 | 512 |
| 512 bool ObfuscatedFileSystemFileUtil::PathExists( | 513 bool ObfuscatedFileSystemFileUtil::PathExists( |
| 513 FileSystemOperationContext* context, | 514 FileSystemOperationContext* context, |
| 514 const FilePath& virtual_path) { | 515 const FilePath& virtual_path) { |
| 515 FileSystemDirectoryDatabase* db = | 516 FileSystemDirectoryDatabase* db = |
| 516 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 517 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
| 517 if (!db) | 518 if (!db) |
| 518 return false; | 519 return false; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 return base::PLATFORM_FILE_ERROR_FAILED; | 712 return base::PLATFORM_FILE_ERROR_FAILED; |
| 712 // We use the third- and fourth-to-last digits as the directory. | 713 // We use the third- and fourth-to-last digits as the directory. |
| 713 int64 directory_number = number % 10000 / 100; | 714 int64 directory_number = number % 10000 / 100; |
| 714 FilePath path = | 715 FilePath path = |
| 715 GetDirectoryForOriginAndType(origin_url, type, false); | 716 GetDirectoryForOriginAndType(origin_url, type, false); |
| 716 if (path.empty()) | 717 if (path.empty()) |
| 717 return base::PLATFORM_FILE_ERROR_FAILED; | 718 return base::PLATFORM_FILE_ERROR_FAILED; |
| 718 | 719 |
| 719 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number)); | 720 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number)); |
| 720 PlatformFileError error; | 721 PlatformFileError error; |
| 721 error = QuotaFileUtil::GetInstance()->CreateDirectory( | 722 error = underlying_file_util_->CreateDirectory( |
| 722 context, path, false /* exclusive */, false /* recursive */); | 723 context, path, false /* exclusive */, false /* recursive */); |
| 723 if (base::PLATFORM_FILE_OK != error) | 724 if (base::PLATFORM_FILE_OK != error) |
| 724 return error; | 725 return error; |
| 725 path = path.AppendASCII(StringPrintf("%08" PRIu64, number)); | 726 path = path.AppendASCII(StringPrintf("%08" PRIu64, number)); |
| 726 FilePath data_path = LocalPathToDataPath(origin_url, type, path); | 727 FilePath data_path = LocalPathToDataPath(origin_url, type, path); |
| 727 if (data_path.empty()) | 728 if (data_path.empty()) |
| 728 return base::PLATFORM_FILE_ERROR_FAILED; | 729 return base::PLATFORM_FILE_ERROR_FAILED; |
| 729 bool created = false; | 730 bool created = false; |
| 730 if (!source_path.empty()) { | 731 if (!source_path.empty()) { |
| 731 DCHECK(!file_flags); | 732 DCHECK(!file_flags); |
| 732 DCHECK(!handle); | 733 DCHECK(!handle); |
| 733 error = QuotaFileUtil::GetInstance()->CopyOrMoveFile( | 734 error = underlying_file_util_->CopyOrMoveFile( |
| 734 context, source_path, path, true /* copy */); | 735 context, source_path, path, true /* copy */); |
| 735 created = true; | 736 created = true; |
| 736 } else { | 737 } else { |
| 737 if (handle) { | 738 if (handle) { |
| 738 error = QuotaFileUtil::GetInstance()->CreateOrOpen( | 739 error = underlying_file_util_->CreateOrOpen( |
| 739 context, path, file_flags, handle, &created); | 740 context, path, file_flags, handle, &created); |
| 740 // If this succeeds, we must close handle on any subsequent error. | 741 // If this succeeds, we must close handle on any subsequent error. |
| 741 } else { | 742 } else { |
| 742 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. | 743 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. |
| 743 error = QuotaFileUtil::GetInstance()->EnsureFileExists( | 744 error = underlying_file_util_->EnsureFileExists( |
| 744 context, path, &created); | 745 context, path, &created); |
| 745 } | 746 } |
| 746 } | 747 } |
| 747 if (error != base::PLATFORM_FILE_OK) | 748 if (error != base::PLATFORM_FILE_OK) |
| 748 return error; | 749 return error; |
| 749 | 750 |
| 750 if (!created) { | 751 if (!created) { |
| 751 NOTREACHED(); | 752 NOTREACHED(); |
| 752 if (handle) { | 753 if (handle) { |
| 753 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 754 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
| 754 base::ClosePlatformFile(*handle); | 755 base::ClosePlatformFile(*handle); |
| 755 QuotaFileUtil::GetInstance()->DeleteFile(context, path); | 756 underlying_file_util_->DeleteFile(context, path); |
| 756 } | 757 } |
| 757 return base::PLATFORM_FILE_ERROR_FAILED; | 758 return base::PLATFORM_FILE_ERROR_FAILED; |
| 758 } | 759 } |
| 759 file_info->data_path = data_path; | 760 file_info->data_path = data_path; |
| 760 FileId file_id; | 761 FileId file_id; |
| 761 if (!db->AddFileInfo(*file_info, &file_id)) { | 762 if (!db->AddFileInfo(*file_info, &file_id)) { |
| 762 if (handle) { | 763 if (handle) { |
| 763 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 764 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
| 764 base::ClosePlatformFile(*handle); | 765 base::ClosePlatformFile(*handle); |
| 765 } | 766 } |
| 766 QuotaFileUtil::GetInstance()->DeleteFile(context, path); | 767 underlying_file_util_->DeleteFile(context, path); |
| 767 return base::PLATFORM_FILE_ERROR_FAILED; | 768 return base::PLATFORM_FILE_ERROR_FAILED; |
| 768 } | 769 } |
| 769 | 770 |
| 770 return base::PLATFORM_FILE_OK; | 771 return base::PLATFORM_FILE_OK; |
| 771 } | 772 } |
| 772 | 773 |
| 773 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( | 774 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( |
| 774 const GURL& origin_url, | 775 const GURL& origin_url, |
| 775 FileSystemType type, | 776 FileSystemType type, |
| 776 const FilePath& virtual_path) { | 777 const FilePath& virtual_path) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 return false; | 1005 return false; |
| 1005 } | 1006 } |
| 1006 origin_database_.reset( | 1007 origin_database_.reset( |
| 1007 new FileSystemOriginDatabase( | 1008 new FileSystemOriginDatabase( |
| 1008 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1009 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
| 1009 } | 1010 } |
| 1010 return true; | 1011 return true; |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 } // namespace fileapi | 1014 } // namespace fileapi |
| OLD | NEW |