Commit 6d2999d7 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Rename AddEntryToDirectory() to MoveEntryFromRootDirectory()

The original name was a misnomer. Looking at the code, the function
moves an entry from the root directory to another directory.

Along the way, remove if (!callback.is_null()) and PostTask() from
this and related functions.

BUG=126634, 139446
TEST=copying and moving of files on Drive work as before

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150907 0039d316-1c4b-4281-b951-d872f2087c98
parent 71cdf717
...@@ -1211,7 +1211,7 @@ void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( ...@@ -1211,7 +1211,7 @@ void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair(
// effectively moves the file from the root directory to the parent // effectively moves the file from the root directory to the parent
// directory of |dest_file_path|. // directory of |dest_file_path|.
FileMoveCallback add_file_to_directory_callback = FileMoveCallback add_file_to_directory_callback =
base::Bind(&GDataFileSystem::AddEntryToDirectory, base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory,
ui_weak_ptr_, ui_weak_ptr_,
dest_file_path.DirName(), dest_file_path.DirName(),
callback); callback);
...@@ -1226,12 +1226,14 @@ void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair( ...@@ -1226,12 +1226,14 @@ void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair(
remove_file_from_directory_callback); remove_file_from_directory_callback);
} }
void GDataFileSystem::AddEntryToDirectory( void GDataFileSystem::MoveEntryFromRootDirectory(
const FilePath& dir_path, const FilePath& dir_path,
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
const FilePath& file_path) { const FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DCHECK_EQ(kGDataRootDirectory, file_path.DirName().value());
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path);
...@@ -1247,16 +1249,14 @@ void GDataFileSystem::AddEntryToDirectory( ...@@ -1247,16 +1249,14 @@ void GDataFileSystem::AddEntryToDirectory(
// Returns if there is an error or |dir_path| is the root directory. // Returns if there is an error or |dir_path| is the root directory.
if (error != GDATA_FILE_OK || if (error != GDATA_FILE_OK ||
dir_entry->resource_id() == kGDataRootDirectoryResourceId) { dir_entry->resource_id() == kGDataRootDirectoryResourceId) {
if (!callback.is_null()) callback.Run(error);
MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error));
return; return;
} }
documents_service_->AddResourceToDirectory( documents_service_->AddResourceToDirectory(
dir_entry->content_url(), dir_entry->content_url(),
entry->edit_url(), entry->edit_url(),
base::Bind(&GDataFileSystem::OnAddEntryToDirectoryCompleted, base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted,
ui_weak_ptr_, ui_weak_ptr_,
callback, callback,
file_path, file_path,
...@@ -2489,18 +2489,22 @@ void GDataFileSystem::OnCopyDocumentCompleted( ...@@ -2489,18 +2489,22 @@ void GDataFileSystem::OnCopyDocumentCompleted(
// |entry| was added in the root directory on the server, so we should // |entry| was added in the root directory on the server, so we should
// first add it to |root_| to mirror the state and then move it to the // first add it to |root_| to mirror the state and then move it to the
// destination directory by AddEntryToDirectory(). // destination directory by MoveEntryFromRootDirectory().
directory_service_->root()->AddEntry(entry); directory_service_->root()->AddEntry(entry);
AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); MoveEntryFromRootDirectory(dir_path,
callback,
GDATA_FILE_OK,
entry->GetFilePath());
} }
void GDataFileSystem::OnAddEntryToDirectoryCompleted( void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted(
const FileOperationCallback& callback, const FileOperationCallback& callback,
const FilePath& file_path, const FilePath& file_path,
const FilePath& dir_path, const FilePath& dir_path,
GDataErrorCode status, GDataErrorCode status,
const GURL& document_url) { const GURL& document_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
GDataFileError error = util::GDataToGDataFileError(status); GDataFileError error = util::GDataToGDataFileError(status);
if (error == GDATA_FILE_OK) { if (error == GDATA_FILE_OK) {
...@@ -2518,8 +2522,7 @@ void GDataFileSystem::OnAddEntryToDirectoryCompleted( ...@@ -2518,8 +2522,7 @@ void GDataFileSystem::OnAddEntryToDirectoryCompleted(
} }
} }
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
} }
void GDataFileSystem::OnRemovedDocument( void GDataFileSystem::OnRemovedDocument(
...@@ -2729,11 +2732,12 @@ void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback( ...@@ -2729,11 +2732,12 @@ void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback(
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
const FilePath& moved_file_path) { const FilePath& moved_file_path) {
DCHECK(!callback.is_null());
if (error == GDATA_FILE_OK) if (error == GDATA_FILE_OK)
OnDirectoryChanged(moved_file_path.DirName()); OnDirectoryChanged(moved_file_path.DirName());
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
} }
GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( GDataFileError GDataFileSystem::RemoveEntryFromFileSystem(
......
...@@ -373,13 +373,16 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -373,13 +373,16 @@ class GDataFileSystem : public GDataFileSystemInterface,
GDataFileError error, GDataFileError error,
scoped_ptr<GDataEntryProto> entry_proto); scoped_ptr<GDataEntryProto> entry_proto);
// Adds a file or directory at |file_path| to the directory at |dir_path|. // Moves a file or directory at |file_path| in the root directory to
// another directory at |dir_path|. This function does nothing if
// |dir_path| points to the root directory.
// //
// Can be called from UI thread. |callback| is run on the calling thread. // Can be called from UI thread. |callback| is run on the calling thread.
void AddEntryToDirectory(const FilePath& dir_path, // |callback| must not be null.
const FileOperationCallback& callback, void MoveEntryFromRootDirectory(const FilePath& dir_path,
GDataFileError error, const FileOperationCallback& callback,
const FilePath& file_path); GDataFileError error,
const FilePath& file_path);
// Removes a file or directory at |file_path| from the directory at // Removes a file or directory at |file_path| from the directory at
// |dir_path| and moves it to the root directory. // |dir_path| and moves it to the root directory.
...@@ -422,13 +425,18 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -422,13 +425,18 @@ class GDataFileSystem : public GDataFileSystemInterface,
GDataErrorCode status, GDataErrorCode status,
scoped_ptr<base::Value> data); scoped_ptr<base::Value> data);
// Callback for handling an attempt to add a file or directory to another // Callback for handling an attempt to move a file or directory from the
// directory. // root directory to another directory on the server side. This function
void OnAddEntryToDirectoryCompleted(const FileOperationCallback& callback, // moves |entry| to the root directory on the client side with
const FilePath& file_path, // GDataDirectoryService::MoveEntryToDirectory().
const FilePath& dir_path, //
GDataErrorCode status, // |callback| must not be null.
const GURL& document_url); void OnMoveEntryFromRootDirectoryCompleted(
const FileOperationCallback& callback,
const FilePath& file_path,
const FilePath& dir_path,
GDataErrorCode status,
const GURL& document_url);
// Callback for handling account metadata fetch. // Callback for handling account metadata fetch.
void OnGetAvailableSpace( void OnGetAvailableSpace(
...@@ -515,6 +523,7 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -515,6 +523,7 @@ class GDataFileSystem : public GDataFileSystemInterface,
// Callback for GDataDirectoryService::MoveEntryToDirectory with // Callback for GDataDirectoryService::MoveEntryToDirectory with
// FileOperationCallback. // FileOperationCallback.
// |callback| must not be null.
void OnMoveEntryToDirectoryWithFileOperationCallback( void OnMoveEntryToDirectoryWithFileOperationCallback(
const FileOperationCallback& callback, const FileOperationCallback& callback,
GDataFileError error, GDataFileError error,
......
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