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

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

Issue 9583031: gdata:: Add GDataFileSystem::GetFile(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 10 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 19c54466ccc97df0c37610b86b4c224cb7b903f9..2454fae1bf68e7b536873f5e0146358dea34fc94 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -402,13 +402,14 @@ void GDataFileSystem::StartDirectoryRefresh(
void GDataFileSystem::Remove(const FilePath& file_path,
bool is_recursive,
const FileOperationCallback& callback) {
- GURL document_url = GetDocumentUrlFromPath(file_path);
- if (document_url.is_empty()) {
+ GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path);
+ if (!file_info) {
if (!callback.is_null()) {
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND));
}
+ return;
}
BrowserThread::PostTask(
@@ -416,13 +417,13 @@ void GDataFileSystem::Remove(const FilePath& file_path,
base::Bind(
&DocumentsService::DeleteDocument,
documents_service_bound_to_ui_thread_,
- document_url,
+ file_info->self_url(),
base::Bind(&GDataFileSystem::OnRemovedDocument,
file_system_bound_to_ui_thread_,
callback,
file_path,
// MessageLoopProxy is used to run |callback| on the
- // thread where Remove() was called.
+ // thread where this function was called.
base::MessageLoopProxy::current())));
}
@@ -501,6 +502,37 @@ void GDataFileSystem::CreateDirectoryInternal(
reply_proxy))));
}
+void GDataFileSystem::GetFile(const FilePath& file_path,
+ const GetFileCallback& callback) {
+ GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path);
+ if (!file_info) {
+ if (!callback.is_null()) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ FilePath()));
+ }
+ return;
+ }
+
+ // TODO(satorux): We should get a file from the cache if it's present, but
+ // the caching layer is not implemented yet. For now, always download from
+ // the cloud.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &DocumentsService::DownloadFile,
+ documents_service_bound_to_ui_thread_,
+ file_info->content_url(),
+ base::Bind(&GDataFileSystem::OnFileDownloaded,
+ file_system_bound_to_ui_thread_,
+ callback,
+ // MessageLoopProxy is used to run |callback| on the
+ // thread where this function was called.
+ base::MessageLoopProxy::current())));
+}
+
void GDataFileSystem::UnsafeFindFileByPath(
const FilePath& file_path, scoped_refptr<FindFileDelegate> delegate) {
lock_.AssertAcquired();
@@ -552,16 +584,17 @@ void GDataFileSystem::UnsafeFindFileByPath(
delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND);
}
-GURL GDataFileSystem::GetDocumentUrlFromPath(const FilePath& file_path) {
+GDataFileBase* GDataFileSystem::GetGDataFileInfoFromPath(
+ const FilePath& file_path) {
base::AutoLock lock(lock_);
// Find directory element within the cached file system snapshot.
scoped_refptr<ReadOnlyFindFileDelegate> find_delegate(
new ReadOnlyFindFileDelegate());
UnsafeFindFileByPath(file_path, find_delegate);
if (!find_delegate->file())
- return GURL();
+ return NULL;
- return find_delegate->file()->self_url();
+ return find_delegate->file();
}
void GDataFileSystem::OnCreateDirectoryCompleted(
@@ -665,6 +698,22 @@ void GDataFileSystem::OnRemovedDocument(
}
}
+void GDataFileSystem::OnFileDownloaded(
+ const GetFileCallback& callback,
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
+ GDataErrorCode status,
+ const GURL& content_url,
+ const FilePath& file_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ base::PlatformFileError error = GDataToPlatformError(status);
+
+ if (!callback.is_null()) {
+ message_loop_proxy->PostTask(FROM_HERE,
+ base::Bind(callback, error, file_path));
+ }
+}
+
base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem(
const FilePath& file_path) {
// We need to lock here as well (despite FindFileByPath lock) since directory
« 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