| 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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 FileError error, | 679 FileError error, |
| 680 scoped_ptr<ResourceEntry> entry) { | 680 scoped_ptr<ResourceEntry> entry) { |
| 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 682 DCHECK(!callback.is_null()); | 682 DCHECK(!callback.is_null()); |
| 683 | 683 |
| 684 if (error == FILE_ERROR_OK) { | 684 if (error == FILE_ERROR_OK) { |
| 685 CheckLocalModificationAndRun(entry.Pass(), callback); | 685 CheckLocalModificationAndRun(entry.Pass(), callback); |
| 686 return; | 686 return; |
| 687 } | 687 } |
| 688 | 688 |
| 689 // Start loading if needed. Note that directory_fetch_info is empty here, | 689 // If the information about the path is not in the local ResourceMetadata, |
| 690 // as we don't need to fetch the contents of a directory when we just need | 690 // try fetching information of the directory and retry. |
| 691 // to get an entry of the directory. | 691 LoadDirectoryIfNeeded( |
| 692 change_list_loader_->LoadIfNeeded( | 692 file_path.DirName(), |
| 693 DirectoryFetchInfo(), | |
| 694 base::Bind(&FileSystem::GetEntryInfoByPathAfterLoad, | 693 base::Bind(&FileSystem::GetEntryInfoByPathAfterLoad, |
| 695 weak_ptr_factory_.GetWeakPtr(), | 694 weak_ptr_factory_.GetWeakPtr(), |
| 696 file_path, | 695 file_path, |
| 697 callback)); | 696 callback)); |
| 698 } | 697 } |
| 699 | 698 |
| 700 void FileSystem::GetEntryInfoByPathAfterLoad( | 699 void FileSystem::GetEntryInfoByPathAfterLoad( |
| 701 const base::FilePath& file_path, | 700 const base::FilePath& file_path, |
| 702 const GetEntryInfoCallback& callback, | 701 const GetEntryInfoCallback& callback, |
| 703 FileError error) { | 702 FileError error) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 731 | 730 |
| 732 CheckLocalModificationAndRun(entry.Pass(), callback); | 731 CheckLocalModificationAndRun(entry.Pass(), callback); |
| 733 } | 732 } |
| 734 | 733 |
| 735 void FileSystem::ReadDirectoryByPath( | 734 void FileSystem::ReadDirectoryByPath( |
| 736 const base::FilePath& directory_path, | 735 const base::FilePath& directory_path, |
| 737 const ReadDirectoryWithSettingCallback& callback) { | 736 const ReadDirectoryWithSettingCallback& callback) { |
| 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 739 DCHECK(!callback.is_null()); | 738 DCHECK(!callback.is_null()); |
| 740 | 739 |
| 740 LoadDirectoryIfNeeded( |
| 741 directory_path, |
| 742 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, |
| 743 weak_ptr_factory_.GetWeakPtr(), |
| 744 directory_path, |
| 745 callback)); |
| 746 } |
| 747 |
| 748 void FileSystem::LoadDirectoryIfNeeded(const base::FilePath& directory_path, |
| 749 const FileOperationCallback& callback) { |
| 750 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 751 DCHECK(!callback.is_null()); |
| 752 |
| 741 // As described in GetEntryInfoByPath(), ResourceMetadata may know | 753 // As described in GetEntryInfoByPath(), ResourceMetadata may know |
| 742 // about the entry even if the file system is not yet fully loaded, hence we | 754 // about the entry even if the file system is not yet fully loaded, hence we |
| 743 // should just ask ResourceMetadata first. | 755 // should just ask ResourceMetadata first. |
| 744 resource_metadata_->GetEntryInfoByPath( | 756 resource_metadata_->GetEntryInfoByPath( |
| 745 directory_path, | 757 directory_path, |
| 746 base::Bind(&FileSystem::ReadDirectoryByPathAfterGetEntry, | 758 base::Bind(&FileSystem::LoadDirectoryIfNeededAfterGetEntry, |
| 747 weak_ptr_factory_.GetWeakPtr(), | 759 weak_ptr_factory_.GetWeakPtr(), |
| 748 directory_path, | 760 directory_path, |
| 749 callback)); | 761 callback)); |
| 750 } | 762 } |
| 751 | 763 |
| 752 void FileSystem::ReadDirectoryByPathAfterGetEntry( | 764 void FileSystem::LoadDirectoryIfNeededAfterGetEntry( |
| 753 const base::FilePath& directory_path, | 765 const base::FilePath& directory_path, |
| 754 const ReadDirectoryWithSettingCallback& callback, | 766 const FileOperationCallback& callback, |
| 755 FileError error, | 767 FileError error, |
| 756 scoped_ptr<ResourceEntry> entry) { | 768 scoped_ptr<ResourceEntry> entry) { |
| 757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 758 DCHECK(!callback.is_null()); | 770 DCHECK(!callback.is_null()); |
| 759 | 771 |
| 760 if (error != FILE_ERROR_OK) { | 772 if (error != FILE_ERROR_OK || |
| 761 // If we don't know about the directory, start loading. | 773 entry->resource_id() == util::kDriveOtherDirSpecialResourceId) { |
| 762 change_list_loader_->LoadIfNeeded( | 774 // If we don't know about the directory, or it is the "drive/other" |
| 763 DirectoryFetchInfo(), | 775 // directory that has to gather all orphan entries, start loading full |
| 764 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, | 776 // resource list. |
| 765 weak_ptr_factory_.GetWeakPtr(), | 777 change_list_loader_->LoadIfNeeded(DirectoryFetchInfo(), callback); |
| 766 directory_path, | |
| 767 callback)); | |
| 768 return; | 778 return; |
| 769 } | 779 } |
| 770 | 780 |
| 771 if (!entry->file_info().is_directory()) { | 781 if (!entry->file_info().is_directory()) { |
| 772 callback.Run(FILE_ERROR_NOT_A_DIRECTORY, | 782 callback.Run(FILE_ERROR_NOT_A_DIRECTORY); |
| 773 hide_hosted_docs_, | |
| 774 scoped_ptr<ResourceEntryVector>()); | |
| 775 return; | 783 return; |
| 776 } | 784 } |
| 777 | 785 |
| 778 // Pass the directory fetch info so we can fetch the contents of the | 786 // Pass the directory fetch info so we can fetch the contents of the |
| 779 // directory before loading change lists. | 787 // directory before loading change lists. |
| 780 DirectoryFetchInfo directory_fetch_info( | 788 DirectoryFetchInfo directory_fetch_info( |
| 781 entry->resource_id(), | 789 entry->resource_id(), |
| 782 entry->directory_specific_info().changestamp()); | 790 entry->directory_specific_info().changestamp()); |
| 783 change_list_loader_->LoadIfNeeded( | 791 change_list_loader_->LoadIfNeeded(directory_fetch_info, callback); |
| 784 directory_fetch_info, | |
| 785 base::Bind(&FileSystem::ReadDirectoryByPathAfterLoad, | |
| 786 weak_ptr_factory_.GetWeakPtr(), | |
| 787 directory_path, | |
| 788 callback)); | |
| 789 } | 792 } |
| 790 | 793 |
| 791 void FileSystem::ReadDirectoryByPathAfterLoad( | 794 void FileSystem::ReadDirectoryByPathAfterLoad( |
| 792 const base::FilePath& directory_path, | 795 const base::FilePath& directory_path, |
| 793 const ReadDirectoryWithSettingCallback& callback, | 796 const ReadDirectoryWithSettingCallback& callback, |
| 794 FileError error) { | 797 FileError error) { |
| 795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 796 DCHECK(!callback.is_null()); | 799 DCHECK(!callback.is_null()); |
| 797 | 800 |
| 798 if (error != FILE_ERROR_OK) { | 801 if (error != FILE_ERROR_OK) { |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); | 1817 util::ConvertPlatformFileInfoToResourceEntry(*file_info, &entry_file_info); |
| 1815 *entry->mutable_file_info() = entry_file_info; | 1818 *entry->mutable_file_info() = entry_file_info; |
| 1816 callback.Run(FILE_ERROR_OK, entry.Pass()); | 1819 callback.Run(FILE_ERROR_OK, entry.Pass()); |
| 1817 } | 1820 } |
| 1818 | 1821 |
| 1819 void FileSystem::CancelJobInScheduler(JobID id) { | 1822 void FileSystem::CancelJobInScheduler(JobID id) { |
| 1820 scheduler_->CancelJob(id); | 1823 scheduler_->CancelJob(id); |
| 1821 } | 1824 } |
| 1822 | 1825 |
| 1823 } // namespace drive | 1826 } // namespace drive |
| OLD | NEW |