Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/chromeos/drive/file_system.cc

Issue 23441049: drive: Enable recursive fast-fetch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 namespace { 50 namespace {
51 51
52 // Gets a ResourceEntry from the metadata, and overwrites its file info when the 52 // Gets a ResourceEntry from the metadata, and overwrites its file info when the
53 // cached file is dirty. 53 // cached file is dirty.
54 FileError GetLocallyStoredResourceEntry( 54 FileError GetLocallyStoredResourceEntry(
55 internal::ResourceMetadata* resource_metadata, 55 internal::ResourceMetadata* resource_metadata,
56 internal::FileCache* cache, 56 internal::FileCache* cache,
57 const base::FilePath& file_path, 57 const base::FilePath& file_path,
58 ResourceEntry* entry) { 58 ResourceEntry* entry) {
59 std::string local_id; 59 std::string local_id;
60 FileError error = 60 FileError error = resource_metadata->GetIdByPath(file_path, &local_id);
61 resource_metadata->GetIdByPath(file_path, &local_id);
62 if (error != FILE_ERROR_OK) 61 if (error != FILE_ERROR_OK)
63 return error; 62 return error;
64 63
65 error = resource_metadata->GetResourceEntryById(local_id, entry); 64 error = resource_metadata->GetResourceEntryById(local_id, entry);
66 if (error != FILE_ERROR_OK) 65 if (error != FILE_ERROR_OK)
67 return error; 66 return error;
68 67
69 // For entries that will never be cached, use the original resource entry 68 // For entries that will never be cached, use the original resource entry
70 // as is. 69 // as is.
71 if (!entry->has_file_specific_info() || 70 if (!entry->has_file_specific_info() ||
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 } 639 }
641 640
642 void FileSystem::GetResourceEntryByPathAfterGetEntry( 641 void FileSystem::GetResourceEntryByPathAfterGetEntry(
643 const base::FilePath& file_path, 642 const base::FilePath& file_path,
644 const GetResourceEntryCallback& callback, 643 const GetResourceEntryCallback& callback,
645 scoped_ptr<ResourceEntry> entry, 644 scoped_ptr<ResourceEntry> entry,
646 FileError error) { 645 FileError error) {
647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
648 DCHECK(!callback.is_null()); 647 DCHECK(!callback.is_null());
649 648
650 if (error == FILE_ERROR_OK) { 649 if (error == FILE_ERROR_NOT_FOUND) {
651 callback.Run(error, entry.Pass()); 650 // If the information about the path is not in the local ResourceMetadata,
652 return; 651 // try fetching information of the directory and retry.
652 //
653 // Note: this forms mutual recursion between GetResourceEntryByPath and
654 // LoadDirectoryIfNeeded, because directory loading requires the existence
655 // of directory entry itself. The recursion terminates because we always go
656 // up the hierarchy by .DirName() bounded under the Drive root path.
657 if (util::GetDriveGrandRootPath().IsParent(file_path)) {
658 LoadDirectoryIfNeeded(
659 file_path.DirName(),
660 base::Bind(&FileSystem::GetResourceEntryByPathAfterLoad,
661 weak_ptr_factory_.GetWeakPtr(),
662 file_path,
663 callback));
664 return;
665 }
653 } 666 }
654 667
655 // If the information about the path is not in the local ResourceMetadata, 668 callback.Run(error, entry.Pass());
656 // try fetching information of the directory and retry.
657 LoadDirectoryIfNeeded(
658 file_path.DirName(),
659 base::Bind(&FileSystem::GetResourceEntryByPathAfterLoad,
660 weak_ptr_factory_.GetWeakPtr(),
661 file_path,
662 callback));
663 } 669 }
664 670
665 void FileSystem::GetResourceEntryByPathAfterLoad( 671 void FileSystem::GetResourceEntryByPathAfterLoad(
666 const base::FilePath& file_path, 672 const base::FilePath& file_path,
667 const GetResourceEntryCallback& callback, 673 const GetResourceEntryCallback& callback,
668 FileError error) { 674 FileError error) {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
670 DCHECK(!callback.is_null()); 676 DCHECK(!callback.is_null());
671 677
672 if (error != FILE_ERROR_OK) { 678 if (error != FILE_ERROR_OK) {
(...skipping 28 matching lines...) Expand all
701 weak_ptr_factory_.GetWeakPtr(), 707 weak_ptr_factory_.GetWeakPtr(),
702 directory_path, 708 directory_path,
703 callback)); 709 callback));
704 } 710 }
705 711
706 void FileSystem::LoadDirectoryIfNeeded(const base::FilePath& directory_path, 712 void FileSystem::LoadDirectoryIfNeeded(const base::FilePath& directory_path,
707 const FileOperationCallback& callback) { 713 const FileOperationCallback& callback) {
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
709 DCHECK(!callback.is_null()); 715 DCHECK(!callback.is_null());
710 716
711 // ResourceMetadata may know about the entry even if the resource 717 GetResourceEntryByPath(
712 // metadata is not yet fully loaded.
713 resource_metadata_->GetResourceEntryByPathOnUIThread(
714 directory_path, 718 directory_path,
715 base::Bind(&FileSystem::LoadDirectoryIfNeededAfterGetEntry, 719 base::Bind(&FileSystem::LoadDirectoryIfNeededAfterGetEntry,
716 weak_ptr_factory_.GetWeakPtr(), 720 weak_ptr_factory_.GetWeakPtr(),
717 directory_path, 721 directory_path,
718 callback)); 722 callback));
719 } 723 }
720 724
721 void FileSystem::LoadDirectoryIfNeededAfterGetEntry( 725 void FileSystem::LoadDirectoryIfNeededAfterGetEntry(
722 const base::FilePath& directory_path, 726 const base::FilePath& directory_path,
723 const FileOperationCallback& callback, 727 const FileOperationCallback& callback,
724 FileError error, 728 FileError error,
725 scoped_ptr<ResourceEntry> entry) { 729 scoped_ptr<ResourceEntry> entry) {
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
727 DCHECK(!callback.is_null()); 731 DCHECK(!callback.is_null());
728 732
729 if (error != FILE_ERROR_OK || 733 if (error != FILE_ERROR_OK) {
730 entry->resource_id() == util::kDriveOtherDirSpecialResourceId) { 734 callback.Run(error);
731 // If we don't know about the directory, or it is the "drive/other"
732 // directory that has to gather all orphan entries, start loading full
733 // resource list.
734 change_list_loader_->LoadIfNeeded(internal::DirectoryFetchInfo(), callback);
735 return; 735 return;
736 } 736 }
737 737
738 if (!entry->file_info().is_directory()) { 738 if (!entry->file_info().is_directory()) {
739 callback.Run(FILE_ERROR_NOT_A_DIRECTORY); 739 callback.Run(FILE_ERROR_NOT_A_DIRECTORY);
740 return; 740 return;
741 } 741 }
742 742
743 // Pass the directory fetch info so we can fetch the contents of the 743 // Pass the directory fetch info so we can fetch the contents of the
744 // directory before loading change lists. 744 // directory before loading change lists.
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 if (util::IsSpecialResourceId(id)) 1089 if (util::IsSpecialResourceId(id))
1090 return; 1090 return;
1091 1091
1092 util::Log(logging::LOG_INFO, 1092 util::Log(logging::LOG_INFO,
1093 "Thumbnail refresh for %s", directory_path.AsUTF8Unsafe().c_str()); 1093 "Thumbnail refresh for %s", directory_path.AsUTF8Unsafe().c_str());
1094 change_list_loader_->LoadDirectoryFromServer( 1094 change_list_loader_->LoadDirectoryFromServer(
1095 id, base::Bind(&util::EmptyFileOperationCallback)); 1095 id, base::Bind(&util::EmptyFileOperationCallback));
1096 } 1096 }
1097 1097
1098 } // namespace drive 1098 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader_unittest.cc ('k') | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698