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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10204013: Move FindEntryDelegate and friends to separate file. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: change tense of comments Created 8 years, 8 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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 } 733 }
734 734
735 *mime_type = kMimeTypeJson; 735 *mime_type = kMimeTypeJson;
736 *file_type = HOSTED_DOCUMENT; 736 *file_type = HOSTED_DOCUMENT;
737 if (*error != base::PLATFORM_FILE_OK) 737 if (*error != base::PLATFORM_FILE_OK)
738 temp_file_path->clear(); 738 temp_file_path->clear();
739 } 739 }
740 740
741 } // namespace 741 } // namespace
742 742
743 // FindEntryDelegate class implementation.
744
745 FindEntryDelegate::~FindEntryDelegate() {
746 }
747
748 // FindEntryCallbackRelayDelegate class implementation.
749 // This class is used to relay calls between sync and async versions
750 // of FindFileByPath(Sync|Async) calls.
751 class FindEntryCallbackRelayDelegate : public FindEntryDelegate {
752 public:
753 explicit FindEntryCallbackRelayDelegate(const FindEntryCallback& callback);
754 virtual ~FindEntryCallbackRelayDelegate();
755
756 private:
757 // FindEntryDelegate overrides.
758 virtual void OnDone(base::PlatformFileError error,
759 const FilePath& directory_path,
760 GDataEntry* entry) OVERRIDE;
761
762 const FindEntryCallback callback_;
763 };
764
765 FindEntryCallbackRelayDelegate::FindEntryCallbackRelayDelegate(
766 const FindEntryCallback& callback) : callback_(callback) {
767 }
768
769 FindEntryCallbackRelayDelegate::~FindEntryCallbackRelayDelegate() {
770 }
771
772 void FindEntryCallbackRelayDelegate::OnDone(base::PlatformFileError error,
773 const FilePath& directory_path,
774 GDataEntry* entry) {
775 if (!callback_.is_null()) {
776 callback_.Run(error, directory_path, entry);
777 }
778 }
779
780 // ReadOnlyFindEntryDelegate class implementation.
781
782 ReadOnlyFindEntryDelegate::ReadOnlyFindEntryDelegate() : entry_(NULL) {
783 }
784
785 void ReadOnlyFindEntryDelegate::OnDone(base::PlatformFileError error,
786 const FilePath& directory_path,
787 GDataEntry* entry) {
788 DCHECK(!entry_);
789 if (error == base::PLATFORM_FILE_OK)
790 entry_ = entry;
791 else
792 entry_ = NULL;
793 }
794
795 // GDataFileProperties struct implementation. 743 // GDataFileProperties struct implementation.
796 744
797 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) { 745 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) {
798 } 746 }
799 747
800 GDataFileProperties::~GDataFileProperties() { 748 GDataFileProperties::~GDataFileProperties() {
801 } 749 }
802 750
803 // GDataFileSystem::GetDocumentsParams struct implementation. 751 // GDataFileSystem::GetDocumentsParams struct implementation.
804 752
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 // TokenFetcher, used in DocumentsService, must be run on UI thread. 937 // TokenFetcher, used in DocumentsService, must be run on UI thread.
990 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
991 939
992 documents_service_->Authenticate(callback); 940 documents_service_->Authenticate(callback);
993 } 941 }
994 942
995 void GDataFileSystem::FindEntryByPathSync( 943 void GDataFileSystem::FindEntryByPathSync(
996 const FilePath& search_file_path, 944 const FilePath& search_file_path,
997 FindEntryDelegate* delegate) { 945 FindEntryDelegate* delegate) {
998 base::AutoLock lock(lock_); 946 base::AutoLock lock(lock_);
999 UnsafeFindEntryByPath(search_file_path, delegate); 947 root_->FindEntryByPath(search_file_path, delegate);
1000 } 948 }
1001 949
1002 void GDataFileSystem::FindEntryByResourceIdSync( 950 void GDataFileSystem::FindEntryByResourceIdSync(
1003 const std::string& resource_id, 951 const std::string& resource_id,
1004 FindEntryDelegate* delegate) { 952 FindEntryDelegate* delegate) {
1005 base::AutoLock lock(lock_); // To access the cache map. 953 base::AutoLock lock(lock_); // To access the cache map.
1006 954
1007 GDataFile* file = NULL; 955 GDataFile* file = NULL;
1008 GDataEntry* entry = root_->GetEntryByResourceId(resource_id); 956 GDataEntry* entry = root_->GetEntryByResourceId(resource_id);
1009 if (entry) 957 if (entry)
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 } 1864 }
1917 1865
1918 void GDataFileSystem::ResumeUpload( 1866 void GDataFileSystem::ResumeUpload(
1919 const ResumeUploadParams& params, 1867 const ResumeUploadParams& params,
1920 const ResumeFileUploadCallback& callback) { 1868 const ResumeFileUploadCallback& callback) {
1921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1922 1870
1923 documents_service_->ResumeUpload(params, callback); 1871 documents_service_->ResumeUpload(params, callback);
1924 } 1872 }
1925 1873
1926 void GDataFileSystem::UnsafeFindEntryByPath(
1927 const FilePath& file_path,
1928 FindEntryDelegate* delegate) {
1929 DCHECK(delegate);
1930 lock_.AssertAcquired();
1931
1932 std::vector<FilePath::StringType> components;
1933 file_path.GetComponents(&components);
1934
1935 GDataDirectory* current_dir = root_.get();
1936 FilePath directory_path;
1937 for (size_t i = 0; i < components.size() && current_dir; i++) {
1938 directory_path = directory_path.Append(current_dir->file_name());
1939
1940 // Last element must match, if not last then it must be a directory.
1941 if (i == components.size() - 1) {
1942 if (current_dir->file_name() == components[i])
1943 delegate->OnDone(base::PLATFORM_FILE_OK, directory_path, current_dir);
1944 else
1945 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1946
1947 return;
1948 }
1949
1950 // Not the last part of the path, search for the next segment.
1951 GDataFileCollection::const_iterator file_iter =
1952 current_dir->children().find(components[i + 1]);
1953 if (file_iter == current_dir->children().end()) {
1954 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1955 return;
1956 }
1957
1958 // Found file, must be the last segment.
1959 if (file_iter->second->file_info().is_directory) {
1960 // Found directory, continue traversal.
1961 current_dir = file_iter->second->AsGDataDirectory();
1962 } else {
1963 if ((i + 1) == (components.size() - 1)) {
1964 delegate->OnDone(base::PLATFORM_FILE_OK,
1965 directory_path,
1966 file_iter->second);
1967 } else {
1968 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1969 }
1970
1971 return;
1972 }
1973 }
1974 delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL);
1975 }
1976
1977 bool GDataFileSystem::GetFileInfoByPath( 1874 bool GDataFileSystem::GetFileInfoByPath(
1978 const FilePath& file_path, GDataFileProperties* properties) { 1875 const FilePath& file_path, GDataFileProperties* properties) {
1979 DCHECK(properties); 1876 DCHECK(properties);
1980 base::AutoLock lock(lock_); 1877 base::AutoLock lock(lock_);
1981 GDataEntry* entry = GetGDataEntryByPath(file_path); 1878 GDataEntry* entry = GetGDataEntryByPath(file_path);
1982 if (!entry) 1879 if (!entry)
1983 return false; 1880 return false;
1984 1881
1985 properties->file_info = entry->file_info(); 1882 properties->file_info = entry->file_info();
1986 properties->resource_id = entry->resource_id(); 1883 properties->resource_id = entry->resource_id();
(...skipping 23 matching lines...) Expand all
2010 NOTREACHED() << "Called on an unexpected thread: " 1907 NOTREACHED() << "Called on an unexpected thread: "
2011 << base::PlatformThread::CurrentId(); 1908 << base::PlatformThread::CurrentId();
2012 return ui_weak_ptr_factory_->GetWeakPtr(); 1909 return ui_weak_ptr_factory_->GetWeakPtr();
2013 } 1910 }
2014 1911
2015 GDataEntry* GDataFileSystem::GetGDataEntryByPath( 1912 GDataEntry* GDataFileSystem::GetGDataEntryByPath(
2016 const FilePath& file_path) { 1913 const FilePath& file_path) {
2017 lock_.AssertAcquired(); 1914 lock_.AssertAcquired();
2018 // Find directory element within the cached file system snapshot. 1915 // Find directory element within the cached file system snapshot.
2019 ReadOnlyFindEntryDelegate find_delegate; 1916 ReadOnlyFindEntryDelegate find_delegate;
2020 UnsafeFindEntryByPath(file_path, &find_delegate); 1917 root_->FindEntryByPath(file_path, &find_delegate);
2021 return find_delegate.entry(); 1918 return find_delegate.entry();
2022 } 1919 }
2023 1920
2024 void GDataFileSystem::GetCacheState(const std::string& resource_id, 1921 void GDataFileSystem::GetCacheState(const std::string& resource_id,
2025 const std::string& md5, 1922 const std::string& md5,
2026 const GetCacheStateCallback& callback) { 1923 const GetCacheStateCallback& callback) {
2027 // This method originates from GDataFile::GetCacheState, which already locks, 1924 // This method originates from GDataFile::GetCacheState, which already locks,
2028 // so we shouldn't lock here. 1925 // so we shouldn't lock here.
2029 UnsafeInitializeCacheIfNecessary(); 1926 UnsafeInitializeCacheIfNecessary();
2030 1927
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 RemoveFromCache(resource_id, CacheOperationCallback()); 2628 RemoveFromCache(resource_id, CacheOperationCallback());
2732 2629
2733 return base::PLATFORM_FILE_OK; 2630 return base::PLATFORM_FILE_OK;
2734 } 2631 }
2735 2632
2736 base::PlatformFileError GDataFileSystem::UpdateFromFeed( 2633 base::PlatformFileError GDataFileSystem::UpdateFromFeed(
2737 const std::vector<DocumentFeed*>& feed_list, 2634 const std::vector<DocumentFeed*>& feed_list,
2738 ContentOrigin origin, 2635 ContentOrigin origin,
2739 int start_changestamp, 2636 int start_changestamp,
2740 int root_feed_changestamp) { 2637 int root_feed_changestamp) {
2741 DVLOG(1) << "Updating directory with a feed"; 2638 DVLOG(1) << "Updating directory with a feed";
2742 2639
2743 bool is_delta_feed = start_changestamp != 0; 2640 bool is_delta_feed = start_changestamp != 0;
2744 // We need to lock here as well (despite FindEntryByPath lock) since directory 2641 // We need to lock here as well (despite FindEntryByPath lock) since directory
2745 // instance below is a 'live' object. 2642 // instance below is a 'live' object.
2746 base::AutoLock lock(lock_); 2643 base::AutoLock lock(lock_);
2747 bool should_notify_initial_load = root_->origin() == INITIALIZING; 2644 bool should_notify_initial_load = root_->origin() == INITIALIZING;
2748 2645
2749 root_->set_origin(origin); 2646 root_->set_origin(origin);
2750 root_->set_refresh_time(base::Time::Now()); 2647 root_->set_refresh_time(base::Time::Now());
2751 2648
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 const DocumentFeed* feed = feed_list[i]; 2818 const DocumentFeed* feed = feed_list[i];
2922 2819
2923 // Get upload url from the root feed. Links for all other collections will 2820 // Get upload url from the root feed. Links for all other collections will
2924 // be handled in GDatadirectory::FromDocumentEntry(); 2821 // be handled in GDatadirectory::FromDocumentEntry();
2925 if (i == 0) { 2822 if (i == 0) {
2926 const Link* root_feed_upload_link = 2823 const Link* root_feed_upload_link =
2927 feed->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); 2824 feed->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA);
2928 if (root_feed_upload_link) 2825 if (root_feed_upload_link)
2929 root_->set_upload_url(root_feed_upload_link->href()); 2826 root_->set_upload_url(root_feed_upload_link->href());
2930 *feed_changestamp = feed->largest_changestamp(); 2827 *feed_changestamp = feed->largest_changestamp();
2931 DCHECK(*feed_changestamp >= 0); 2828 DCHECK_GE(*feed_changestamp, 0);
2932 } 2829 }
2933 2830
2934 for (ScopedVector<DocumentEntry>::const_iterator iter = 2831 for (ScopedVector<DocumentEntry>::const_iterator iter =
2935 feed->entries().begin(); 2832 feed->entries().begin();
2936 iter != feed->entries().end(); ++iter) { 2833 iter != feed->entries().end(); ++iter) {
2937 DocumentEntry* doc = *iter; 2834 DocumentEntry* doc = *iter;
2938 GDataEntry* entry = GDataEntry::FromDocumentEntry(NULL, doc, 2835 GDataEntry* entry = GDataEntry::FromDocumentEntry(NULL, doc,
2939 root_.get()); 2836 root_.get());
2940 // Some document entries don't map into files (i.e. sites). 2837 // Some document entries don't map into files (i.e. sites).
2941 if (!entry) 2838 if (!entry)
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 pref_registrar_->Init(profile_->GetPrefs()); 4267 pref_registrar_->Init(profile_->GetPrefs());
4371 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4268 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4372 } 4269 }
4373 4270
4374 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4271 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4375 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4272 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4376 global_free_disk_getter_for_testing = getter; 4273 global_free_disk_getter_for_testing = getter;
4377 } 4274 }
4378 4275
4379 } // namespace gdata 4276 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698