Commit eade2d63 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Remove use of FindEntryByPathAsyncOnUI from CreateFileOnUIThread()

By the time CreateFileOnUIThread() is called, the feed is already fetched
so there is no need to use FindEntryByPathAsyncOnUI() which initiates the
feed loading as needed.

Along the way, make callback parameter of CreateFile() mandatory.

BUG=142420,126634
TEST=editing a photo from Files.app works as before.

Review URL: https://chromiumcodereview.appspot.com/10832276

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151359 0039d316-1c4b-4281-b951-d872f2087c98
parent ddd05a58
...@@ -1462,6 +1462,8 @@ void GDataFileSystem::CreateFile(const FilePath& file_path, ...@@ -1462,6 +1462,8 @@ void GDataFileSystem::CreateFile(const FilePath& file_path,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!callback.is_null());
RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread, RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread,
ui_weak_ptr_, ui_weak_ptr_,
file_path, file_path,
...@@ -1474,9 +1476,10 @@ void GDataFileSystem::CreateFileOnUIThread( ...@@ -1474,9 +1476,10 @@ void GDataFileSystem::CreateFileOnUIThread(
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// First, checks the existence of a file at |file_path|. // First, checks the existence of a file at |file_path|.
FindEntryByPathAsyncOnUIThread( directory_service_->GetEntryInfoByPath(
file_path, file_path,
base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile, base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile,
ui_weak_ptr_, ui_weak_ptr_,
...@@ -1490,32 +1493,31 @@ void GDataFileSystem::OnGetEntryInfoForCreateFile( ...@@ -1490,32 +1493,31 @@ void GDataFileSystem::OnGetEntryInfoForCreateFile(
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError result, GDataFileError result,
GDataEntry* entry) { scoped_ptr<GDataEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// The |file_path| is invalid. It is an error. // The |file_path| is invalid. It is an error.
if (result != GDATA_FILE_ERROR_NOT_FOUND && if (result != GDATA_FILE_ERROR_NOT_FOUND &&
result != GDATA_FILE_OK) { result != GDATA_FILE_OK) {
if (!callback.is_null()) callback.Run(result);
callback.Run(result);
return; return;
} }
// An entry already exists at |file_path|. // An entry already exists at |file_path|.
if (result == GDATA_FILE_OK) { if (result == GDATA_FILE_OK) {
DCHECK(entry_proto.get());
// If an exclusive mode is requested, or the entry is not a regular file, // If an exclusive mode is requested, or the entry is not a regular file,
// it is an error. // it is an error.
if (is_exclusive || if (is_exclusive ||
!entry->AsGDataFile() || entry_proto->file_info().is_directory() ||
entry->AsGDataFile()->is_hosted_document()) { entry_proto->file_specific_info().is_hosted_document()) {
if (!callback.is_null()) callback.Run(GDATA_FILE_ERROR_EXISTS);
callback.Run(GDATA_FILE_ERROR_EXISTS);
return; return;
} }
// Otherwise nothing more to do. Succeeded. // Otherwise nothing more to do. Succeeded.
if (!callback.is_null()) callback.Run(GDATA_FILE_OK);
callback.Run(GDATA_FILE_OK);
return; return;
} }
......
...@@ -223,12 +223,13 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -223,12 +223,13 @@ class GDataFileSystem : public GDataFileSystemInterface,
// with the cases when an entry already existed at the path. If there was no // with the cases when an entry already existed at the path. If there was no
// entry, a new empty file is uploaded, and when it finishes // entry, a new empty file is uploaded, and when it finishes
// DidUploadForCreateBrandNewFile does the final clean up. // DidUploadForCreateBrandNewFile does the final clean up.
// |callback| must not be null.
void OnGetEntryInfoForCreateFile( void OnGetEntryInfoForCreateFile(
const FilePath& file_path, const FilePath& file_path,
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError result, GDataFileError result,
GDataEntry* entry); scoped_ptr<GDataEntryProto> entry_proto);
void DoUploadForCreateBrandNewFile( void DoUploadForCreateBrandNewFile(
const FilePath& remote_path, const FilePath& remote_path,
FilePath* local_path, FilePath* local_path,
......
...@@ -257,6 +257,7 @@ class GDataFileSystemInterface { ...@@ -257,6 +257,7 @@ class GDataFileSystemInterface {
// path, or the parent directory of the path is not present yet. // path, or the parent directory of the path is not present yet.
// //
// Can be called from UI/IO thread. |callback| is run on the calling thread // Can be called from UI/IO thread. |callback| is run on the calling thread
// |callback| must not be null.
virtual void CreateFile(const FilePath& file_path, virtual void CreateFile(const FilePath& file_path,
bool is_exclusive, bool is_exclusive,
const FileOperationCallback& callback) = 0; const FileOperationCallback& callback) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment