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/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 Loading... | |
| 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 // Post a task to the same thread, rather than calling it here, as |
|
achuithb
2012/08/17 19:36:49
Could you please also add a comment here that the
satorux1
2012/08/17 20:35:30
Added a comment.
| |
| 723 // FindEntryByPath() is asynchronous. | 715 // LoadFeedIfNeeded() is asynchronous. |
| 724 base::MessageLoopProxy::current()->PostTask( | 716 base::MessageLoopProxy::current()->PostTask( |
| 725 FROM_HERE, | 717 FROM_HERE, |
| 726 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 718 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 } | 719 } |
| 740 | 720 |
| 741 void GDataFileSystem::TransferFileFromRemoteToLocal( | 721 void GDataFileSystem::TransferFileFromRemoteToLocal( |
| 742 const FilePath& remote_src_file_path, | 722 const FilePath& remote_src_file_path, |
| 743 const FilePath& local_dest_file_path, | 723 const FilePath& local_dest_file_path, |
| 744 const FileOperationCallback& callback) { | 724 const FileOperationCallback& callback) { |
| 745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 746 DCHECK(!callback.is_null()); | 726 DCHECK(!callback.is_null()); |
| 747 | 727 |
| 748 GetFileByPath(remote_src_file_path, | 728 GetFileByPath(remote_src_file_path, |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 params.get_content_callback); | 1871 params.get_content_callback); |
| 1892 } | 1872 } |
| 1893 | 1873 |
| 1894 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path, | 1874 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path, |
| 1895 const GetEntryInfoCallback& callback) { | 1875 const GetEntryInfoCallback& callback) { |
| 1896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1897 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1877 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1898 DCHECK(!callback.is_null()); | 1878 DCHECK(!callback.is_null()); |
| 1899 | 1879 |
| 1900 RunTaskOnUIThread( | 1880 RunTaskOnUIThread( |
| 1901 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread, | 1881 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThread, |
| 1902 ui_weak_ptr_, | 1882 ui_weak_ptr_, |
| 1903 file_path, | 1883 file_path, |
| 1904 CreateRelayCallback(callback))); | 1884 CreateRelayCallback(callback))); |
| 1905 } | 1885 } |
| 1906 | 1886 |
| 1907 void GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread( | 1887 void GDataFileSystem::GetEntryInfoByPathOnUIThread( |
| 1908 const FilePath& file_path, | 1888 const FilePath& file_path, |
| 1909 const GetEntryInfoCallback& callback) { | 1889 const GetEntryInfoCallback& callback) { |
| 1910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1890 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1911 DCHECK(!callback.is_null()); | 1891 DCHECK(!callback.is_null()); |
| 1912 | 1892 |
| 1913 FindEntryByPathAsyncOnUIThread( | 1893 LoadFeedIfNeeded( |
| 1914 file_path, | 1894 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, |
| 1915 base::Bind(&GDataFileSystem::OnGetEntryInfo, | |
| 1916 ui_weak_ptr_, | 1895 ui_weak_ptr_, |
| 1896 file_path, | |
| 1917 callback)); | 1897 callback)); |
| 1918 } | 1898 } |
| 1919 | 1899 |
| 1920 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, | 1900 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad( |
| 1921 GDataFileError error, | 1901 const FilePath& file_path, |
| 1922 GDataEntry* entry) { | 1902 const GetEntryInfoCallback& callback, |
| 1903 GDataFileError error) { | |
| 1923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1924 DCHECK(!callback.is_null()); | 1905 DCHECK(!callback.is_null()); |
| 1925 | 1906 |
| 1926 if (error != GDATA_FILE_OK) { | 1907 if (error != GDATA_FILE_OK) { |
| 1927 callback.Run(error, scoped_ptr<GDataEntryProto>()); | 1908 callback.Run(error, scoped_ptr<GDataEntryProto>()); |
| 1928 return; | 1909 return; |
| 1929 } | 1910 } |
| 1930 DCHECK(entry); | |
| 1931 | 1911 |
| 1932 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); | 1912 directory_service_->GetEntryInfoByPath( |
| 1933 entry->ToProtoFull(entry_proto.get()); | 1913 file_path, |
| 1914 base::Bind(&GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry, | |
| 1915 ui_weak_ptr_, | |
| 1916 callback)); | |
| 1917 } | |
| 1918 | |
| 1919 void GDataFileSystem::GetEntryInfoByPathOnUIThreadAfterGetEntry( | |
| 1920 const GetEntryInfoCallback& callback, | |
| 1921 GDataFileError error, | |
| 1922 scoped_ptr<GDataEntryProto> entry_proto) { | |
| 1923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1924 DCHECK(!callback.is_null()); | |
| 1925 | |
| 1926 if (error != GDATA_FILE_OK) { | |
| 1927 callback.Run(error, scoped_ptr<GDataEntryProto>()); | |
| 1928 return; | |
| 1929 } | |
| 1930 DCHECK(entry_proto.get()); | |
| 1934 | 1931 |
| 1935 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 1932 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
| 1936 } | 1933 } |
| 1937 | 1934 |
| 1938 void GDataFileSystem::ReadDirectoryByPath( | 1935 void GDataFileSystem::ReadDirectoryByPath( |
| 1939 const FilePath& file_path, | 1936 const FilePath& file_path, |
| 1940 const ReadDirectoryWithSettingCallback& callback) { | 1937 const ReadDirectoryWithSettingCallback& callback) { |
| 1941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1942 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1939 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1943 DCHECK(!callback.is_null()); | 1940 DCHECK(!callback.is_null()); |
| 1944 | 1941 |
| 1945 RunTaskOnUIThread( | 1942 RunTaskOnUIThread( |
| 1946 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, | 1943 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThread, |
| 1947 ui_weak_ptr_, | 1944 ui_weak_ptr_, |
| 1948 file_path, | 1945 file_path, |
| 1949 CreateRelayCallback(callback))); | 1946 CreateRelayCallback(callback))); |
| 1950 } | 1947 } |
| 1951 | 1948 |
| 1952 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread( | 1949 void GDataFileSystem::ReadDirectoryByPathOnUIThread( |
| 1953 const FilePath& file_path, | 1950 const FilePath& file_path, |
| 1954 const ReadDirectoryWithSettingCallback& callback) { | 1951 const ReadDirectoryWithSettingCallback& callback) { |
| 1955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1952 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1956 DCHECK(!callback.is_null()); | 1953 DCHECK(!callback.is_null()); |
| 1957 | 1954 |
| 1958 FindEntryByPathAsyncOnUIThread( | 1955 LoadFeedIfNeeded( |
| 1956 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, | |
| 1957 ui_weak_ptr_, | |
| 1958 file_path, | |
| 1959 callback)); | |
| 1960 } | |
| 1961 | |
| 1962 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad( | |
| 1963 const FilePath& file_path, | |
| 1964 const ReadDirectoryWithSettingCallback& callback, | |
| 1965 GDataFileError error) { | |
| 1966 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1967 DCHECK(!callback.is_null()); | |
| 1968 | |
| 1969 if (error != GDATA_FILE_OK) { | |
| 1970 callback.Run(error, | |
| 1971 hide_hosted_docs_, | |
| 1972 scoped_ptr<GDataEntryProtoVector>()); | |
| 1973 return; | |
| 1974 } | |
| 1975 | |
| 1976 directory_service_->ReadDirectoryByPath( | |
| 1959 file_path, | 1977 file_path, |
| 1960 base::Bind(&GDataFileSystem::OnReadDirectory, | 1978 base::Bind(&GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead, |
| 1961 ui_weak_ptr_, | 1979 ui_weak_ptr_, |
| 1962 callback)); | 1980 callback)); |
| 1963 } | 1981 } |
| 1964 | 1982 |
| 1965 void GDataFileSystem::OnReadDirectory( | 1983 void GDataFileSystem::ReadDirectoryByPathOnUIThreadAfterRead( |
| 1966 const ReadDirectoryWithSettingCallback& callback, | 1984 const ReadDirectoryWithSettingCallback& callback, |
| 1967 GDataFileError error, | 1985 GDataFileError error, |
| 1968 GDataEntry* entry) { | 1986 scoped_ptr<GDataEntryProtoVector> entries) { |
| 1969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1988 DCHECK(!callback.is_null()); | |
| 1970 | 1989 |
| 1971 if (error != GDATA_FILE_OK) { | 1990 if (error != GDATA_FILE_OK) { |
| 1972 if (!callback.is_null()) | 1991 callback.Run(error, |
| 1973 callback.Run(error, | 1992 hide_hosted_docs_, |
| 1974 hide_hosted_docs_, | 1993 scoped_ptr<GDataEntryProtoVector>()); |
| 1975 scoped_ptr<GDataEntryProtoVector>()); | |
| 1976 return; | 1994 return; |
| 1977 } | 1995 } |
| 1978 DCHECK(entry); | 1996 DCHECK(entries.get()); |
|
achuithb
2012/08/17 19:36:49
Is this DCHECK valid for empty directories?
satorux1
2012/08/17 20:35:30
Yes. added a comment.
achuithb
2012/08/17 20:52:05
nit: s/emptry/empty
| |
| 1979 | 1997 |
| 1980 GDataDirectory* directory = entry->AsGDataDirectory(); | 1998 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 } | 1999 } |
| 1994 | 2000 |
| 1995 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { | 2001 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { |
| 1996 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1997 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2003 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1998 RunTaskOnUIThread( | 2004 RunTaskOnUIThread( |
| 1999 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, | 2005 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, |
| 2000 ui_weak_ptr_, | 2006 ui_weak_ptr_, |
| 2001 file_path)); | 2007 file_path)); |
| 2002 } | 2008 } |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2835 | 2841 |
| 2836 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { | 2842 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { |
| 2837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2838 | 2844 |
| 2839 DVLOG(1) << "File System is to be unmounted"; | 2845 DVLOG(1) << "File System is to be unmounted"; |
| 2840 // Notify the observers that the file system is being unmounted. | 2846 // Notify the observers that the file system is being unmounted. |
| 2841 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2847 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
| 2842 OnFileSystemBeingUnmounted()); | 2848 OnFileSystemBeingUnmounted()); |
| 2843 } | 2849 } |
| 2844 | 2850 |
| 2845 void GDataFileSystem::FindAndNotifyInitialLoadFinished( | 2851 void GDataFileSystem::NotifyInitialLoadFinishedAndRun( |
| 2846 const FilePath& search_file_path, | 2852 const FileOperationCallback& callback, |
| 2847 const FindEntryCallback& callback, | |
| 2848 GDataFileError error) { | 2853 GDataFileError error) { |
| 2849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2850 DCHECK(!callback.is_null()); | 2855 DCHECK(!callback.is_null()); |
| 2851 | 2856 |
| 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. | 2857 // Notify the observers that root directory has been initialized. |
| 2858 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2858 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
| 2859 OnInitialLoadFinished()); | 2859 OnInitialLoadFinished()); |
| 2860 | |
| 2861 callback.Run(error); | |
| 2860 } | 2862 } |
| 2861 | 2863 |
| 2862 GDataFileError GDataFileSystem::AddNewDirectory( | 2864 GDataFileError GDataFileSystem::AddNewDirectory( |
| 2863 const FilePath& directory_path, base::Value* entry_value) { | 2865 const FilePath& directory_path, base::Value* entry_value) { |
| 2864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2866 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2865 | 2867 |
| 2866 if (!entry_value) | 2868 if (!entry_value) |
| 2867 return GDATA_FILE_ERROR_FAILED; | 2869 return GDATA_FILE_ERROR_FAILED; |
| 2868 | 2870 |
| 2869 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); | 2871 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::CreateFrom(*entry_value)); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3455 return; | 3457 return; |
| 3456 } | 3458 } |
| 3457 | 3459 |
| 3458 PlatformFileInfoProto entry_file_info; | 3460 PlatformFileInfoProto entry_file_info; |
| 3459 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3461 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3460 *entry_proto->mutable_file_info() = entry_file_info; | 3462 *entry_proto->mutable_file_info() = entry_file_info; |
| 3461 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3463 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3462 } | 3464 } |
| 3463 | 3465 |
| 3464 } // namespace gdata | 3466 } // namespace gdata |
| OLD | NEW |