| 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/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 bool success) { | 172 bool success) { |
| 173 DCHECK(!callback.is_null()); | 173 DCHECK(!callback.is_null()); |
| 174 callback.Run(success, *cache_entry); | 174 callback.Run(success, *cache_entry); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Callback for ResourceMetadata::GetLargestChangestamp. | 177 // Callback for ResourceMetadata::GetLargestChangestamp. |
| 178 // |callback| must not be null. | 178 // |callback| must not be null. |
| 179 void OnGetLargestChangestamp( | 179 void OnGetLargestChangestamp( |
| 180 FileSystemMetadata metadata, // Will be modified. | 180 FileSystemMetadata metadata, // Will be modified. |
| 181 const GetFilesystemMetadataCallback& callback, | 181 const GetFilesystemMetadataCallback& callback, |
| 182 int64 largest_changestamp) { | 182 const int64* largest_changestamp, |
| 183 FileError error) { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 184 DCHECK(!callback.is_null()); | 185 DCHECK(!callback.is_null()); |
| 185 | 186 |
| 186 metadata.largest_changestamp = largest_changestamp; | 187 metadata.largest_changestamp = *largest_changestamp; |
| 187 callback.Run(metadata); | 188 callback.Run(metadata); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // Thin adapter to map GetFileCallback to FileOperationCallback. | 191 // Thin adapter to map GetFileCallback to FileOperationCallback. |
| 191 void GetFileCallbackToFileOperationCallbackAdapter( | 192 void GetFileCallbackToFileOperationCallbackAdapter( |
| 192 const FileOperationCallback& callback, | 193 const FileOperationCallback& callback, |
| 193 FileError error, | 194 FileError error, |
| 194 const base::FilePath& unused_file_path, | 195 const base::FilePath& unused_file_path, |
| 195 scoped_ptr<ResourceEntry> unused_entry) { | 196 scoped_ptr<ResourceEntry> unused_entry) { |
| 196 callback.Run(error); | 197 callback.Run(error); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 208 // Part of GetPathFromResourceId(). | 209 // Part of GetPathFromResourceId(). |
| 209 // Obtains |file_path| from |resource_id|. The function should be run on the | 210 // Obtains |file_path| from |resource_id|. The function should be run on the |
| 210 // blocking pool. | 211 // blocking pool. |
| 211 FileError GetPathFromResourceIdOnBlockingPool( | 212 FileError GetPathFromResourceIdOnBlockingPool( |
| 212 internal::ResourceMetadata* resource_metadata, | 213 internal::ResourceMetadata* resource_metadata, |
| 213 const std::string& resource_id, | 214 const std::string& resource_id, |
| 214 base::FilePath* file_path) { | 215 base::FilePath* file_path) { |
| 215 std::string local_id; | 216 std::string local_id; |
| 216 const FileError error = | 217 const FileError error = |
| 217 resource_metadata->GetIdByResourceId(resource_id, &local_id); | 218 resource_metadata->GetIdByResourceId(resource_id, &local_id); |
| 218 *file_path = error == FILE_ERROR_OK ? | 219 if (error != FILE_ERROR_OK) |
| 219 resource_metadata->GetFilePath(local_id) : base::FilePath(); | 220 return error; |
| 220 return error; | 221 return resource_metadata->GetFilePath(local_id, file_path); |
| 221 } | 222 } |
| 222 | 223 |
| 223 // Part of GetPathFromResourceId(). | 224 // Part of GetPathFromResourceId(). |
| 224 // Called when GetPathFromResourceIdInBlockingPool is complete. | 225 // Called when GetPathFromResourceIdInBlockingPool is complete. |
| 225 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path, | 226 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path, |
| 226 const GetFilePathCallback& callback, | 227 const GetFilePathCallback& callback, |
| 227 FileError error) { | 228 FileError error) { |
| 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 229 callback.Run(error, *file_path); | 230 callback.Run(error, *file_path); |
| 230 } | 231 } |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 const base::FilePath& directory_path) { | 814 const base::FilePath& directory_path) { |
| 814 OnDirectoryChanged(directory_path); | 815 OnDirectoryChanged(directory_path); |
| 815 } | 816 } |
| 816 | 817 |
| 817 void FileSystem::OnEntryUpdatedByOperation(const std::string& local_id) { | 818 void FileSystem::OnEntryUpdatedByOperation(const std::string& local_id) { |
| 818 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), local_id); | 819 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), local_id); |
| 819 } | 820 } |
| 820 | 821 |
| 821 void FileSystem::OnDriveSyncError(file_system::DriveSyncErrorType type, | 822 void FileSystem::OnDriveSyncError(file_system::DriveSyncErrorType type, |
| 822 const std::string& local_id) { | 823 const std::string& local_id) { |
| 824 base::FilePath* file_path = new base::FilePath; |
| 823 base::PostTaskAndReplyWithResult( | 825 base::PostTaskAndReplyWithResult( |
| 824 blocking_task_runner_, | 826 blocking_task_runner_, |
| 825 FROM_HERE, | 827 FROM_HERE, |
| 826 base::Bind(&internal::ResourceMetadata::GetFilePath, | 828 base::Bind(&internal::ResourceMetadata::GetFilePath, |
| 827 base::Unretained(resource_metadata_), | 829 base::Unretained(resource_metadata_), |
| 828 local_id), | 830 local_id, |
| 831 file_path), |
| 829 base::Bind(&FileSystem::OnDriveSyncErrorAfterGetFilePath, | 832 base::Bind(&FileSystem::OnDriveSyncErrorAfterGetFilePath, |
| 830 weak_ptr_factory_.GetWeakPtr(), | 833 weak_ptr_factory_.GetWeakPtr(), |
| 831 type)); | 834 type, |
| 835 base::Owned(file_path))); |
| 832 } | 836 } |
| 833 | 837 |
| 834 void FileSystem::OnDriveSyncErrorAfterGetFilePath( | 838 void FileSystem::OnDriveSyncErrorAfterGetFilePath( |
| 835 file_system::DriveSyncErrorType type, | 839 file_system::DriveSyncErrorType type, |
| 836 const base::FilePath& path) { | 840 const base::FilePath* file_path, |
| 837 if (path.empty()) | 841 FileError error) { |
| 842 if (error != FILE_ERROR_OK) |
| 838 return; | 843 return; |
| 839 FOR_EACH_OBSERVER(FileSystemObserver, | 844 FOR_EACH_OBSERVER(FileSystemObserver, |
| 840 observers_, | 845 observers_, |
| 841 OnDriveSyncError(type, path)); | 846 OnDriveSyncError(type, *file_path)); |
| 842 } | 847 } |
| 843 | 848 |
| 844 void FileSystem::OnDirectoryChanged(const base::FilePath& directory_path) { | 849 void FileSystem::OnDirectoryChanged(const base::FilePath& directory_path) { |
| 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 846 | 851 |
| 847 FOR_EACH_OBSERVER(FileSystemObserver, observers_, | 852 FOR_EACH_OBSERVER(FileSystemObserver, observers_, |
| 848 OnDirectoryChanged(directory_path)); | 853 OnDirectoryChanged(directory_path)); |
| 849 } | 854 } |
| 850 | 855 |
| 851 void FileSystem::OnLoadFromServerComplete() { | 856 void FileSystem::OnLoadFromServerComplete() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 870 DCHECK(!callback.is_null()); | 875 DCHECK(!callback.is_null()); |
| 871 | 876 |
| 872 FileSystemMetadata metadata; | 877 FileSystemMetadata metadata; |
| 873 metadata.refreshing = change_list_loader_->IsRefreshing(); | 878 metadata.refreshing = change_list_loader_->IsRefreshing(); |
| 874 | 879 |
| 875 // Metadata related to delta update. | 880 // Metadata related to delta update. |
| 876 metadata.last_update_check_time = last_update_check_time_; | 881 metadata.last_update_check_time = last_update_check_time_; |
| 877 metadata.last_update_check_error = last_update_check_error_; | 882 metadata.last_update_check_error = last_update_check_error_; |
| 878 | 883 |
| 884 int64* largest_changestamp = new int64(0); |
| 879 base::PostTaskAndReplyWithResult( | 885 base::PostTaskAndReplyWithResult( |
| 880 blocking_task_runner_, | 886 blocking_task_runner_, |
| 881 FROM_HERE, | 887 FROM_HERE, |
| 882 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, | 888 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, |
| 883 base::Unretained(resource_metadata_)), | 889 base::Unretained(resource_metadata_), largest_changestamp), |
| 884 base::Bind(&OnGetLargestChangestamp, metadata, callback)); | 890 base::Bind(&OnGetLargestChangestamp, metadata, callback, |
| 891 base::Owned(largest_changestamp))); |
| 885 } | 892 } |
| 886 | 893 |
| 887 void FileSystem::MarkCacheFileAsMounted( | 894 void FileSystem::MarkCacheFileAsMounted( |
| 888 const base::FilePath& drive_file_path, | 895 const base::FilePath& drive_file_path, |
| 889 const MarkMountedCallback& callback) { | 896 const MarkMountedCallback& callback) { |
| 890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 891 DCHECK(!callback.is_null()); | 898 DCHECK(!callback.is_null()); |
| 892 | 899 |
| 893 base::FilePath* cache_file_path = new base::FilePath; | 900 base::FilePath* cache_file_path = new base::FilePath; |
| 894 base::PostTaskAndReplyWithResult( | 901 base::PostTaskAndReplyWithResult( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 FROM_HERE, | 1016 FROM_HERE, |
| 1010 base::Bind(&GetPathFromResourceIdOnBlockingPool, | 1017 base::Bind(&GetPathFromResourceIdOnBlockingPool, |
| 1011 resource_metadata_, | 1018 resource_metadata_, |
| 1012 resource_id, | 1019 resource_id, |
| 1013 file_path), | 1020 file_path), |
| 1014 base::Bind(&GetPathFromResourceIdAfterGetPath, | 1021 base::Bind(&GetPathFromResourceIdAfterGetPath, |
| 1015 base::Owned(file_path), | 1022 base::Owned(file_path), |
| 1016 callback)); | 1023 callback)); |
| 1017 } | 1024 } |
| 1018 } // namespace drive | 1025 } // namespace drive |
| OLD | NEW |