| 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/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 10 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 void FileSystem::Reset(const FileOperationCallback& callback) { | 280 void FileSystem::Reset(const FileOperationCallback& callback) { |
| 281 // Discard the current loader and operation objects and renew them. This is to | 281 // Discard the current loader and operation objects and renew them. This is to |
| 282 // avoid that changes initiated before the metadata reset is applied after the | 282 // avoid that changes initiated before the metadata reset is applied after the |
| 283 // reset, which may cause an inconsistent state. | 283 // reset, which may cause an inconsistent state. |
| 284 // TODO(kinaba): callbacks held in the subcomponents are discarded. We might | 284 // TODO(kinaba): callbacks held in the subcomponents are discarded. We might |
| 285 // want to have a way to abort and flush callbacks in in-flight operations. | 285 // want to have a way to abort and flush callbacks in in-flight operations. |
| 286 ResetComponents(); | 286 ResetComponents(); |
| 287 | 287 |
| 288 base::PostTaskAndReplyWithResult( | 288 base::PostTaskAndReplyWithResult( |
| 289 blocking_task_runner_, | 289 blocking_task_runner_.get(), |
| 290 FROM_HERE, | 290 FROM_HERE, |
| 291 base::Bind(&ResetOnBlockingPool, resource_metadata_, cache_), | 291 base::Bind(&ResetOnBlockingPool, resource_metadata_, cache_), |
| 292 callback); | 292 callback); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void FileSystem::ResetComponents() { | 295 void FileSystem::ResetComponents() { |
| 296 file_system::OperationDelegate* delegate = this; | 296 file_system::OperationDelegate* delegate = this; |
| 297 | 297 |
| 298 about_resource_loader_.reset(new internal::AboutResourceLoader(scheduler_)); | 298 about_resource_loader_.reset(new internal::AboutResourceLoader(scheduler_)); |
| 299 loader_controller_.reset(new internal::LoaderController); | 299 loader_controller_.reset(new internal::LoaderController); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 truncate_operation_->Truncate(file_path, length, callback); | 503 truncate_operation_->Truncate(file_path, length, callback); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void FileSystem::Pin(const base::FilePath& file_path, | 506 void FileSystem::Pin(const base::FilePath& file_path, |
| 507 const FileOperationCallback& callback) { | 507 const FileOperationCallback& callback) { |
| 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 509 DCHECK(!callback.is_null()); | 509 DCHECK(!callback.is_null()); |
| 510 | 510 |
| 511 std::string* local_id = new std::string; | 511 std::string* local_id = new std::string; |
| 512 base::PostTaskAndReplyWithResult( | 512 base::PostTaskAndReplyWithResult( |
| 513 blocking_task_runner_, | 513 blocking_task_runner_.get(), |
| 514 FROM_HERE, | 514 FROM_HERE, |
| 515 base::Bind(&PinInternal, resource_metadata_, cache_, file_path, local_id), | 515 base::Bind(&PinInternal, resource_metadata_, cache_, file_path, local_id), |
| 516 base::Bind(&FileSystem::FinishPin, | 516 base::Bind(&FileSystem::FinishPin, |
| 517 weak_ptr_factory_.GetWeakPtr(), | 517 weak_ptr_factory_.GetWeakPtr(), |
| 518 callback, | 518 callback, |
| 519 base::Owned(local_id))); | 519 base::Owned(local_id))); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void FileSystem::FinishPin(const FileOperationCallback& callback, | 522 void FileSystem::FinishPin(const FileOperationCallback& callback, |
| 523 const std::string* local_id, | 523 const std::string* local_id, |
| 524 FileError error) { | 524 FileError error) { |
| 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 526 DCHECK(!callback.is_null()); | 526 DCHECK(!callback.is_null()); |
| 527 | 527 |
| 528 if (error == FILE_ERROR_OK) | 528 if (error == FILE_ERROR_OK) |
| 529 sync_client_->AddFetchTask(*local_id); | 529 sync_client_->AddFetchTask(*local_id); |
| 530 callback.Run(error); | 530 callback.Run(error); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void FileSystem::Unpin(const base::FilePath& file_path, | 533 void FileSystem::Unpin(const base::FilePath& file_path, |
| 534 const FileOperationCallback& callback) { | 534 const FileOperationCallback& callback) { |
| 535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 536 DCHECK(!callback.is_null()); | 536 DCHECK(!callback.is_null()); |
| 537 | 537 |
| 538 std::string* local_id = new std::string; | 538 std::string* local_id = new std::string; |
| 539 base::PostTaskAndReplyWithResult( | 539 base::PostTaskAndReplyWithResult( |
| 540 blocking_task_runner_, | 540 blocking_task_runner_.get(), |
| 541 FROM_HERE, | 541 FROM_HERE, |
| 542 base::Bind(&UnpinInternal, | 542 base::Bind( |
| 543 resource_metadata_, | 543 &UnpinInternal, resource_metadata_, cache_, file_path, local_id), |
| 544 cache_, | |
| 545 file_path, | |
| 546 local_id), | |
| 547 base::Bind(&FileSystem::FinishUnpin, | 544 base::Bind(&FileSystem::FinishUnpin, |
| 548 weak_ptr_factory_.GetWeakPtr(), | 545 weak_ptr_factory_.GetWeakPtr(), |
| 549 callback, | 546 callback, |
| 550 base::Owned(local_id))); | 547 base::Owned(local_id))); |
| 551 } | 548 } |
| 552 | 549 |
| 553 void FileSystem::FinishUnpin(const FileOperationCallback& callback, | 550 void FileSystem::FinishUnpin(const FileOperationCallback& callback, |
| 554 const std::string* local_id, | 551 const std::string* local_id, |
| 555 FileError error) { | 552 FileError error) { |
| 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 FileError error) { | 618 FileError error) { |
| 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 623 DCHECK(!callback.is_null()); | 620 DCHECK(!callback.is_null()); |
| 624 | 621 |
| 625 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. " | 622 DVLOG_IF(1, error != FILE_ERROR_OK) << "ReadDirectory failed. " |
| 626 << FileErrorToString(error); | 623 << FileErrorToString(error); |
| 627 | 624 |
| 628 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | 625 scoped_ptr<ResourceEntry> entry(new ResourceEntry); |
| 629 ResourceEntry* entry_ptr = entry.get(); | 626 ResourceEntry* entry_ptr = entry.get(); |
| 630 base::PostTaskAndReplyWithResult( | 627 base::PostTaskAndReplyWithResult( |
| 631 blocking_task_runner_, | 628 blocking_task_runner_.get(), |
| 632 FROM_HERE, | 629 FROM_HERE, |
| 633 base::Bind(&GetLocallyStoredResourceEntry, | 630 base::Bind(&GetLocallyStoredResourceEntry, |
| 634 resource_metadata_, | 631 resource_metadata_, |
| 635 cache_, | 632 cache_, |
| 636 file_path, | 633 file_path, |
| 637 entry_ptr), | 634 entry_ptr), |
| 638 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry))); | 635 base::Bind(&RunGetResourceEntryCallback, callback, base::Passed(&entry))); |
| 639 } | 636 } |
| 640 | 637 |
| 641 void FileSystem::ReadDirectory( | 638 void FileSystem::ReadDirectory( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 } | 792 } |
| 796 | 793 |
| 797 void FileSystem::OnEntryUpdatedByOperation(const std::string& local_id) { | 794 void FileSystem::OnEntryUpdatedByOperation(const std::string& local_id) { |
| 798 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), local_id); | 795 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), local_id); |
| 799 } | 796 } |
| 800 | 797 |
| 801 void FileSystem::OnDriveSyncError(file_system::DriveSyncErrorType type, | 798 void FileSystem::OnDriveSyncError(file_system::DriveSyncErrorType type, |
| 802 const std::string& local_id) { | 799 const std::string& local_id) { |
| 803 base::FilePath* file_path = new base::FilePath; | 800 base::FilePath* file_path = new base::FilePath; |
| 804 base::PostTaskAndReplyWithResult( | 801 base::PostTaskAndReplyWithResult( |
| 805 blocking_task_runner_, | 802 blocking_task_runner_.get(), |
| 806 FROM_HERE, | 803 FROM_HERE, |
| 807 base::Bind(&internal::ResourceMetadata::GetFilePath, | 804 base::Bind(&internal::ResourceMetadata::GetFilePath, |
| 808 base::Unretained(resource_metadata_), | 805 base::Unretained(resource_metadata_), |
| 809 local_id, | 806 local_id, |
| 810 file_path), | 807 file_path), |
| 811 base::Bind(&FileSystem::OnDriveSyncErrorAfterGetFilePath, | 808 base::Bind(&FileSystem::OnDriveSyncErrorAfterGetFilePath, |
| 812 weak_ptr_factory_.GetWeakPtr(), | 809 weak_ptr_factory_.GetWeakPtr(), |
| 813 type, | 810 type, |
| 814 base::Owned(file_path))); | 811 base::Owned(file_path))); |
| 815 } | 812 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 | 864 |
| 868 FileSystemMetadata metadata; | 865 FileSystemMetadata metadata; |
| 869 metadata.refreshing = change_list_loader_->IsRefreshing(); | 866 metadata.refreshing = change_list_loader_->IsRefreshing(); |
| 870 | 867 |
| 871 // Metadata related to delta update. | 868 // Metadata related to delta update. |
| 872 metadata.last_update_check_time = last_update_check_time_; | 869 metadata.last_update_check_time = last_update_check_time_; |
| 873 metadata.last_update_check_error = last_update_check_error_; | 870 metadata.last_update_check_error = last_update_check_error_; |
| 874 | 871 |
| 875 int64* largest_changestamp = new int64(0); | 872 int64* largest_changestamp = new int64(0); |
| 876 base::PostTaskAndReplyWithResult( | 873 base::PostTaskAndReplyWithResult( |
| 877 blocking_task_runner_, | 874 blocking_task_runner_.get(), |
| 878 FROM_HERE, | 875 FROM_HERE, |
| 879 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, | 876 base::Bind(&internal::ResourceMetadata::GetLargestChangestamp, |
| 880 base::Unretained(resource_metadata_), largest_changestamp), | 877 base::Unretained(resource_metadata_), |
| 881 base::Bind(&OnGetLargestChangestamp, metadata, callback, | 878 largest_changestamp), |
| 879 base::Bind(&OnGetLargestChangestamp, |
| 880 metadata, |
| 881 callback, |
| 882 base::Owned(largest_changestamp))); | 882 base::Owned(largest_changestamp))); |
| 883 } | 883 } |
| 884 | 884 |
| 885 void FileSystem::MarkCacheFileAsMounted( | 885 void FileSystem::MarkCacheFileAsMounted( |
| 886 const base::FilePath& drive_file_path, | 886 const base::FilePath& drive_file_path, |
| 887 const MarkMountedCallback& callback) { | 887 const MarkMountedCallback& callback) { |
| 888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 889 DCHECK(!callback.is_null()); | 889 DCHECK(!callback.is_null()); |
| 890 | 890 |
| 891 base::FilePath* cache_file_path = new base::FilePath; | 891 base::FilePath* cache_file_path = new base::FilePath; |
| 892 base::PostTaskAndReplyWithResult( | 892 base::PostTaskAndReplyWithResult( |
| 893 blocking_task_runner_, | 893 blocking_task_runner_.get(), |
| 894 FROM_HERE, | 894 FROM_HERE, |
| 895 base::Bind(&MarkCacheFileAsMountedInternal, | 895 base::Bind(&MarkCacheFileAsMountedInternal, |
| 896 resource_metadata_, | 896 resource_metadata_, |
| 897 cache_, | 897 cache_, |
| 898 drive_file_path, | 898 drive_file_path, |
| 899 cache_file_path), | 899 cache_file_path), |
| 900 base::Bind(&RunMarkMountedCallback, | 900 base::Bind( |
| 901 callback, | 901 &RunMarkMountedCallback, callback, base::Owned(cache_file_path))); |
| 902 base::Owned(cache_file_path))); | |
| 903 } | 902 } |
| 904 | 903 |
| 905 void FileSystem::MarkCacheFileAsUnmounted( | 904 void FileSystem::MarkCacheFileAsUnmounted( |
| 906 const base::FilePath& cache_file_path, | 905 const base::FilePath& cache_file_path, |
| 907 const FileOperationCallback& callback) { | 906 const FileOperationCallback& callback) { |
| 908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 909 DCHECK(!callback.is_null()); | 908 DCHECK(!callback.is_null()); |
| 910 | 909 |
| 911 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) { | 910 if (!cache_->IsUnderFileCacheDirectory(cache_file_path)) { |
| 912 callback.Run(FILE_ERROR_FAILED); | 911 callback.Run(FILE_ERROR_FAILED); |
| 913 return; | 912 return; |
| 914 } | 913 } |
| 915 | 914 |
| 916 base::PostTaskAndReplyWithResult( | 915 base::PostTaskAndReplyWithResult( |
| 917 blocking_task_runner_, | 916 blocking_task_runner_.get(), |
| 918 FROM_HERE, | 917 FROM_HERE, |
| 919 base::Bind(&internal::FileCache::MarkAsUnmounted, | 918 base::Bind(&internal::FileCache::MarkAsUnmounted, |
| 920 base::Unretained(cache_), | 919 base::Unretained(cache_), |
| 921 cache_file_path), | 920 cache_file_path), |
| 922 callback); | 921 callback); |
| 923 } | 922 } |
| 924 | 923 |
| 925 void FileSystem::AddPermission(const base::FilePath& drive_file_path, | 924 void FileSystem::AddPermission(const base::FilePath& drive_file_path, |
| 926 const std::string& email, | 925 const std::string& email, |
| 927 google_apis::drive::PermissionRole role, | 926 google_apis::drive::PermissionRole role, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 open_file_operation_->OpenFile(file_path, open_mode, mime_type, callback); | 975 open_file_operation_->OpenFile(file_path, open_mode, mime_type, callback); |
| 977 } | 976 } |
| 978 | 977 |
| 979 void FileSystem::GetPathFromResourceId(const std::string& resource_id, | 978 void FileSystem::GetPathFromResourceId(const std::string& resource_id, |
| 980 const GetFilePathCallback& callback) { | 979 const GetFilePathCallback& callback) { |
| 981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 982 DCHECK(!callback.is_null()); | 981 DCHECK(!callback.is_null()); |
| 983 | 982 |
| 984 base::FilePath* const file_path = new base::FilePath(); | 983 base::FilePath* const file_path = new base::FilePath(); |
| 985 base::PostTaskAndReplyWithResult( | 984 base::PostTaskAndReplyWithResult( |
| 986 blocking_task_runner_, | 985 blocking_task_runner_.get(), |
| 987 FROM_HERE, | 986 FROM_HERE, |
| 988 base::Bind(&GetPathFromResourceIdOnBlockingPool, | 987 base::Bind(&GetPathFromResourceIdOnBlockingPool, |
| 989 resource_metadata_, | 988 resource_metadata_, |
| 990 resource_id, | 989 resource_id, |
| 991 file_path), | 990 file_path), |
| 992 base::Bind(&GetPathFromResourceIdAfterGetPath, | 991 base::Bind(&GetPathFromResourceIdAfterGetPath, |
| 993 base::Owned(file_path), | 992 base::Owned(file_path), |
| 994 callback)); | 993 callback)); |
| 995 } | 994 } |
| 996 } // namespace drive | 995 } // namespace drive |
| OLD | NEW |