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

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

Issue 10543037: gdata: Convert public synchronous functions in GDataFileSystem to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 f320bc932fe25979e35596a4d3e3a262b54960e5..d4bc88fdfadcc8b377510a5a730c6a0bf0370331 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -893,14 +893,6 @@ CallbackType CreateRelayCallback(const CallbackType& callback) {
} // namespace
-// GDataFileProperties struct implementation.
-
-GDataFileProperties::GDataFileProperties() : is_hosted_document(false) {
-}
-
-GDataFileProperties::~GDataFileProperties() {
-}
-
// GDataFileSystem::GetDocumentsParams struct implementation.
GDataFileSystem::GetDocumentsParams::GetDocumentsParams(
@@ -2022,21 +2014,42 @@ void GDataFileSystem::GetFileByPath(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::IO));
RunTaskOnUIThread(
- base::Bind(&GDataFileSystem::GetFileByPathOnUIThread,
+ base::Bind(&GDataFileSystem::GetFileInfoByPathAsync,
satorux1 2012/06/07 22:47:17 Can you keep the function as before? We use this p
hshi1 2012/06/08 00:22:05 Done. Note that I have to create a common shared
ui_weak_ptr_,
file_path,
- CreateRelayCallback(get_file_callback),
- CreateRelayCallback(get_download_data_callback)));
+ base::Bind(
+ &GDataFileSystem::OnGetFileInfoCompleteForGetFileByPath,
+ ui_weak_ptr_,
+ file_path,
+ CreateRelayCallback(get_file_callback),
+ CreateRelayCallback(get_download_data_callback))));
+}
+
+void GDataFileSystem::OnGetFileInfoCompleteForGetFileByPath(
+ const FilePath& file_path,
+ const GetFileCallback& get_file_callback,
+ const GetDownloadDataCallback& get_download_data_callback,
+ base::PlatformFileError error,
+ scoped_ptr<GDataFileProto> file_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ DCHECK(!file_info->gdata_entry().resource_id().empty());
+ GetFileByPathOnUIThread(file_path,
+ get_file_callback,
+ get_download_data_callback,
+ error,
+ file_info.get());
}
void GDataFileSystem::GetFileByPathOnUIThread(
const FilePath& file_path,
const GetFileCallback& get_file_callback,
- const GetDownloadDataCallback& get_download_data_callback) {
+ const GetDownloadDataCallback& get_download_data_callback,
+ base::PlatformFileError error,
+ const GDataFileProto* file_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
satorux1 2012/06/07 22:47:17 DCHECK(file_proto);
hshi1 2012/06/08 00:22:05 Actually file_proto can be NULL. It is checked in
- GDataFileProperties file_properties;
- if (!GetFileInfoByPath(file_path, &file_properties)) {
+ if (error != base::PLATFORM_FILE_OK || !file_proto) {
if (!get_file_callback.is_null()) {
MessageLoop::current()->PostTask(
FROM_HERE,
@@ -2053,7 +2066,7 @@ void GDataFileSystem::GetFileByPathOnUIThread(
// document instead of fetching the document content in one of the exported
// formats. The JSON file contains the edit URL and resource ID of the
// document.
- if (file_properties.is_hosted_document) {
+ if (file_proto->is_hosted_document()) {
base::PlatformFileError* error =
new base::PlatformFileError(base::PLATFORM_FILE_OK);
FilePath* temp_file_path = new FilePath;
@@ -2064,8 +2077,8 @@ void GDataFileSystem::GetFileByPathOnUIThread(
base::Bind(&CreateDocumentJsonFileOnIOThreadPool,
GetCacheDirectoryPath(
GDataCache::CACHE_TYPE_TMP_DOCUMENTS),
- file_properties.alternate_url,
- file_properties.resource_id,
+ GURL(file_proto->alternate_url()),
+ file_proto->gdata_entry().resource_id(),
error,
temp_file_path,
mime_type,
@@ -2080,22 +2093,23 @@ void GDataFileSystem::GetFileByPathOnUIThread(
}
// Returns absolute path of the file if it were cached or to be cached.
- FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id,
- file_properties.file_md5,
- GDataCache::CACHE_TYPE_TMP,
- CACHED_FILE_FROM_SERVER);
+ FilePath local_tmp_path = GetCacheFilePath(
+ file_proto->gdata_entry().resource_id(),
+ file_proto->file_md5(),
+ GDataCache::CACHE_TYPE_TMP,
+ CACHED_FILE_FROM_SERVER);
GetFileFromCacheByResourceIdAndMd5(
- file_properties.resource_id,
- file_properties.file_md5,
+ file_proto->gdata_entry().resource_id(),
+ file_proto->file_md5(),
base::Bind(
&GDataFileSystem::OnGetFileFromCache,
ui_weak_ptr_,
GetFileFromCacheParams(file_path,
local_tmp_path,
- file_properties.content_url,
- file_properties.resource_id,
- file_properties.file_md5,
- file_properties.mime_type,
+ GURL(file_proto->gdata_entry().content_url()),
+ file_proto->gdata_entry().resource_id(),
+ file_proto->file_md5(),
+ file_proto->content_mime_type(),
get_file_callback,
get_download_data_callback)));
}
@@ -2554,28 +2568,6 @@ void GDataFileSystem::OnRequestDirectoryRefresh(
DVLOG(1) << "Directory refreshed: " << directory_path.value();
}
-bool GDataFileSystem::GetFileInfoByPath(
- const FilePath& file_path, GDataFileProperties* properties) {
- DCHECK(properties);
- base::AutoLock lock(lock_);
- GDataEntry* entry = GetGDataEntryByPath(file_path);
- if (!entry)
- return false;
-
- properties->file_info = entry->file_info();
- properties->resource_id = entry->resource_id();
-
- GDataFile* regular_file = entry->AsGDataFile();
- if (regular_file) {
- properties->file_md5 = regular_file->file_md5();
- properties->mime_type = regular_file->content_mime_type();
- properties->content_url = regular_file->content_url();
- properties->alternate_url = regular_file->alternate_url();
- properties->is_hosted_document = regular_file->is_hosted_document();
- }
- return true;
-}
-
GDataEntry* GDataFileSystem::GetGDataEntryByPath(
const FilePath& file_path) {
lock_.AssertAcquired();
@@ -5147,21 +5139,15 @@ void GDataFileSystem::OnGetFileInfoCompleteForOpenFile(
}
DCHECK(!file_info->gdata_entry().resource_id().empty());
-
- // TODO(kinaba): once it is cleaned up (crbug/127048), remove the indirection.
- // Do not call GetFileByPathOnUIThread() directly for avoiding deadlock.
- // The current method is called as a callback from GetFileInfoByPathAsync(),
- // which is under the lock taken.
- base::MessageLoopProxy::current()->PostTask(
- FROM_HERE,
- base::Bind(&GDataFileSystem::GetFileByPathOnUIThread,
+ GetFileByPathOnUIThread(
+ file_path,
+ base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile,
ui_weak_ptr_,
- file_path,
- base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile,
- ui_weak_ptr_,
- callback,
- base::Passed(&file_info)),
- GetDownloadDataCallback()));
+ callback,
+ base::Passed(&file_info)),
+ GetDownloadDataCallback(),
+ error,
+ file_info.get());
}
void GDataFileSystem::OnGetFileCompleteForOpenFile(
@@ -5250,21 +5236,13 @@ void GDataFileSystem::OnGetFileInfoCompleteForCloseFile(
// if the file has not been modified. Come up with a way to detect the
// intactness effectively, or provide a method for user to declare it when
// calling CloseFile().
-
- // TODO(kinaba): once it is cleaned up (crbug/127048), remove the indirection.
- // Do not call CommitDirtyInCache() directly for avoiding deadlock.
- // The current method is called as a callback from GetFileInfoByPathAsync(),
- // which is under the lock taken.
- base::MessageLoopProxy::current()->PostTask(
- FROM_HERE,
+ CommitDirtyInCache(
+ file_info->gdata_entry().resource_id(),
+ file_info->file_md5(),
base::Bind(
- &GDataFileSystem::CommitDirtyInCache,
+ &GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile,
ui_weak_ptr_,
- file_info->gdata_entry().resource_id(),
- file_info->file_md5(),
- base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile,
- ui_weak_ptr_,
- callback)));
+ callback));
}
void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(

Powered by Google App Engine
This is Rietveld 408576698