| OLD | NEW |
| 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 "chrome/browser/chromeos/drive/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 15 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
| 16 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 16 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
| 17 #include "chrome/browser/chromeos/drive/drive.pb.h" | 17 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 18 #include "chrome/browser/chromeos/drive/file_cache.h" | 18 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 19 #include "chrome/browser/chromeos/drive/file_system/close_file_operation.h" | |
| 20 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" | 19 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
| 21 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h
" | 20 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h
" |
| 22 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | 21 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
| 23 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 22 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| 24 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" | 23 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 25 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" | 24 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" |
| 26 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" | 25 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" |
| 27 #include "chrome/browser/chromeos/drive/file_system/search_operation.h" | 26 #include "chrome/browser/chromeos/drive/file_system/search_operation.h" |
| 28 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h" | 27 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h" |
| 29 #include "chrome/browser/chromeos/drive/file_system/truncate_operation.h" | 28 #include "chrome/browser/chromeos/drive/file_system/truncate_operation.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 &FileSystem::ReloadAfterReset, | 97 &FileSystem::ReloadAfterReset, |
| 99 weak_ptr_factory_.GetWeakPtr())); | 98 weak_ptr_factory_.GetWeakPtr())); |
| 100 } | 99 } |
| 101 | 100 |
| 102 void FileSystem::Initialize() { | 101 void FileSystem::Initialize() { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 | 103 |
| 105 SetupChangeListLoader(); | 104 SetupChangeListLoader(); |
| 106 | 105 |
| 107 file_system::OperationObserver* observer = this; | 106 file_system::OperationObserver* observer = this; |
| 108 close_file_operation_.reset( | |
| 109 new file_system::CloseFileOperation(blocking_task_runner_.get(), | |
| 110 observer, | |
| 111 resource_metadata_, | |
| 112 &open_files_)); | |
| 113 copy_operation_.reset( | 107 copy_operation_.reset( |
| 114 new file_system::CopyOperation(blocking_task_runner_.get(), | 108 new file_system::CopyOperation(blocking_task_runner_.get(), |
| 115 observer, | 109 observer, |
| 116 scheduler_, | 110 scheduler_, |
| 117 resource_metadata_, | 111 resource_metadata_, |
| 118 cache_, | 112 cache_, |
| 119 drive_service_, | 113 drive_service_, |
| 120 temporary_file_directory_)); | 114 temporary_file_directory_)); |
| 121 create_directory_operation_.reset(new file_system::CreateDirectoryOperation( | 115 create_directory_operation_.reset(new file_system::CreateDirectoryOperation( |
| 122 blocking_task_runner_.get(), observer, scheduler_, resource_metadata_)); | 116 blocking_task_runner_.get(), observer, scheduler_, resource_metadata_)); |
| 123 create_file_operation_.reset( | 117 create_file_operation_.reset( |
| 124 new file_system::CreateFileOperation(blocking_task_runner_.get(), | 118 new file_system::CreateFileOperation(blocking_task_runner_.get(), |
| 125 observer, | 119 observer, |
| 126 scheduler_, | 120 scheduler_, |
| 127 resource_metadata_, | 121 resource_metadata_, |
| 128 cache_)); | 122 cache_)); |
| 129 move_operation_.reset( | 123 move_operation_.reset( |
| 130 new file_system::MoveOperation(observer, scheduler_, resource_metadata_)); | 124 new file_system::MoveOperation(observer, scheduler_, resource_metadata_)); |
| 131 open_file_operation_.reset( | 125 open_file_operation_.reset( |
| 132 new file_system::OpenFileOperation(blocking_task_runner_.get(), | 126 new file_system::OpenFileOperation(blocking_task_runner_.get(), |
| 133 observer, | 127 observer, |
| 134 scheduler_, | 128 scheduler_, |
| 135 resource_metadata_, | 129 resource_metadata_, |
| 136 cache_, | 130 cache_, |
| 137 temporary_file_directory_, | 131 temporary_file_directory_)); |
| 138 &open_files_)); | |
| 139 remove_operation_.reset( | 132 remove_operation_.reset( |
| 140 new file_system::RemoveOperation(blocking_task_runner_.get(), | 133 new file_system::RemoveOperation(blocking_task_runner_.get(), |
| 141 observer, | 134 observer, |
| 142 scheduler_, | 135 scheduler_, |
| 143 resource_metadata_, | 136 resource_metadata_, |
| 144 cache_)); | 137 cache_)); |
| 145 touch_operation_.reset(new file_system::TouchOperation( | 138 touch_operation_.reset(new file_system::TouchOperation( |
| 146 blocking_task_runner_.get(), observer, scheduler_, resource_metadata_)); | 139 blocking_task_runner_.get(), observer, scheduler_, resource_metadata_)); |
| 147 truncate_operation_.reset( | 140 truncate_operation_.reset( |
| 148 new file_system::TruncateOperation(blocking_task_runner_.get(), | 141 new file_system::TruncateOperation(blocking_task_runner_.get(), |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // Metadata related to delta update. | 741 // Metadata related to delta update. |
| 749 metadata.last_update_check_time = last_update_check_time_; | 742 metadata.last_update_check_time = last_update_check_time_; |
| 750 metadata.last_update_check_error = last_update_check_error_; | 743 metadata.last_update_check_error = last_update_check_error_; |
| 751 | 744 |
| 752 resource_metadata_->GetLargestChangestampOnUIThread( | 745 resource_metadata_->GetLargestChangestampOnUIThread( |
| 753 base::Bind(&OnGetLargestChangestamp, metadata, callback)); | 746 base::Bind(&OnGetLargestChangestamp, metadata, callback)); |
| 754 } | 747 } |
| 755 | 748 |
| 756 void FileSystem::MarkCacheFileAsMounted( | 749 void FileSystem::MarkCacheFileAsMounted( |
| 757 const base::FilePath& drive_file_path, | 750 const base::FilePath& drive_file_path, |
| 758 const OpenFileCallback& callback) { | 751 const MarkMountedCallback& callback) { |
| 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 760 DCHECK(!callback.is_null()); | 753 DCHECK(!callback.is_null()); |
| 761 | 754 |
| 762 GetResourceEntryByPath( | 755 GetResourceEntryByPath( |
| 763 drive_file_path, | 756 drive_file_path, |
| 764 base::Bind(&FileSystem::MarkCacheFileAsMountedAfterGetResourceEntry, | 757 base::Bind(&FileSystem::MarkCacheFileAsMountedAfterGetResourceEntry, |
| 765 weak_ptr_factory_.GetWeakPtr(), callback)); | 758 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 766 } | 759 } |
| 767 | 760 |
| 768 void FileSystem::MarkCacheFileAsMountedAfterGetResourceEntry( | 761 void FileSystem::MarkCacheFileAsMountedAfterGetResourceEntry( |
| 769 const OpenFileCallback& callback, | 762 const MarkMountedCallback& callback, |
| 770 FileError error, | 763 FileError error, |
| 771 scoped_ptr<ResourceEntry> entry) { | 764 scoped_ptr<ResourceEntry> entry) { |
| 772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 773 DCHECK(!callback.is_null()); | 766 DCHECK(!callback.is_null()); |
| 774 | 767 |
| 775 if (error != FILE_ERROR_OK) { | 768 if (error != FILE_ERROR_OK) { |
| 776 callback.Run(error, base::FilePath()); | 769 callback.Run(error, base::FilePath()); |
| 777 return; | 770 return; |
| 778 } | 771 } |
| 779 | 772 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 832 |
| 840 void FileSystem::OpenFile(const base::FilePath& file_path, | 833 void FileSystem::OpenFile(const base::FilePath& file_path, |
| 841 OpenMode open_mode, | 834 OpenMode open_mode, |
| 842 const OpenFileCallback& callback) { | 835 const OpenFileCallback& callback) { |
| 843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 844 DCHECK(!callback.is_null()); | 837 DCHECK(!callback.is_null()); |
| 845 | 838 |
| 846 open_file_operation_->OpenFile(file_path, open_mode, callback); | 839 open_file_operation_->OpenFile(file_path, open_mode, callback); |
| 847 } | 840 } |
| 848 | 841 |
| 849 void FileSystem::CloseFile(const base::FilePath& file_path, | |
| 850 const FileOperationCallback& callback) { | |
| 851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 852 DCHECK(!callback.is_null()); | |
| 853 | |
| 854 close_file_operation_->CloseFile(file_path, callback); | |
| 855 } | |
| 856 | |
| 857 void FileSystem::CheckLocalModificationAndRun( | 842 void FileSystem::CheckLocalModificationAndRun( |
| 858 scoped_ptr<ResourceEntry> entry, | 843 scoped_ptr<ResourceEntry> entry, |
| 859 const GetResourceEntryCallback& callback) { | 844 const GetResourceEntryCallback& callback) { |
| 860 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 861 DCHECK(entry.get()); | 846 DCHECK(entry.get()); |
| 862 DCHECK(!callback.is_null()); | 847 DCHECK(!callback.is_null()); |
| 863 | 848 |
| 864 // For entries that will never be cached, use the original resource entry | 849 // For entries that will never be cached, use the original resource entry |
| 865 // as is. | 850 // as is. |
| 866 if (!entry->has_file_specific_info() || | 851 if (!entry->has_file_specific_info() || |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 return; | 936 return; |
| 952 } | 937 } |
| 953 | 938 |
| 954 PlatformFileInfoProto entry_file_info; | 939 PlatformFileInfoProto entry_file_info; |
| 955 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 940 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
| 956 *entry->mutable_file_info() = entry_file_info; | 941 *entry->mutable_file_info() = entry_file_info; |
| 957 callback.Run(FILE_ERROR_OK, entry.Pass()); | 942 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 958 } | 943 } |
| 959 | 944 |
| 960 } // namespace drive | 945 } // namespace drive |
| OLD | NEW |