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

Unified Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10271026: gdata: Add GDataFileSystem::ReadDirectoryByPathAsync() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_file_system.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc
index c573b6ee9c4fb4ca5578186d592b5cd1e073effd..b333cc4e705c41f953388a332606ae9a4f55689e 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -820,6 +820,17 @@ void RelayGetFileInfoCallback(
base::Bind(callback, error, base::Passed(&file_proto)));
}
+// Ditto for ReadDirectoryCallback.
+void RelayReadDirectoryCallback(
+ scoped_refptr<base::MessageLoopProxy> relay_proxy,
+ const ReadDirectoryCallback& callback,
+ base::PlatformFileError error,
+ scoped_ptr<GDataDirectoryProto> directory_proto) {
+ relay_proxy->PostTask(
+ FROM_HERE,
+ base::Bind(callback, error, base::Passed(&directory_proto)));
+}
+
} // namespace
// GDataFileProperties struct implementation.
@@ -2124,7 +2135,7 @@ void GDataFileSystem::GetFileInfoByPathAsync(
const bool posted = BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&GDataFileSystem::GetFileInfoByPathAsync,
+ base::Bind(&GDataFileSystem::GetFileInfoByPathAsyncOnUIThread,
ui_weak_ptr_,
file_path,
base::Bind(&RelayGetFileInfoCallback,
@@ -2144,15 +2155,15 @@ void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread(
FindEntryByPathAsyncOnUIThread(
file_path,
- base::Bind(&GDataFileSystem::OnEntryFound,
+ base::Bind(&GDataFileSystem::OnGetFileInfo,
ui_weak_ptr_,
callback));
}
-void GDataFileSystem::OnEntryFound(const GetFileInfoCallback& callback,
- base::PlatformFileError error,
- const FilePath& directory_path,
- GDataEntry* entry) {
+void GDataFileSystem::OnGetFileInfo(const GetFileInfoCallback& callback,
+ base::PlatformFileError error,
+ const FilePath& directory_path,
+ GDataEntry* entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != base::PLATFORM_FILE_OK) {
@@ -2176,6 +2187,66 @@ void GDataFileSystem::OnEntryFound(const GetFileInfoCallback& callback,
callback.Run(base::PLATFORM_FILE_OK, file_proto.Pass());
}
+void GDataFileSystem::ReadDirectoryByPathAsync(
+ const FilePath& file_path,
+ const ReadDirectoryCallback& callback) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ const bool posted = BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread,
+ ui_weak_ptr_,
+ file_path,
+ base::Bind(&RelayReadDirectoryCallback,
+ base::MessageLoopProxy::current(),
+ callback)));
+ DCHECK(posted);
+ return;
+ }
+
+ ReadDirectoryByPathAsyncOnUIThread(file_path, callback);
+}
+
+void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread(
+ const FilePath& file_path,
+ const ReadDirectoryCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ FindEntryByPathAsyncOnUIThread(
+ file_path,
+ base::Bind(&GDataFileSystem::OnReadDirectory,
+ ui_weak_ptr_,
+ callback));
+}
+
+void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback,
+ base::PlatformFileError error,
+ const FilePath& directory_path,
+ GDataEntry* entry) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (error != base::PLATFORM_FILE_OK) {
+ if (!callback.is_null())
+ callback.Run(error, scoped_ptr<GDataDirectoryProto>());
+ return;
+ }
+
+ GDataDirectory* directory = entry->AsGDataDirectory();
+ if (!directory) {
+ if (!callback.is_null())
+ callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ scoped_ptr<GDataDirectoryProto>());
+ return;
+ }
+
+ scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto);
+ directory->ToProto(directory_proto.get());
+
+ if (!callback.is_null())
+ callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass());
+}
+
bool GDataFileSystem::GetFileInfoByPath(
const FilePath& file_path, GDataFileProperties* properties) {
DCHECK(properties);
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698