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 "components/drive/file_system.h" | 5 #include "components/drive/file_system.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
9 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
10 #include "components/drive/change_list_loader.h" | 12 #include "components/drive/change_list_loader.h" |
11 #include "components/drive/directory_loader.h" | 13 #include "components/drive/directory_loader.h" |
12 #include "components/drive/drive.pb.h" | 14 #include "components/drive/drive.pb.h" |
13 #include "components/drive/drive_pref_names.h" | 15 #include "components/drive/drive_pref_names.h" |
14 #include "components/drive/file_cache.h" | 16 #include "components/drive/file_cache.h" |
15 #include "components/drive/file_change.h" | 17 #include "components/drive/file_change.h" |
16 #include "components/drive/file_system/copy_operation.h" | 18 #include "components/drive/file_system/copy_operation.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Runs the callback with arguments. | 146 // Runs the callback with arguments. |
145 void RunMarkMountedCallback(const MarkMountedCallback& callback, | 147 void RunMarkMountedCallback(const MarkMountedCallback& callback, |
146 base::FilePath* cache_file_path, | 148 base::FilePath* cache_file_path, |
147 FileError error) { | 149 FileError error) { |
148 DCHECK(!callback.is_null()); | 150 DCHECK(!callback.is_null()); |
149 callback.Run(error, *cache_file_path); | 151 callback.Run(error, *cache_file_path); |
150 } | 152 } |
151 | 153 |
152 // Callback for ResourceMetadata::GetLargestChangestamp. | 154 // Callback for ResourceMetadata::GetLargestChangestamp. |
153 // |callback| must not be null. | 155 // |callback| must not be null. |
154 void OnGetLargestChangestamp( | 156 void OnGetLargestChangestamp(FileSystemMetadata metadata, // Will be modified. |
155 FileSystemMetadata metadata, // Will be modified. | 157 const GetFilesystemMetadataCallback& callback, |
156 const GetFilesystemMetadataCallback& callback, | 158 const int64_t* largest_changestamp, |
157 const int64* largest_changestamp, | 159 FileError error) { |
158 FileError error) { | |
159 DCHECK(!callback.is_null()); | 160 DCHECK(!callback.is_null()); |
160 | 161 |
161 metadata.largest_changestamp = *largest_changestamp; | 162 metadata.largest_changestamp = *largest_changestamp; |
162 callback.Run(metadata); | 163 callback.Run(metadata); |
163 } | 164 } |
164 | 165 |
165 // Thin adapter to map GetFileCallback to FileOperationCallback. | 166 // Thin adapter to map GetFileCallback to FileOperationCallback. |
166 void GetFileCallbackToFileOperationCallbackAdapter( | 167 void GetFileCallbackToFileOperationCallbackAdapter( |
167 const FileOperationCallback& callback, | 168 const FileOperationCallback& callback, |
168 FileError error, | 169 FileError error, |
(...skipping 28 matching lines...) Expand all Loading... |
197 | 198 |
198 // Part of GetPathFromResourceId(). | 199 // Part of GetPathFromResourceId(). |
199 // Called when GetPathFromResourceIdInBlockingPool is complete. | 200 // Called when GetPathFromResourceIdInBlockingPool is complete. |
200 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path, | 201 void GetPathFromResourceIdAfterGetPath(base::FilePath* file_path, |
201 const GetFilePathCallback& callback, | 202 const GetFilePathCallback& callback, |
202 FileError error) { | 203 FileError error) { |
203 callback.Run(error, *file_path); | 204 callback.Run(error, *file_path); |
204 } | 205 } |
205 | 206 |
206 bool FreeDiskSpaceIfNeededForOnBlockingPool(internal::FileCache* cache, | 207 bool FreeDiskSpaceIfNeededForOnBlockingPool(internal::FileCache* cache, |
207 int64 num_bytes) { | 208 int64_t num_bytes) { |
208 return cache->FreeDiskSpaceIfNeededFor(num_bytes); | 209 return cache->FreeDiskSpaceIfNeededFor(num_bytes); |
209 } | 210 } |
210 | 211 |
211 uint64_t CalculateEvictableCacheSizeOnBlockingPool(internal::FileCache* cache) { | 212 uint64_t CalculateEvictableCacheSizeOnBlockingPool(internal::FileCache* cache) { |
212 return cache->CalculateEvictableCacheSize(); | 213 return cache->CalculateEvictableCacheSize(); |
213 } | 214 } |
214 | 215 |
215 // Excludes hosted documents from the given entries. | 216 // Excludes hosted documents from the given entries. |
216 // Used to implement ReadDirectory(). | 217 // Used to implement ReadDirectory(). |
217 void FilterHostedDocuments(const ReadDirectoryEntriesCallback& callback, | 218 void FilterHostedDocuments(const ReadDirectoryEntriesCallback& callback, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 const base::Time& last_access_time, | 514 const base::Time& last_access_time, |
514 const base::Time& last_modified_time, | 515 const base::Time& last_modified_time, |
515 const FileOperationCallback& callback) { | 516 const FileOperationCallback& callback) { |
516 DCHECK(thread_checker_.CalledOnValidThread()); | 517 DCHECK(thread_checker_.CalledOnValidThread()); |
517 DCHECK(!callback.is_null()); | 518 DCHECK(!callback.is_null()); |
518 touch_operation_->TouchFile( | 519 touch_operation_->TouchFile( |
519 file_path, last_access_time, last_modified_time, callback); | 520 file_path, last_access_time, last_modified_time, callback); |
520 } | 521 } |
521 | 522 |
522 void FileSystem::TruncateFile(const base::FilePath& file_path, | 523 void FileSystem::TruncateFile(const base::FilePath& file_path, |
523 int64 length, | 524 int64_t length, |
524 const FileOperationCallback& callback) { | 525 const FileOperationCallback& callback) { |
525 DCHECK(thread_checker_.CalledOnValidThread()); | 526 DCHECK(thread_checker_.CalledOnValidThread()); |
526 DCHECK(!callback.is_null()); | 527 DCHECK(!callback.is_null()); |
527 truncate_operation_->Truncate(file_path, length, callback); | 528 truncate_operation_->Truncate(file_path, length, callback); |
528 } | 529 } |
529 | 530 |
530 void FileSystem::Pin(const base::FilePath& file_path, | 531 void FileSystem::Pin(const base::FilePath& file_path, |
531 const FileOperationCallback& callback) { | 532 const FileOperationCallback& callback) { |
532 DCHECK(thread_checker_.CalledOnValidThread()); | 533 DCHECK(thread_checker_.CalledOnValidThread()); |
533 DCHECK(!callback.is_null()); | 534 DCHECK(!callback.is_null()); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 DCHECK(thread_checker_.CalledOnValidThread()); | 895 DCHECK(thread_checker_.CalledOnValidThread()); |
895 DCHECK(!callback.is_null()); | 896 DCHECK(!callback.is_null()); |
896 | 897 |
897 FileSystemMetadata metadata; | 898 FileSystemMetadata metadata; |
898 metadata.refreshing = change_list_loader_->IsRefreshing(); | 899 metadata.refreshing = change_list_loader_->IsRefreshing(); |
899 | 900 |
900 // Metadata related to delta update. | 901 // Metadata related to delta update. |
901 metadata.last_update_check_time = last_update_check_time_; | 902 metadata.last_update_check_time = last_update_check_time_; |
902 metadata.last_update_check_error = last_update_check_error_; | 903 metadata.last_update_check_error = last_update_check_error_; |
903 | 904 |
904 int64* largest_changestamp = new int64(0); | 905 int64_t* largest_changestamp = new int64_t(0); |
905 base::PostTaskAndReplyWithResult( | 906 base::PostTaskAndReplyWithResult( |
906 blocking_task_runner_.get(), | 907 blocking_task_runner_.get(), |
907 FROM_HERE, | 908 FROM_HERE, |
908 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, | 909 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, |
909 base::Unretained(resource_metadata_), | 910 base::Unretained(resource_metadata_), |
910 largest_changestamp), | 911 largest_changestamp), |
911 base::Bind(&OnGetLargestChangestamp, | 912 base::Bind(&OnGetLargestChangestamp, |
912 metadata, | 913 metadata, |
913 callback, | 914 callback, |
914 base::Owned(largest_changestamp))); | 915 base::Owned(largest_changestamp))); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 base::Bind(&GetPathFromResourceIdOnBlockingPool, | 1033 base::Bind(&GetPathFromResourceIdOnBlockingPool, |
1033 resource_metadata_, | 1034 resource_metadata_, |
1034 resource_id, | 1035 resource_id, |
1035 file_path), | 1036 file_path), |
1036 base::Bind(&GetPathFromResourceIdAfterGetPath, | 1037 base::Bind(&GetPathFromResourceIdAfterGetPath, |
1037 base::Owned(file_path), | 1038 base::Owned(file_path), |
1038 callback)); | 1039 callback)); |
1039 } | 1040 } |
1040 | 1041 |
1041 void FileSystem::FreeDiskSpaceIfNeededFor( | 1042 void FileSystem::FreeDiskSpaceIfNeededFor( |
1042 int64 num_bytes, | 1043 int64_t num_bytes, |
1043 const FreeDiskSpaceCallback& callback) { | 1044 const FreeDiskSpaceCallback& callback) { |
1044 DCHECK(thread_checker_.CalledOnValidThread()); | 1045 DCHECK(thread_checker_.CalledOnValidThread()); |
1045 DCHECK(!callback.is_null()); | 1046 DCHECK(!callback.is_null()); |
1046 base::PostTaskAndReplyWithResult( | 1047 base::PostTaskAndReplyWithResult( |
1047 blocking_task_runner_.get(), FROM_HERE, | 1048 blocking_task_runner_.get(), FROM_HERE, |
1048 base::Bind(&FreeDiskSpaceIfNeededForOnBlockingPool, cache_, num_bytes), | 1049 base::Bind(&FreeDiskSpaceIfNeededForOnBlockingPool, cache_, num_bytes), |
1049 callback); | 1050 callback); |
1050 } | 1051 } |
1051 | 1052 |
1052 void FileSystem::CalculateEvictableCacheSize( | 1053 void FileSystem::CalculateEvictableCacheSize( |
1053 const EvictableCacheSizeCallback& callback) { | 1054 const EvictableCacheSizeCallback& callback) { |
1054 DCHECK(thread_checker_.CalledOnValidThread()); | 1055 DCHECK(thread_checker_.CalledOnValidThread()); |
1055 DCHECK(!callback.is_null()); | 1056 DCHECK(!callback.is_null()); |
1056 base::PostTaskAndReplyWithResult( | 1057 base::PostTaskAndReplyWithResult( |
1057 blocking_task_runner_.get(), FROM_HERE, | 1058 blocking_task_runner_.get(), FROM_HERE, |
1058 base::Bind(&CalculateEvictableCacheSizeOnBlockingPool, cache_), callback); | 1059 base::Bind(&CalculateEvictableCacheSizeOnBlockingPool, cache_), callback); |
1059 } | 1060 } |
1060 } // namespace drive | 1061 } // namespace drive |
OLD | NEW |