Chromium Code Reviews| 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_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 FileError error, | 656 FileError error, |
| 657 scoped_ptr<DriveEntryProto> entry_proto) { | 657 scoped_ptr<DriveEntryProto> entry_proto) { |
| 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 659 DCHECK(!callback.is_null()); | 659 DCHECK(!callback.is_null()); |
| 660 | 660 |
| 661 if (error == FILE_ERROR_OK) { | 661 if (error == FILE_ERROR_OK) { |
| 662 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 662 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
| 663 return; | 663 return; |
| 664 } | 664 } |
| 665 | 665 |
| 666 // Start loading if needed. Note that directory_fetch_info is empty here, | 666 // If the information about the path is not in the local ResourceMetadata, |
| 667 // as we don't need to fetch the contents of a directory when we just need | 667 // try fetching information of the directory and retry. |
| 668 // to get an entry of the directory. | 668 LoadDirectoryIfNeeded( |
| 669 change_list_loader_->LoadIfNeeded( | 669 file_path.DirName(), |
| 670 DirectoryFetchInfo(), | |
| 671 base::Bind(&FileSystem::GetEntryInfoByPathAfterLoad, | 670 base::Bind(&FileSystem::GetEntryInfoByPathAfterLoad, |
| 672 weak_ptr_factory_.GetWeakPtr(), | 671 weak_ptr_factory_.GetWeakPtr(), |
| 673 file_path, | 672 file_path, |
| 674 callback)); | 673 callback)); |
| 675 } | 674 } |
| 676 | 675 |
| 677 void FileSystem::GetEntryInfoByPathAfterLoad( | 676 void FileSystem::GetEntryInfoByPathAfterLoad( |
| 678 const base::FilePath& file_path, | 677 const base::FilePath& file_path, |
| 679 const GetEntryInfoCallback& callback, | 678 const GetEntryInfoCallback& callback, |
| 680 FileError error) { | 679 FileError error) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 708 | 707 |
| 709 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 708 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
| 710 } | 709 } |
| 711 | 710 |
| 712 void FileSystem::ReadDirectoryByPath( | 711 void FileSystem::ReadDirectoryByPath( |
| 713 const base::FilePath& directory_path, | 712 const base::FilePath& directory_path, |
| 714 const ReadDirectoryWithSettingCallback& callback) { | 713 const ReadDirectoryWithSettingCallback& callback) { |
| 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 716 DCHECK(!callback.is_null()); | 715 DCHECK(!callback.is_null()); |
| 717 | 716 |
| 717 LoadDirectoryIfNeeded( | |
| 718 directory_path, | |
| 719 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, | |
| 720 weak_ptr_factory_.GetWeakPtr(), | |
| 721 directory_path, | |
| 722 callback)); | |
| 723 } | |
| 724 | |
| 725 void FileSystem::LoadDirectoryIfNeeded(const base::FilePath& directory_path, | |
| 726 const FileOperationCallback& callback) { | |
| 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 728 DCHECK(!callback.is_null()); | |
| 729 | |
| 718 // As described in GetEntryInfoByPath(), ResourceMetadata may know | 730 // As described in GetEntryInfoByPath(), ResourceMetadata may know |
| 719 // about the entry even if the file system is not yet fully loaded, hence we | 731 // about the entry even if the file system is not yet fully loaded, hence we |
| 720 // should just ask ResourceMetadata first. | 732 // should just ask ResourceMetadata first. |
| 721 resource_metadata_->GetEntryInfoByPath( | 733 resource_metadata_->GetEntryInfoByPath( |
| 722 directory_path, | 734 directory_path, |
| 723 base::Bind(&FileSystem::ReadDirectoryByPathAfterGetEntry, | 735 base::Bind(&FileSystem::LoadDirectoryIfNeededAfterGetEntry, |
| 724 weak_ptr_factory_.GetWeakPtr(), | 736 weak_ptr_factory_.GetWeakPtr(), |
| 725 directory_path, | 737 directory_path, |
| 726 callback)); | 738 callback)); |
| 727 } | 739 } |
| 728 | 740 |
| 729 void FileSystem::ReadDirectoryByPathAfterGetEntry( | 741 void FileSystem::LoadDirectoryIfNeededAfterGetEntry( |
| 730 const base::FilePath& directory_path, | 742 const base::FilePath& directory_path, |
| 731 const ReadDirectoryWithSettingCallback& callback, | 743 const FileOperationCallback& callback, |
| 732 FileError error, | 744 FileError error, |
| 733 scoped_ptr<DriveEntryProto> entry_proto) { | 745 scoped_ptr<DriveEntryProto> entry_proto) { |
| 734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 735 DCHECK(!callback.is_null()); | 747 DCHECK(!callback.is_null()); |
| 736 | 748 |
| 737 if (error != FILE_ERROR_OK) { | 749 if (error != FILE_ERROR_OK) { |
| 738 // If we don't know about the directory, start loading. | 750 // If we don't know about the directory, start loading full feed. |
|
satorux1
2013/05/02 04:42:38
full feed -> full resource list.
kinaba
2013/05/02 11:32:11
Done.
| |
| 739 change_list_loader_->LoadIfNeeded( | 751 change_list_loader_->LoadIfNeeded(DirectoryFetchInfo(), callback); |
| 740 DirectoryFetchInfo(), | |
| 741 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, | |
| 742 weak_ptr_factory_.GetWeakPtr(), | |
| 743 directory_path, | |
| 744 callback)); | |
| 745 return; | 752 return; |
| 746 } | 753 } |
| 747 | 754 |
| 748 if (!entry_proto->file_info().is_directory()) { | 755 if (!entry_proto->file_info().is_directory()) { |
| 749 callback.Run(FILE_ERROR_NOT_A_DIRECTORY, | 756 callback.Run(FILE_ERROR_NOT_A_DIRECTORY); |
| 750 hide_hosted_docs_, | |
| 751 scoped_ptr<DriveEntryProtoVector>()); | |
| 752 return; | 757 return; |
| 753 } | 758 } |
| 754 | 759 |
| 755 // Pass the directory fetch info so we can fetch the contents of the | 760 // Pass the directory fetch info so we can fetch the contents of the |
| 756 // directory before loading change lists. | 761 // directory before loading change lists. |
| 757 DirectoryFetchInfo directory_fetch_info( | 762 DirectoryFetchInfo directory_fetch_info( |
| 758 entry_proto->resource_id(), | 763 entry_proto->resource_id(), |
| 759 entry_proto->directory_specific_info().changestamp()); | 764 entry_proto->directory_specific_info().changestamp()); |
| 760 change_list_loader_->LoadIfNeeded( | 765 change_list_loader_->LoadIfNeeded(directory_fetch_info, callback); |
| 761 directory_fetch_info, | |
| 762 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, | |
| 763 weak_ptr_factory_.GetWeakPtr(), | |
| 764 directory_path, | |
| 765 callback)); | |
| 766 } | 766 } |
| 767 | 767 |
| 768 void FileSystem::ReadDirectoryByPathAfterLoad( | 768 void FileSystem::ReadDirectoryByPathAfterLoad( |
| 769 const base::FilePath& directory_path, | 769 const base::FilePath& directory_path, |
| 770 const ReadDirectoryWithSettingCallback& callback, | 770 const ReadDirectoryWithSettingCallback& callback, |
| 771 FileError error) { | 771 FileError error) { |
| 772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 773 DCHECK(!callback.is_null()); | 773 DCHECK(!callback.is_null()); |
| 774 | 774 |
| 775 if (error != FILE_ERROR_OK) { | 775 if (error != FILE_ERROR_OK) { |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1791 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 1791 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 1792 *entry_proto->mutable_file_info() = entry_file_info; | 1792 *entry_proto->mutable_file_info() = entry_file_info; |
| 1793 callback.Run(FILE_ERROR_OK, entry_proto.Pass()); | 1793 callback.Run(FILE_ERROR_OK, entry_proto.Pass()); |
| 1794 } | 1794 } |
| 1795 | 1795 |
| 1796 void FileSystem::CancelJobInScheduler(JobID id) { | 1796 void FileSystem::CancelJobInScheduler(JobID id) { |
| 1797 scheduler_->CancelJob(id); | 1797 scheduler_->CancelJob(id); |
| 1798 } | 1798 } |
| 1799 | 1799 |
| 1800 } // namespace drive | 1800 } // namespace drive |
| OLD | NEW |