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" |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 // TODO(ericu): This could easily be made faster with help from the database. | 657 // TODO(ericu): This could easily be made faster with help from the database. |
658 if (!db->ListChildren(file_id, &children)) | 658 if (!db->ListChildren(file_id, &children)) |
659 return true; | 659 return true; |
660 return children.empty(); | 660 return children.empty(); |
661 } | 661 } |
662 | 662 |
663 class ObfuscatedFileSystemFileEnumerator | 663 class ObfuscatedFileSystemFileEnumerator |
664 : public FileSystemFileUtil::AbstractFileEnumerator { | 664 : public FileSystemFileUtil::AbstractFileEnumerator { |
665 public: | 665 public: |
666 ObfuscatedFileSystemFileEnumerator( | 666 ObfuscatedFileSystemFileEnumerator( |
667 FileSystemDirectoryDatabase* db, const FilePath& virtual_root_path) | 667 const FilePath& base_path, |
668 : db_(db) { | 668 FileSystemDirectoryDatabase* db, |
669 FileSystemOperationContext* context, | |
ericu
2011/08/25 18:29:30
You're assuming that this context will remain vali
tzik
2011/08/26 02:41:53
Make sense. I added a comment there.
| |
670 FileSystemFileUtil* underlying_file_util, | |
671 const FilePath& virtual_root_path) | |
672 : base_path_(base_path), | |
673 db_(db), | |
674 context_(context), | |
675 underlying_file_util_(underlying_file_util) { | |
kinuko
2011/08/25 09:28:49
DCHECK() for pointers? (db, context, underlying_fu
tzik
2011/08/26 02:41:53
Done.
| |
669 FileId file_id; | 676 FileId file_id; |
670 FileInfo file_info; | 677 FileInfo file_info; |
671 if (!db_->GetFileWithPath(virtual_root_path, &file_id)) | 678 if (!db_->GetFileWithPath(virtual_root_path, &file_id)) |
672 return; | 679 return; |
673 if (!db_->GetFileInfo(file_id, &file_info)) | 680 if (!db_->GetFileInfo(file_id, &file_info)) |
674 return; | 681 return; |
675 if (!file_info.is_directory()) | 682 if (!file_info.is_directory()) |
676 return; | 683 return; |
677 FileRecord record = { file_id, file_info, virtual_root_path }; | 684 FileRecord record = { file_id, file_info, virtual_root_path }; |
678 display_queue_.push(record); | 685 display_queue_.push(record); |
679 Next(); // Enumerators don't include the directory itself. | 686 Next(); // Enumerators don't include the directory itself. |
680 } | 687 } |
681 | 688 |
682 ~ObfuscatedFileSystemFileEnumerator() {} | 689 ~ObfuscatedFileSystemFileEnumerator() {} |
683 | 690 |
684 virtual FilePath Next() { | 691 virtual FilePath Next() OVERRIDE { |
685 ProcessRecurseQueue(); | 692 ProcessRecurseQueue(); |
686 if (display_queue_.empty()) | 693 if (display_queue_.empty()) |
687 return FilePath(); | 694 return FilePath(); |
688 current_ = display_queue_.front(); | 695 current_ = display_queue_.front(); |
689 display_queue_.pop(); | 696 display_queue_.pop(); |
690 if (current_.file_info.is_directory()) | 697 if (current_.file_info.is_directory()) |
691 recurse_queue_.push(current_); | 698 recurse_queue_.push(current_); |
692 return current_.file_path; | 699 return current_.file_path; |
693 } | 700 } |
694 | 701 |
695 virtual bool IsDirectory() { | 702 virtual int64 Size() OVERRIDE { |
703 if (IsDirectory()) | |
704 return 0; | |
705 FileSystemOperationContext context(*context_); | |
ericu
2011/08/25 18:29:30
There's no need to copy the context here; just pas
tzik
2011/08/26 02:41:53
I see. Done.
| |
706 | |
707 base::PlatformFileInfo file_info; | |
708 FilePath platform_file_path; | |
709 | |
710 FilePath local_path = base_path_.Append(current_.file_info.data_path); | |
711 base::PlatformFileError error = underlying_file_util_->GetFileInfo( | |
712 &context, local_path, &file_info, &platform_file_path); | |
713 if (error != base::PLATFORM_FILE_OK) { | |
714 LOG(WARNING) << "Lost a backing file."; | |
715 return 0; | |
716 } | |
717 return file_info.size; | |
718 } | |
719 | |
720 virtual bool IsDirectory() OVERRIDE { | |
696 return current_.file_info.is_directory(); | 721 return current_.file_info.is_directory(); |
697 } | 722 } |
698 | 723 |
699 private: | 724 private: |
700 typedef FileSystemDirectoryDatabase::FileId FileId; | 725 typedef FileSystemDirectoryDatabase::FileId FileId; |
701 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; | 726 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; |
702 | 727 |
703 struct FileRecord { | 728 struct FileRecord { |
704 FileId file_id; | 729 FileId file_id; |
705 FileInfo file_info; | 730 FileInfo file_info; |
(...skipping 15 matching lines...) Expand all Loading... | |
721 return; | 746 return; |
722 child.file_path = directory.file_path.Append(child.file_info.name); | 747 child.file_path = directory.file_path.Append(child.file_info.name); |
723 display_queue_.push(child); | 748 display_queue_.push(child); |
724 } | 749 } |
725 } | 750 } |
726 } | 751 } |
727 | 752 |
728 std::queue<FileRecord> display_queue_; | 753 std::queue<FileRecord> display_queue_; |
729 std::queue<FileRecord> recurse_queue_; | 754 std::queue<FileRecord> recurse_queue_; |
730 FileRecord current_; | 755 FileRecord current_; |
756 FilePath base_path_; | |
731 FileSystemDirectoryDatabase* db_; | 757 FileSystemDirectoryDatabase* db_; |
758 FileSystemOperationContext* context_; | |
759 FileSystemFileUtil* underlying_file_util_; | |
732 }; | 760 }; |
733 | 761 |
734 class ObfuscatedFileSystemOriginEnumerator | 762 class ObfuscatedFileSystemOriginEnumerator |
735 : public ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator { | 763 : public ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator { |
736 public: | 764 public: |
737 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; | 765 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; |
738 ObfuscatedFileSystemOriginEnumerator( | 766 ObfuscatedFileSystemOriginEnumerator( |
739 FileSystemOriginDatabase* origin_database, | 767 FileSystemOriginDatabase* origin_database, |
740 const FilePath& base_path) | 768 const FilePath& base_path) |
741 : base_path_(base_path) { | 769 : base_path_(base_path) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 } | 814 } |
787 | 815 |
788 FileSystemFileUtil::AbstractFileEnumerator* | 816 FileSystemFileUtil::AbstractFileEnumerator* |
789 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( | 817 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( |
790 FileSystemOperationContext* context, | 818 FileSystemOperationContext* context, |
791 const FilePath& root_path) { | 819 const FilePath& root_path) { |
792 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 820 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
793 context->src_origin_url(), context->src_type(), false); | 821 context->src_origin_url(), context->src_type(), false); |
794 if (!db) | 822 if (!db) |
795 return new FileSystemFileUtil::EmptyFileEnumerator(); | 823 return new FileSystemFileUtil::EmptyFileEnumerator(); |
796 return new ObfuscatedFileSystemFileEnumerator(db, root_path); | 824 return new ObfuscatedFileSystemFileEnumerator( |
825 GetDirectoryForOriginAndType(context->src_origin_url(), | |
826 context->src_type(), false), | |
827 db, | |
828 context, | |
829 underlying_file_util_.get(), | |
830 root_path); | |
797 } | 831 } |
798 | 832 |
799 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfoInternal( | 833 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfoInternal( |
800 FileSystemDirectoryDatabase* db, | 834 FileSystemDirectoryDatabase* db, |
801 FileSystemOperationContext* context, | 835 FileSystemOperationContext* context, |
802 FileId file_id, | 836 FileId file_id, |
803 FileInfo* local_info, | 837 FileInfo* local_info, |
804 base::PlatformFileInfo* file_info, | 838 base::PlatformFileInfo* file_info, |
805 FilePath* platform_file_path) { | 839 FilePath* platform_file_path) { |
806 DCHECK(db); | 840 DCHECK(db); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 return false; | 1211 return false; |
1178 } | 1212 } |
1179 origin_database_.reset( | 1213 origin_database_.reset( |
1180 new FileSystemOriginDatabase( | 1214 new FileSystemOriginDatabase( |
1181 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1215 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
1182 } | 1216 } |
1183 return true; | 1217 return true; |
1184 } | 1218 } |
1185 | 1219 |
1186 } // namespace fileapi | 1220 } // namespace fileapi |
OLD | NEW |