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

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

Issue 7057032: Integrated obfuscation with quota; all unit tests now pass (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eliminated a vector copy Created 9 years, 7 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 9
9 #include "base/file_util.h" 10 #include "base/file_util.h"
10 #include "base/format_macros.h" 11 #include "base/format_macros.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
14 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
15 #include "base/sys_string_conversions.h" 16 #include "base/sys_string_conversions.h"
16 #include "base/stl_util-inl.h" 17 #include "base/stl_util-inl.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "webkit/fileapi/file_system_context.h" 19 #include "webkit/fileapi/file_system_context.h"
19 #include "webkit/fileapi/file_system_operation_context.h" 20 #include "webkit/fileapi/file_system_operation_context.h"
20 #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"
21 #include "webkit/fileapi/quota_file_util.h" 23 #include "webkit/fileapi/quota_file_util.h"
22 #include "webkit/fileapi/sandbox_mount_point_provider.h" 24 #include "webkit/fileapi/sandbox_mount_point_provider.h"
23 25
24 // TODO(ericu): Every instance of FileSystemFileUtil in this file should switch 26 // TODO(ericu): Make deleting an origin [or a type under the origin, if it's the
25 // to QuotaFileUtil as soon as I sort out FileSystemPathManager's and 27 // last type] remove the origin from origin_database_ as well.
26 // SandboxMountPointProvider's lookups of the root path for a filesystem.
27 namespace { 28 namespace {
28 29
29 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes 30 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes
30 31
31 const char kOriginDatabaseName[] = "Origins"; 32 const char kOriginDatabaseName[] = "Origins";
32 const char kDirectoryDatabaseName[] = "Paths"; 33 const char kDirectoryDatabaseName[] = "Paths";
33 34
34 void InitFileInfo( 35 void InitFileInfo(
35 fileapi::FileSystemDirectoryDatabase::FileInfo* file_info, 36 fileapi::FileSystemDirectoryDatabase::FileInfo* file_info,
36 fileapi::FileSystemDirectoryDatabase::FileId parent_id, 37 fileapi::FileSystemDirectoryDatabase::FileId parent_id,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 FileInfo file_info; 97 FileInfo file_info;
97 if (!db->GetFileInfo(file_id, &file_info)) { 98 if (!db->GetFileInfo(file_id, &file_info)) {
98 NOTREACHED(); 99 NOTREACHED();
99 return base::PLATFORM_FILE_ERROR_FAILED; 100 return base::PLATFORM_FILE_ERROR_FAILED;
100 } 101 }
101 if (file_info.is_directory()) 102 if (file_info.is_directory())
102 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 103 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
103 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 104 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
104 context->src_type(), file_info.data_path); 105 context->src_type(), file_info.data_path);
105 return FileSystemFileUtil::GetInstance()->CreateOrOpen( 106 return QuotaFileUtil::GetInstance()->CreateOrOpen(
106 context, data_path, file_flags, file_handle, created); 107 context, data_path, file_flags, file_handle, created);
107 } 108 }
108 109
109 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( 110 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists(
110 FileSystemOperationContext* context, 111 FileSystemOperationContext* context,
111 const FilePath& virtual_path, 112 const FilePath& virtual_path,
112 bool* created) { 113 bool* created) {
113 FileSystemDirectoryDatabase* db = 114 FileSystemDirectoryDatabase* db =
114 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); 115 GetDirectoryDatabase(context->src_origin_url(), context->src_type());
115 if (!db) 116 if (!db)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 file_info->is_symbolic_link = false; 177 file_info->is_symbolic_link = false;
177 file_info->last_modified = local_info.modification_time; 178 file_info->last_modified = local_info.modification_time;
178 *platform_file_path = FilePath(); 179 *platform_file_path = FilePath();
179 // We don't fill in ctime or atime. 180 // We don't fill in ctime or atime.
180 return base::PLATFORM_FILE_OK; 181 return base::PLATFORM_FILE_OK;
181 } 182 }
182 if (local_info.data_path.empty()) 183 if (local_info.data_path.empty())
183 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 184 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
184 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 185 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
185 context->src_type(), local_info.data_path); 186 context->src_type(), local_info.data_path);
186 return FileSystemFileUtil::GetInstance()->GetFileInfo( 187 return QuotaFileUtil::GetInstance()->GetFileInfo(
187 context, data_path, file_info, platform_file_path); 188 context, data_path, file_info, platform_file_path);
188 } 189 }
189 190
190 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( 191 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory(
191 FileSystemOperationContext* context, 192 FileSystemOperationContext* context,
192 const FilePath& virtual_path, 193 const FilePath& virtual_path,
193 std::vector<base::FileUtilProxy::Entry>* entries) { 194 std::vector<base::FileUtilProxy::Entry>* entries) {
194 // TODO(kkanetkar): Implement directory read in multiple chunks. 195 // TODO(kkanetkar): Implement directory read in multiple chunks.
195 FileSystemDirectoryDatabase* db = 196 FileSystemDirectoryDatabase* db =
196 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); 197 GetDirectoryDatabase(context->src_origin_url(), context->src_type());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 * Delete target entry's old backing file 324 * Delete target entry's old backing file
324 * Move-without-overwrite 325 * Move-without-overwrite
325 * Just update metadata 326 * Just update metadata
326 */ 327 */
327 if (copy) { 328 if (copy) {
328 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(), 329 FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(),
329 context->src_type(), src_file_info.data_path); 330 context->src_type(), src_file_info.data_path);
330 if (overwrite) { 331 if (overwrite) {
331 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), 332 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
332 context->src_type(), dest_file_info.data_path); 333 context->src_type(), dest_file_info.data_path);
333 return FileSystemFileUtil::GetInstance()->CopyOrMoveFile(context, 334 return QuotaFileUtil::GetInstance()->CopyOrMoveFile(context,
334 src_data_path, dest_data_path, copy); 335 src_data_path, dest_data_path, copy);
335 } else { 336 } else {
336 FileId dest_parent_id; 337 FileId dest_parent_id;
337 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 338 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
338 NOTREACHED(); // We shouldn't be called in this case. 339 NOTREACHED(); // We shouldn't be called in this case.
339 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 340 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
340 } 341 }
341 InitFileInfo(&dest_file_info, dest_parent_id, 342 InitFileInfo(&dest_file_info, dest_parent_id,
342 dest_file_path.BaseName().value()); 343 dest_file_path.BaseName().value());
343 return CreateFile(context, context->dest_origin_url(), 344 return CreateFile(context, context->dest_origin_url(),
344 context->dest_type(), src_data_path, &dest_file_info, 0, 345 context->dest_type(), src_data_path, &dest_file_info, 0,
345 NULL); 346 NULL);
346 } 347 }
347 } else { // It's a move. 348 } else { // It's a move.
348 if (overwrite) { 349 if (overwrite) {
349 if (!db->OverwritingMoveFile(src_file_id, dest_file_id)) 350 if (!db->OverwritingMoveFile(src_file_id, dest_file_id))
350 return base::PLATFORM_FILE_ERROR_FAILED; 351 return base::PLATFORM_FILE_ERROR_FAILED;
351 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), 352 FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
352 context->src_type(), dest_file_info.data_path); 353 context->src_type(), dest_file_info.data_path);
353 if (base::PLATFORM_FILE_OK != 354 if (base::PLATFORM_FILE_OK !=
354 FileSystemFileUtil::GetInstance()->DeleteFile( 355 QuotaFileUtil::GetInstance()->DeleteFile(context, dest_data_path))
355 context, dest_data_path))
356 LOG(WARNING) << "Leaked a backing file."; 356 LOG(WARNING) << "Leaked a backing file.";
357 return base::PLATFORM_FILE_OK; 357 return base::PLATFORM_FILE_OK;
358 } else { 358 } else {
359 FileId dest_parent_id; 359 FileId dest_parent_id;
360 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { 360 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
361 NOTREACHED(); 361 NOTREACHED();
362 return base::PLATFORM_FILE_ERROR_FAILED; 362 return base::PLATFORM_FILE_ERROR_FAILED;
363 } 363 }
364 src_file_info.parent_id = dest_parent_id; 364 src_file_info.parent_id = dest_parent_id;
365 src_file_info.name = dest_file_path.BaseName().value(); 365 src_file_info.name = dest_file_path.BaseName().value();
(...skipping 21 matching lines...) Expand all
387 NOTREACHED(); 387 NOTREACHED();
388 return base::PLATFORM_FILE_ERROR_FAILED; 388 return base::PLATFORM_FILE_ERROR_FAILED;
389 } 389 }
390 if (!db->RemoveFileInfo(file_id)) { 390 if (!db->RemoveFileInfo(file_id)) {
391 NOTREACHED(); 391 NOTREACHED();
392 return base::PLATFORM_FILE_ERROR_FAILED; 392 return base::PLATFORM_FILE_ERROR_FAILED;
393 } 393 }
394 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 394 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
395 context->src_type(), file_info.data_path); 395 context->src_type(), file_info.data_path);
396 if (base::PLATFORM_FILE_OK != 396 if (base::PLATFORM_FILE_OK !=
397 FileSystemFileUtil::GetInstance()->DeleteFile(context, data_path)) 397 QuotaFileUtil::GetInstance()->DeleteFile(context, data_path))
398 LOG(WARNING) << "Leaked a backing file."; 398 LOG(WARNING) << "Leaked a backing file.";
399 return base::PLATFORM_FILE_OK; 399 return base::PLATFORM_FILE_OK;
400 } 400 }
401 401
402 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( 402 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory(
403 FileSystemOperationContext* context, 403 FileSystemOperationContext* context,
404 const FilePath& virtual_path) { 404 const FilePath& virtual_path) {
405 FileSystemDirectoryDatabase* db = 405 FileSystemDirectoryDatabase* db =
406 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); 406 GetDirectoryDatabase(context->src_origin_url(), context->src_type());
407 if (!db) 407 if (!db)
(...skipping 28 matching lines...) Expand all
436 return base::PLATFORM_FILE_ERROR_FAILED; 436 return base::PLATFORM_FILE_ERROR_FAILED;
437 } 437 }
438 if (file_info.is_directory()) { 438 if (file_info.is_directory()) {
439 file_info.modification_time = last_modified_time; 439 file_info.modification_time = last_modified_time;
440 if (!db->UpdateFileInfo(file_id, file_info)) 440 if (!db->UpdateFileInfo(file_id, file_info))
441 return base::PLATFORM_FILE_ERROR_FAILED; 441 return base::PLATFORM_FILE_ERROR_FAILED;
442 return base::PLATFORM_FILE_OK; 442 return base::PLATFORM_FILE_OK;
443 } 443 }
444 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 444 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
445 context->src_type(), file_info.data_path); 445 context->src_type(), file_info.data_path);
446 return FileSystemFileUtil::GetInstance()->Touch( 446 return QuotaFileUtil::GetInstance()->Touch(
447 context, data_path, last_access_time, last_modified_time); 447 context, data_path, last_access_time, last_modified_time);
448 } 448 }
449 FileId parent_id; 449 FileId parent_id;
450 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) 450 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id))
451 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 451 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
452 452
453 FileInfo file_info; 453 FileInfo file_info;
454 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); 454 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
455 // In the event of a sporadic underlying failure, we might create a new file, 455 // In the event of a sporadic underlying failure, we might create a new file,
456 // but fail to update its mtime + atime. 456 // but fail to update its mtime + atime.
457 PlatformFileError error = CreateFile(context, context->src_origin_url(), 457 PlatformFileError error = CreateFile(context, context->src_origin_url(),
458 context->src_type(), FilePath(), &file_info, 0, NULL); 458 context->src_type(), FilePath(), &file_info, 0, NULL);
459 if (base::PLATFORM_FILE_OK != error) 459 if (base::PLATFORM_FILE_OK != error)
460 return error; 460 return error;
461 461
462 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), 462 FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
463 context->src_type(), file_info.data_path); 463 context->src_type(), file_info.data_path);
464 return FileSystemFileUtil::GetInstance()->Touch(context, data_path, 464 return QuotaFileUtil::GetInstance()->Touch(context, data_path,
465 last_access_time, last_modified_time); 465 last_access_time, last_modified_time);
466 } 466 }
467 467
468 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( 468 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate(
469 FileSystemOperationContext* context, 469 FileSystemOperationContext* context,
470 const FilePath& virtual_path, 470 const FilePath& virtual_path,
471 int64 length) { 471 int64 length) {
472 FilePath local_path = 472 FilePath local_path =
473 GetLocalPath(context->src_origin_url(), context->src_type(), 473 GetLocalPath(context->src_origin_url(), context->src_type(),
474 virtual_path); 474 virtual_path);
475 if (local_path.empty()) 475 if (local_path.empty())
476 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 476 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
477 return FileSystemFileUtil::GetInstance()->Truncate( 477 return QuotaFileUtil::GetInstance()->Truncate(
478 context, local_path, length); 478 context, local_path, length);
479 } 479 }
480 480
481 bool ObfuscatedFileSystemFileUtil::PathExists( 481 bool ObfuscatedFileSystemFileUtil::PathExists(
482 FileSystemOperationContext* context, 482 FileSystemOperationContext* context,
483 const FilePath& virtual_path) { 483 const FilePath& virtual_path) {
484 FileSystemDirectoryDatabase* db = 484 FileSystemDirectoryDatabase* db =
485 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); 485 GetDirectoryDatabase(context->src_origin_url(), context->src_type());
486 if (!db) 486 if (!db)
487 return false; 487 return false;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 596 }
597 } 597 }
598 } 598 }
599 599
600 std::queue<FileRecord> display_queue_; 600 std::queue<FileRecord> display_queue_;
601 std::queue<FileRecord> recurse_queue_; 601 std::queue<FileRecord> recurse_queue_;
602 FileRecord current_; 602 FileRecord current_;
603 FileSystemDirectoryDatabase* db_; 603 FileSystemDirectoryDatabase* db_;
604 }; 604 };
605 605
606 class ObfuscatedFileSystemOriginEnumerator
607 : public ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator {
608 public:
609 typedef FileSystemOriginDatabase::OriginRecord OriginRecord;
610 ObfuscatedFileSystemOriginEnumerator(
611 FileSystemOriginDatabase* origin_database,
612 const FilePath& base_path)
613 : base_path_(base_path) {
614 if (origin_database)
615 origin_database->ListAllOrigins(&origins_);
616 }
617
618 ~ObfuscatedFileSystemOriginEnumerator() {}
619
620 // Returns the next origin. Returns empty if there are no more origins.
621 virtual GURL Next() OVERRIDE {
622 OriginRecord record;
623 if (!origins_.empty()) {
624 record = origins_.back();
625 origins_.pop_back();
626 }
627 current_ = record;
628 return GetOriginURLFromIdentifier(record.origin);
629 }
630
631 // Returns the current origin's information.
632 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE {
633 if (current_.path.empty())
634 return false;
635 FilePath::StringType type_string =
636 ObfuscatedFileSystemFileUtil::GetDirectoryNameForType(type);
637 if (type_string.empty()) {
638 NOTREACHED();
639 return false;
640 }
641 FilePath path = base_path_.Append(current_.path).Append(type_string);
642 return file_util::DirectoryExists(path);
643 }
644
645 private:
646 std::vector<OriginRecord> origins_;
647 OriginRecord current_;
648 FilePath base_path_;
649 };
650
651 ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator*
652 ObfuscatedFileSystemFileUtil::CreateOriginEnumerator() {
653 std::vector<FileSystemOriginDatabase::OriginRecord> origins;
654
655 InitOriginDatabase(false);
656 return new ObfuscatedFileSystemOriginEnumerator(
657 origin_database_.get(), file_system_directory_);
658 }
659
606 FileSystemFileUtil::AbstractFileEnumerator* 660 FileSystemFileUtil::AbstractFileEnumerator*
607 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( 661 ObfuscatedFileSystemFileUtil::CreateFileEnumerator(
608 FileSystemOperationContext* context, 662 FileSystemOperationContext* context,
609 const FilePath& root_path) { 663 const FilePath& root_path) {
610 FileSystemDirectoryDatabase* db = 664 FileSystemDirectoryDatabase* db =
611 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); 665 GetDirectoryDatabase(context->src_origin_url(), context->src_type());
612 if (!db) 666 if (!db)
613 return new FileSystemFileUtil::EmptyFileEnumerator(); 667 return new FileSystemFileUtil::EmptyFileEnumerator();
614 return new ObfuscatedFileSystemFileEnumerator(db, root_path); 668 return new ObfuscatedFileSystemFileEnumerator(db, root_path);
615 } 669 }
(...skipping 10 matching lines...) Expand all
626 return base::PLATFORM_FILE_ERROR_FAILED; 680 return base::PLATFORM_FILE_ERROR_FAILED;
627 // We use the third- and fourth-to-last digits as the directory. 681 // We use the third- and fourth-to-last digits as the directory.
628 int64 directory_number = number % 10000 / 100; 682 int64 directory_number = number % 10000 / 100;
629 FilePath path = 683 FilePath path =
630 GetDirectoryForOriginAndType(origin_url, type, false); 684 GetDirectoryForOriginAndType(origin_url, type, false);
631 if (path.empty()) 685 if (path.empty())
632 return base::PLATFORM_FILE_ERROR_FAILED; 686 return base::PLATFORM_FILE_ERROR_FAILED;
633 687
634 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number)); 688 path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number));
635 PlatformFileError error; 689 PlatformFileError error;
636 error = FileSystemFileUtil::GetInstance()->CreateDirectory( 690 error = QuotaFileUtil::GetInstance()->CreateDirectory(
637 context, path, false /* exclusive */, false /* recursive */); 691 context, path, false /* exclusive */, false /* recursive */);
638 if (base::PLATFORM_FILE_OK != error) 692 if (base::PLATFORM_FILE_OK != error)
639 return error; 693 return error;
640 path = path.AppendASCII(StringPrintf("%08" PRIu64, number)); 694 path = path.AppendASCII(StringPrintf("%08" PRIu64, number));
641 FilePath data_path = LocalPathToDataPath(origin_url, type, path); 695 FilePath data_path = LocalPathToDataPath(origin_url, type, path);
642 if (data_path.empty()) 696 if (data_path.empty())
643 return base::PLATFORM_FILE_ERROR_FAILED; 697 return base::PLATFORM_FILE_ERROR_FAILED;
644 bool created = false; 698 bool created = false;
645 if (!source_path.empty()) { 699 if (!source_path.empty()) {
646 DCHECK(!file_flags); 700 DCHECK(!file_flags);
647 DCHECK(!handle); 701 DCHECK(!handle);
648 error = FileSystemFileUtil::GetInstance()->CopyOrMoveFile( 702 error = QuotaFileUtil::GetInstance()->CopyOrMoveFile(
649 context, source_path, path, true /* copy */); 703 context, source_path, path, true /* copy */);
650 created = true; 704 created = true;
651 } else { 705 } else {
652 if (handle) { 706 if (handle) {
653 error = FileSystemFileUtil::GetInstance()->CreateOrOpen( 707 error = QuotaFileUtil::GetInstance()->CreateOrOpen(
654 context, path, file_flags, handle, &created); 708 context, path, file_flags, handle, &created);
655 // If this succeeds, we must close handle on any subsequent error. 709 // If this succeeds, we must close handle on any subsequent error.
656 } else { 710 } else {
657 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. 711 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
658 error = FileSystemFileUtil::GetInstance()->EnsureFileExists( 712 error = QuotaFileUtil::GetInstance()->EnsureFileExists(
659 context, path, &created); 713 context, path, &created);
660 } 714 }
661 } 715 }
662 if (error != base::PLATFORM_FILE_OK) 716 if (error != base::PLATFORM_FILE_OK)
663 return error; 717 return error;
664 718
665 if (!created) { 719 if (!created) {
666 NOTREACHED(); 720 NOTREACHED();
667 if (handle) { 721 if (handle) {
668 base::ClosePlatformFile(*handle); 722 base::ClosePlatformFile(*handle);
669 FileSystemFileUtil::GetInstance()->DeleteFile(context, path); 723 QuotaFileUtil::GetInstance()->DeleteFile(context, path);
670 } 724 }
671 return base::PLATFORM_FILE_ERROR_FAILED; 725 return base::PLATFORM_FILE_ERROR_FAILED;
672 } 726 }
673 file_info->data_path = data_path; 727 file_info->data_path = data_path;
674 FileId file_id; 728 FileId file_id;
675 if (!db->AddFileInfo(*file_info, &file_id)) { 729 if (!db->AddFileInfo(*file_info, &file_id)) {
676 if (handle) 730 if (handle)
677 base::ClosePlatformFile(*handle); 731 base::ClosePlatformFile(*handle);
678 FileSystemFileUtil::GetInstance()->DeleteFile(context, path); 732 QuotaFileUtil::GetInstance()->DeleteFile(context, path);
679 return base::PLATFORM_FILE_ERROR_FAILED; 733 return base::PLATFORM_FILE_ERROR_FAILED;
680 } 734 }
681 735
682 return base::PLATFORM_FILE_OK; 736 return base::PLATFORM_FILE_OK;
683 } 737 }
684 738
685 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( 739 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath(
686 const GURL& origin_url, 740 const GURL& origin_url,
687 FileSystemType type, 741 FileSystemType type,
688 const FilePath& virtual_path) { 742 const FilePath& virtual_path) {
(...skipping 14 matching lines...) Expand all
703 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOriginAndType( 757 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOriginAndType(
704 const GURL& origin, FileSystemType type, bool create) { 758 const GURL& origin, FileSystemType type, bool create) {
705 FilePath origin_dir = GetDirectoryForOrigin(origin, create); 759 FilePath origin_dir = GetDirectoryForOrigin(origin, create);
706 if (origin_dir.empty()) 760 if (origin_dir.empty())
707 return FilePath(); 761 return FilePath();
708 FilePath::StringType type_string = GetDirectoryNameForType(type); 762 FilePath::StringType type_string = GetDirectoryNameForType(type);
709 if (type_string.empty()) { 763 if (type_string.empty()) {
710 LOG(WARNING) << "Unknown filesystem type requested:" << type; 764 LOG(WARNING) << "Unknown filesystem type requested:" << type;
711 return FilePath(); 765 return FilePath();
712 } 766 }
713 return origin_dir.Append(type_string); 767 FilePath path = origin_dir.Append(type_string);
768 if (!file_util::DirectoryExists(path) &&
769 (!create || !file_util::CreateDirectory(path)))
770 return FilePath();
771 return path;
714 } 772 }
715 773
716 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( 774 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin(
717 const GURL& origin, bool create) { 775 const GURL& origin, bool create) {
718 if (!origin_database_.get()) { 776 if (!InitOriginDatabase(create))
719 if (!create && !file_util::DirectoryExists(file_system_directory_)) { 777 return FilePath();
720 return FilePath();
721 }
722 if (!file_util::CreateDirectory(file_system_directory_)) {
723 LOG(WARNING) << "Failed to create FileSystem directory: " <<
724 file_system_directory_.value();
725 return FilePath();
726 }
727 origin_database_.reset(
728 new FileSystemOriginDatabase(
729 file_system_directory_.AppendASCII(kOriginDatabaseName)));
730 }
731 FilePath directory_name; 778 FilePath directory_name;
732 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from 779 std::string id = GetOriginIdentifierFromURL(origin);
733 // sandbox_mount_point_provider.cc, instead of just using origin.spec(). 780 if (!create && !origin_database_->HasOriginPath(id))
734 if (!create && !origin_database_->HasOriginPath(origin.spec()))
735 return FilePath(); 781 return FilePath();
736 if (!origin_database_->GetPathForOrigin(origin.spec(), &directory_name)) 782 if (!origin_database_->GetPathForOrigin(id, &directory_name))
737 return FilePath(); 783 return FilePath();
738 return file_system_directory_.Append(directory_name); 784 FilePath path = file_system_directory_.Append(directory_name);
785 if (!file_util::DirectoryExists(path) &&
786 (!create || !file_util::CreateDirectory(path)))
787 return FilePath();
788 return path;
739 } 789 }
740 790
741 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( 791 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox(
742 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { 792 const GURL& origin_url, FileSystemType type, const FilePath& src_root) {
743 if (!DestroyDirectoryDatabase(origin_url, type)) 793 if (!DestroyDirectoryDatabase(origin_url, type))
744 return false; 794 return false;
745 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); 795 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true);
746 if (dest_root.empty()) 796 if (dest_root.empty())
747 return false; 797 return false;
748 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); 798 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 NOTREACHED(); 843 NOTREACHED();
794 return false; 844 return false;
795 } 845 }
796 } 846 }
797 // TODO(ericu): Should we adjust the mtime of the root directory to match as 847 // TODO(ericu): Should we adjust the mtime of the root directory to match as
798 // well? 848 // well?
799 FilePath legacy_dest_dir = dest_root.Append(kLegacyDataDirectory); 849 FilePath legacy_dest_dir = dest_root.Append(kLegacyDataDirectory);
800 return file_util::Move(src_root, legacy_dest_dir); 850 return file_util::Move(src_root, legacy_dest_dir);
801 } 851 }
802 852
853 // static
803 FilePath::StringType ObfuscatedFileSystemFileUtil::GetDirectoryNameForType( 854 FilePath::StringType ObfuscatedFileSystemFileUtil::GetDirectoryNameForType(
804 FileSystemType type) const { 855 FileSystemType type) {
805 switch (type) { 856 switch (type) {
806 case kFileSystemTypeTemporary: 857 case kFileSystemTypeTemporary:
807 return kTemporaryDirectoryName; 858 return kTemporaryDirectoryName;
808 case kFileSystemTypePersistent: 859 case kFileSystemTypePersistent:
809 return kPersistentDirectoryName; 860 return kPersistentDirectoryName;
810 case kFileSystemTypeUnknown: 861 case kFileSystemTypeUnknown:
811 default: 862 default:
812 return FilePath::StringType(); 863 return FilePath::StringType();
813 } 864 }
814 } 865 }
(...skipping 22 matching lines...) Expand all
837 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( 888 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase(
838 const GURL& origin, FileSystemType type) { 889 const GURL& origin, FileSystemType type) {
839 890
840 MarkUsed(); 891 MarkUsed();
841 std::string type_string = 892 std::string type_string =
842 FileSystemPathManager::GetFileSystemTypeString(type); 893 FileSystemPathManager::GetFileSystemTypeString(type);
843 if (type_string.empty()) { 894 if (type_string.empty()) {
844 LOG(WARNING) << "Unknown filesystem type requested:" << type; 895 LOG(WARNING) << "Unknown filesystem type requested:" << type;
845 return NULL; 896 return NULL;
846 } 897 }
847 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from 898 std::string key = GetOriginIdentifierFromURL(origin) + type_string;
848 // sandbox_mount_point_provider.cc, instead of just using origin.spec().
849 std::string key = origin.spec() + type_string;
850 DirectoryMap::iterator iter = directories_.find(key); 899 DirectoryMap::iterator iter = directories_.find(key);
851 if (iter != directories_.end()) 900 if (iter != directories_.end())
852 return iter->second; 901 return iter->second;
853 902
854 FilePath path = GetDirectoryForOriginAndType(origin, type, true); 903 FilePath path = GetDirectoryForOriginAndType(origin, type, true);
855 if (path.empty()) 904 if (path.empty())
856 return NULL; 905 return NULL;
857 if (!file_util::DirectoryExists(path)) { 906 if (!file_util::DirectoryExists(path)) {
858 if (!file_util::CreateDirectory(path)) { 907 if (!file_util::CreateDirectory(path)) {
859 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); 908 LOG(WARNING) << "Failed to origin+type directory: " << path.value();
(...skipping 22 matching lines...) Expand all
882 } 931 }
883 932
884 bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase( 933 bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase(
885 const GURL& origin, FileSystemType type) { 934 const GURL& origin, FileSystemType type) {
886 std::string type_string = 935 std::string type_string =
887 FileSystemPathManager::GetFileSystemTypeString(type); 936 FileSystemPathManager::GetFileSystemTypeString(type);
888 if (type_string.empty()) { 937 if (type_string.empty()) {
889 LOG(WARNING) << "Unknown filesystem type requested:" << type; 938 LOG(WARNING) << "Unknown filesystem type requested:" << type;
890 return true; 939 return true;
891 } 940 }
892 // TODO(ericu): This should probably be using GetOriginIdentifierFromURL from 941 std::string key = GetOriginIdentifierFromURL(origin) + type_string;
893 // sandbox_mount_point_provider.cc, instead of just using origin.spec().
894 std::string key = origin.spec() + type_string;
895 DirectoryMap::iterator iter = directories_.find(key); 942 DirectoryMap::iterator iter = directories_.find(key);
896 if (iter != directories_.end()) 943 if (iter != directories_.end())
897 directories_.erase(iter); 944 directories_.erase(iter);
898 945
899 FilePath path = GetDirectoryForOriginAndType(origin, type, false); 946 FilePath path = GetDirectoryForOriginAndType(origin, type, false);
900 if (path.empty()) 947 if (path.empty())
901 return true; 948 return true;
902 if (!file_util::DirectoryExists(path)) 949 if (!file_util::DirectoryExists(path))
903 return true; 950 return true;
904 path = path.AppendASCII(kDirectoryDatabaseName); 951 path = path.AppendASCII(kDirectoryDatabaseName);
905 return FileSystemDirectoryDatabase::DestroyDatabase(path); 952 return FileSystemDirectoryDatabase::DestroyDatabase(path);
906 } 953 }
907 954
955 bool ObfuscatedFileSystemFileUtil::InitOriginDatabase(bool create) {
956 if (!origin_database_.get()) {
957 if (!create && !file_util::DirectoryExists(file_system_directory_))
958 return false;
959 if (!file_util::CreateDirectory(file_system_directory_)) {
960 LOG(WARNING) << "Failed to create FileSystem directory: " <<
961 file_system_directory_.value();
962 return false;
963 }
964 origin_database_.reset(
965 new FileSystemOriginDatabase(
966 file_system_directory_.AppendASCII(kOriginDatabaseName)));
967 }
968 return true;
969 }
970
908 } // namespace fileapi 971 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/obfuscated_file_system_file_util.h ('k') | webkit/fileapi/obfuscated_file_system_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698