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

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

Issue 10831375: gdata: Remove GDataDirectoryService::FindEntryByPathAndRunSync(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 4 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 entry_proto.Pass(), 681 entry_proto.Pass(),
682 base::Bind(&RunGetEntryInfoWithFilePathCallback, 682 base::Bind(&RunGetEntryInfoWithFilePathCallback,
683 callback, entry->GetFilePath())); 683 callback, entry->GetFilePath()));
684 } else { 684 } else {
685 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, 685 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
686 FilePath(), 686 FilePath(),
687 scoped_ptr<GDataEntryProto>()); 687 scoped_ptr<GDataEntryProto>());
688 } 688 }
689 } 689 }
690 690
691 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( 691 void GDataFileSystem::LoadFeedIfNeeded(const FileOperationCallback& callback) {
692 const FilePath& search_file_path,
693 const FindEntryCallback& callback) {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
695 DCHECK(!callback.is_null()); 693 DCHECK(!callback.is_null());
696 694
697 if (directory_service_->origin() == INITIALIZING) { 695 if (directory_service_->origin() == INITIALIZING) {
698 // If root feed is not initialized but the initialization process has 696 // If root feed is not initialized but the initialization process has
699 // already started, add an observer to execute the remaining task after 697 // already started, add an observer to execute the remaining task after
700 // the end of the initialization. 698 // the end of the initialization.
701 AddObserver(new InitialLoadObserver( 699 AddObserver(new InitialLoadObserver(this,
702 this, 700 base::Bind(callback, GDATA_FILE_OK)));
703 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
704 ui_weak_ptr_,
705 search_file_path,
706 callback)));
707 return; 701 return;
708 } else if (directory_service_->origin() == UNINITIALIZED) { 702 } else if (directory_service_->origin() == UNINITIALIZED) {
709 // Load root feed from this disk cache. Upon completion, kick off server 703 // Load root feed from this disk cache. Upon completion, kick off server
710 // fetching. 704 // fetching.
711 directory_service_->set_origin(INITIALIZING); 705 directory_service_->set_origin(INITIALIZING);
712 feed_loader_->LoadFromCache( 706 feed_loader_->LoadFromCache(
713 true, // should_load_from_server 707 true, // should_load_from_server
714 // This is the initial load, hence we'll notify when it's done. 708 base::Bind(&GDataFileSystem::NotifyInitialLoadFinishedAndRun,
715 base::Bind(&GDataFileSystem::FindAndNotifyInitialLoadFinished,
716 ui_weak_ptr_, 709 ui_weak_ptr_,
717 search_file_path,
718 callback)); 710 callback));
719 return; 711 return;
720 } 712 }
721 713
722 // Post a task to the same thread, rather than calling it here, as 714 // The feed has already been loaded, so we have nothing to do, but post a
723 // FindEntryByPath() is asynchronous. 715 // task to the same thread, rather than calling it here, as
716 // LoadFeedIfNeeded() is asynchronous.
724 base::MessageLoopProxy::current()->PostTask( 717 base::MessageLoopProxy::current()->PostTask(
725 FROM_HERE, 718 FROM_HERE,
726 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 719 base::Bind(callback, GDATA_FILE_OK));
727 ui_weak_ptr_,
728 search_file_path,
729 callback));
730 }
731
732 void GDataFileSystem::FindEntryByPathSyncOnUIThread(
733 const FilePath& search_file_path,
734 const FindEntryCallback& callback) {
735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
736 DCHECK(!callback.is_null());
737
738 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback);
739 } 720 }
740 721
741 void GDataFileSystem::TransferFileFromRemoteToLocal( 722 void GDataFileSystem::TransferFileFromRemoteToLocal(
742 const FilePath& remote_src_file_path, 723 const FilePath& remote_src_file_path,
743 const FilePath& local_dest_file_path, 724 const FilePath& local_dest_file_path,
744 const FileOperationCallback& callback) { 725 const FileOperationCallback& callback) {
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
746 DCHECK(!callback.is_null()); 727 DCHECK(!callback.is_null());
747 728
748 GetFileByPath(remote_src_file_path, 729 GetFileByPath(remote_src_file_path,
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 params.get_content_callback); 1872 params.get_content_callback);
1892 } 1873 }
1893 1874
1894 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path, 1875 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path,
1895 const GetEntryInfoCallback& callback) { 1876 const GetEntryInfoCallback& callback) {
1896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1897 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1878 BrowserThread::CurrentlyOn(BrowserThread::IO));
1898 DCHECK(!callback.is_null()); 1879 DCHECK(!callback.is_null());
1899 1880
1900 RunTaskOnUIThread( 1881 RunTaskOnUIThread(
1901 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread, 1882 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThread,
1902 ui_weak_ptr_, 1883 ui_weak_ptr_,
1903 file_path, 1884 file_path,
1904 CreateRelayCallback(callback))); 1885 CreateRelayCallback(callback)));
1905 } 1886 }
1906 1887
1907 void GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread( 1888 void GDataFileSystem::GetEntryInfoByPathOnUIThread(
1908 const FilePath& file_path, 1889 const FilePath& file_path,
1909 const GetEntryInfoCallback& callback) { 1890 const GetEntryInfoCallback& callback) {
1910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1911 DCHECK(!callback.is_null()); 1892 DCHECK(!callback.is_null());
1912 1893
1913 FindEntryByPathAsyncOnUIThread( 1894 LoadFeedIfNeeded(
1914 file_path, 1895 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad,
1915 base::Bind(&GDataFileSystem::OnGetEntryInfo,
1916 ui_weak_ptr_, 1896 ui_weak_ptr_,
1897 file_path,
1917 callback)); 1898 callback));
1918 } 1899 }
1919 1900
1920 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, 1901 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad(
1921 GDataFileError error, 1902 const FilePath& file_path,
1922 GDataEntry* entry) { 1903 const GetEntryInfoCallback& callback,
1904 GDataFileError error) {
1923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1924 DCHECK(!callback.is_null()); 1906 DCHECK(!callback.is_null());
1925 1907
1926 if (error != GDATA_FILE_OK) { 1908 if (error != GDATA_FILE_OK) {
1927 callback.Run(error, scoped_ptr<GDataEntryProto>()); 1909 callback.Run(error, scoped_ptr<GDataEntryProto>());
1928 return; 1910 return;
1929 } 1911 }
1930 DCHECK(entry);
1931 1912
1932 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 1913 directory_service_->GetEntryInfoByPath(
1933 entry->ToProtoFull(entry_proto.get()); 1914 file_path,
1915 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry,
1916 ui_weak_ptr_,
1917 callback));
1918 }
1919
1920 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry(
1921 const GetEntryInfoCallback& callback,
1922 GDataFileError error,
1923 scoped_ptr<GDataEntryProto> entry_proto) {
1924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1925 DCHECK(!callback.is_null());
1926
1927 if (error != GDATA_FILE_OK) {
1928 callback.Run(error, scoped_ptr<GDataEntryProto>());
1929 return;
1930 }
1931 DCHECK(entry_proto.get());
1934 1932
1935 CheckLocalModificationAndRun(entry_proto.Pass(), callback); 1933 CheckLocalModificationAndRun(entry_proto.Pass(), callback);
1936 } 1934 }
1937 1935
1938 void GDataFileSystem::ReadDirectoryByPath( 1936 void GDataFileSystem::ReadDirectoryByPath(
1939 const FilePath& file_path, 1937 const FilePath& file_path,
1940 const ReadDirectoryWithSettingCallback& callback) { 1938 const ReadDirectoryWithSettingCallback& callback) {
1941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1942 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1940 BrowserThread::CurrentlyOn(BrowserThread::IO));
1943 DCHECK(!callback.is_null()); 1941 DCHECK(!callback.is_null());
1944 1942
1945 RunTaskOnUIThread( 1943 RunTaskOnUIThread(
1946 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, 1944 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThread,
1947 ui_weak_ptr_, 1945 ui_weak_ptr_,
1948 file_path, 1946 file_path,
1949 CreateRelayCallback(callback))); 1947 CreateRelayCallback(callback)));
1950 } 1948 }
1951 1949
1952 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread( 1950 void GDataFileSystem::ReadDirectoryByPathOnUIThread(
1953 const FilePath& file_path, 1951 const FilePath& file_path,
1954 const ReadDirectoryWithSettingCallback& callback) { 1952 const ReadDirectoryWithSettingCallback& callback) {
1955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1956 DCHECK(!callback.is_null()); 1954 DCHECK(!callback.is_null());
1957 1955
1958 FindEntryByPathAsyncOnUIThread( 1956 LoadFeedIfNeeded(
1957 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad,
1958 ui_weak_ptr_,
1959 file_path,
1960 callback));
1961 }
1962
1963 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad(
1964 const FilePath& file_path,
1965 const ReadDirectoryWithSettingCallback& callback,
1966 GDataFileError error) {
1967 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1968 DCHECK(!callback.is_null());
1969
1970 if (error != GDATA_FILE_OK) {
1971 callback.Run(error,
1972 hide_hosted_docs_,
1973 scoped_ptr<GDataEntryProtoVector>());
1974 return;
1975 }
1976
1977 directory_service_->ReadDirectoryByPath(
1959 file_path, 1978 file_path,
1960 base::Bind(&GDataFileSystem::OnReadDirectory, 1979 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead,
1961 ui_weak_ptr_, 1980 ui_weak_ptr_,
1962 callback)); 1981 callback));
1963 } 1982 }
1964 1983
1965 void GDataFileSystem::OnReadDirectory( 1984 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead(
1966 const ReadDirectoryWithSettingCallback& callback, 1985 const ReadDirectoryWithSettingCallback& callback,
1967 GDataFileError error, 1986 GDataFileError error,
1968 GDataEntry* entry) { 1987 scoped_ptr<GDataEntryProtoVector> entries) {
1969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1988 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1989 DCHECK(!callback.is_null());
1970 1990
1971 if (error != GDATA_FILE_OK) { 1991 if (error != GDATA_FILE_OK) {
1972 if (!callback.is_null()) 1992 callback.Run(error,
1973 callback.Run(error, 1993 hide_hosted_docs_,
1974 hide_hosted_docs_, 1994 scoped_ptr<GDataEntryProtoVector>());
1975 scoped_ptr<GDataEntryProtoVector>());
1976 return; 1995 return;
1977 } 1996 }
1978 DCHECK(entry); 1997 DCHECK(entries.get()); // This is valid for emptry directories too.
1979 1998
1980 GDataDirectory* directory = entry->AsGDataDirectory(); 1999 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass());
1981 if (!directory) {
1982 if (!callback.is_null())
1983 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
1984 hide_hosted_docs_,
1985 scoped_ptr<GDataEntryProtoVector>());
1986 return;
1987 }
1988
1989 scoped_ptr<GDataEntryProtoVector> entries(directory->ToProtoVector());
1990
1991 if (!callback.is_null())
1992 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass());
1993 } 2000 }
1994 2001
1995 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { 2002 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) {
1996 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2003 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1997 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2004 BrowserThread::CurrentlyOn(BrowserThread::IO));
1998 RunTaskOnUIThread( 2005 RunTaskOnUIThread(
1999 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, 2006 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread,
2000 ui_weak_ptr_, 2007 ui_weak_ptr_,
2001 file_path)); 2008 file_path));
2002 } 2009 }
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 2842
2836 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { 2843 void GDataFileSystem::NotifyFileSystemToBeUnmounted() {
2837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2838 2845
2839 DVLOG(1) << "File System is to be unmounted"; 2846 DVLOG(1) << "File System is to be unmounted";
2840 // Notify the observers that the file system is being unmounted. 2847 // Notify the observers that the file system is being unmounted.
2841 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2848 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2842 OnFileSystemBeingUnmounted()); 2849 OnFileSystemBeingUnmounted());
2843 } 2850 }
2844 2851
2845 void GDataFileSystem::FindAndNotifyInitialLoadFinished( 2852 void GDataFileSystem::NotifyInitialLoadFinishedAndRun(
2846 const FilePath& search_file_path, 2853 const FileOperationCallback& callback,
2847 const FindEntryCallback& callback,
2848 GDataFileError error) { 2854 GDataFileError error) {
2849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2850 DCHECK(!callback.is_null()); 2856 DCHECK(!callback.is_null());
2851 2857
2852 // TODO(satorux): Remove this: crbug.com/141196.
2853 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback);
2854
2855 DVLOG(1) << "RunAndNotifyInitialLoadFinished";
2856
2857 // Notify the observers that root directory has been initialized. 2858 // Notify the observers that root directory has been initialized.
2858 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2859 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2859 OnInitialLoadFinished()); 2860 OnInitialLoadFinished());
2861
2862 callback.Run(error);
2860 } 2863 }
2861 2864
2862 GDataFileError GDataFileSystem::AddNewDirectory( 2865 GDataFileError GDataFileSystem::AddNewDirectory(
2863 const FilePath& directory_path, base::Value* entry_value) { 2866 const FilePath& directory_path, base::Value* entry_value) {
2864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2865 2868
2866 if (!entry_value) 2869 if (!entry_value)
2867 return GDATA_FILE_ERROR_FAILED; 2870 return GDATA_FILE_ERROR_FAILED;
2868 2871
2869 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); 2872 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value));
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
3455 return; 3458 return;
3456 } 3459 }
3457 3460
3458 PlatformFileInfoProto entry_file_info; 3461 PlatformFileInfoProto entry_file_info;
3459 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3462 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3460 *entry_proto->mutable_file_info() = entry_file_info; 3463 *entry_proto->mutable_file_info() = entry_file_info;
3461 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3464 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3462 } 3465 }
3463 3466
3464 } // namespace gdata 3467 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698