Commit 9ff2db80 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Fix bad function names in GDataFileSystem

- RemoveEntryFromDirectory() was a misnomer. It removes an entry if it's
  not on the root directory. The |dir_path| parameter was unnecessary
  as it can be obtained from |file_path|.
  New name: RemoveEntryFromNonRootDirectory()

- RemoveEntryFromDirectoryOnFileSystem() was a misnomer. It moves an
  entry to the root directory on the client side
  New name: MoveEntryToRootDirectoryOnClientSide()

- Rename *OnFileSystem() with *OnClientSide() to make it clear these are
  client side operations

- Rename OnMoveEntryToDirectoryWithFileMoveCallback() to
  NotifyAndRunFileMoveCallback() based on what it does

- Rename OnMoveEntryToDirectoryWithFileOperationCallback() to
  NotifyAndRunFileOperationCallback() based on what it does

Along the way, eliminate if (!callback.is_null()) and PostTask() from
places where these are unnecessary.

BUG=126634, 139446
TEST=moving and renaming of files on Drive works as before

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151115 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b79299d
......@@ -1129,7 +1129,7 @@ void GDataFileSystem::RenameAfterGetEntryInfo(
documents_service_->RenameResource(
GURL(entry_proto->edit_url()),
file_name,
base::Bind(&GDataFileSystem::RenameFileOnFileSystem,
base::Bind(&GDataFileSystem::RenameEntryLocally,
ui_weak_ptr_,
file_path,
file_name,
......@@ -1217,9 +1217,8 @@ void GDataFileSystem::MoveOnUIThreadAfterGetEntryInfoPair(
callback);
FileMoveCallback remove_file_from_directory_callback =
base::Bind(&GDataFileSystem::RemoveEntryFromDirectory,
base::Bind(&GDataFileSystem::RemoveEntryFromNonRootDirectory,
ui_weak_ptr_,
src_file_path.DirName(),
add_file_to_directory_callback);
Rename(src_file_path, dest_file_path.BaseName().value(),
......@@ -1285,13 +1284,14 @@ void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair(
dir_path));
}
void GDataFileSystem::RemoveEntryFromDirectory(
const FilePath& dir_path,
void GDataFileSystem::RemoveEntryFromNonRootDirectory(
const FileMoveCallback& callback,
GDataFileError error,
const FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
const FilePath dir_path = file_path.DirName();
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path);
if (error == GDATA_FILE_OK) {
......@@ -1306,10 +1306,7 @@ void GDataFileSystem::RemoveEntryFromDirectory(
// Returns if there is an error or |dir_path| is the root directory.
if (error != GDATA_FILE_OK ||
dir->resource_id() == kGDataRootDirectoryResourceId) {
if (!callback.is_null()) {
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(callback, error, file_path));
}
callback.Run(error, file_path);
return;
}
......@@ -1317,7 +1314,7 @@ void GDataFileSystem::RemoveEntryFromDirectory(
dir->content_url(),
entry->edit_url(),
entry->resource_id(),
base::Bind(&GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem,
base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally,
ui_weak_ptr_,
callback,
file_path,
......@@ -2531,7 +2528,7 @@ void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted(
DCHECK_EQ(directory_service_->root(), entry->parent());
directory_service_->MoveEntryToDirectory(dir_path, entry,
base::Bind(
&GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback,
&GDataFileSystem::NotifyAndRunFileOperationCallback,
ui_weak_ptr_,
callback));
return;
......@@ -2553,7 +2550,7 @@ void GDataFileSystem::OnRemovedDocument(
GDataFileError error = util::GDataToGDataFileError(status);
if (error == GDATA_FILE_OK)
error = RemoveEntryFromFileSystem(file_path);
error = RemoveEntryAndCacheLocally(file_path);
if (!callback.is_null()) {
callback.Run(error);
......@@ -2666,7 +2663,7 @@ void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error,
// Nothing much to do here for now.
}
void GDataFileSystem::RenameFileOnFileSystem(
void GDataFileSystem::RenameEntryLocally(
const FilePath& file_path,
const FilePath::StringType& new_name,
const FileMoveCallback& callback,
......@@ -2700,56 +2697,58 @@ void GDataFileSystem::RenameFileOnFileSystem(
directory_service_->MoveEntryToDirectory(
entry->parent()->GetFilePath(),
entry,
base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback,
base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
ui_weak_ptr_,
callback));
}
void GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem(
void GDataFileSystem::MoveEntryToRootDirectoryLocally(
const FileMoveCallback& callback,
const FilePath& file_path,
const FilePath& dir_path,
GDataErrorCode status,
const GURL& document_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
const GDataFileError error = util::GDataToGDataFileError(status);
if (error != GDATA_FILE_OK) {
if (!callback.is_null())
callback.Run(error, FilePath());
callback.Run(error, FilePath());
return;
}
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
if (!entry) {
if (!callback.is_null())
callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
return;
}
directory_service_->MoveEntryToDirectory(
directory_service_->root()->GetFilePath(),
entry,
base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback,
base::Bind(&GDataFileSystem::NotifyAndRunFileMoveCallback,
ui_weak_ptr_,
callback));
}
void GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback(
void GDataFileSystem::NotifyAndRunFileMoveCallback(
const FileMoveCallback& callback,
GDataFileError error,
const FilePath& moved_file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error == GDATA_FILE_OK)
OnDirectoryChanged(moved_file_path.DirName());
if (!callback.is_null())
callback.Run(error, moved_file_path);
callback.Run(error, moved_file_path);
}
void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback(
void GDataFileSystem::NotifyAndRunFileOperationCallback(
const FileOperationCallback& callback,
GDataFileError error,
const FilePath& moved_file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error == GDATA_FILE_OK)
......@@ -2758,12 +2757,12 @@ void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback(
callback.Run(error);
}
GDataFileError GDataFileSystem::RemoveEntryFromFileSystem(
GDataFileError GDataFileSystem::RemoveEntryAndCacheLocally(
const FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
std::string resource_id;
GDataFileError error = RemoveEntryFromGData(file_path, &resource_id);
GDataFileError error = RemoveEntryLocally(file_path, &resource_id);
if (error != GDATA_FILE_OK)
return error;
......@@ -2889,7 +2888,7 @@ GDataFileSystem::FindFirstMissingParentDirectory(
return DIRECTORY_ALREADY_PRESENT;
}
GDataFileError GDataFileSystem::RemoveEntryFromGData(
GDataFileError GDataFileSystem::RemoveEntryLocally(
const FilePath& file_path, std::string* resource_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
......@@ -390,21 +390,22 @@ class GDataFileSystem : public GDataFileSystemInterface,
const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result);
// Removes a file or directory at |file_path| from the directory at
// |dir_path| and moves it to the root directory.
// Removes a file or directory at |file_path| from the current directory if
// it's not in the root directory. This essentially moves an entry to the
// root directory on the server side.
//
// Can be called from UI thread. |callback| is run on the calling thread.
void RemoveEntryFromDirectory(const FilePath& dir_path,
const FileMoveCallback& callback,
GDataFileError error,
const FilePath& file_path);
// |callback| must not be null.
void RemoveEntryFromNonRootDirectory(const FileMoveCallback& callback,
GDataFileError error,
const FilePath& file_path);
// Removes file under |file_path| from in-memory snapshot of the file system.
// Removes file under |file_path| on the client side.
// |resource_id| contains the resource id of the removed file if it was a
// file.
// Return PLATFORM_FILE_OK if successful.
GDataFileError RemoveEntryFromGData(const FilePath& file_path,
std::string* resource_id);
GDataFileError RemoveEntryLocally(const FilePath& file_path,
std::string* resource_id);
// A pass-through callback used for bridging from
// FileMoveCallback to FileOperationCallback.
......@@ -498,39 +499,42 @@ class GDataFileSystem : public GDataFileSystemInterface,
const std::string& md5);
// Callback for handling resource rename attempt. Renames a file or
// directory at |file_path| on in-memory snapshot of the file system.
void RenameFileOnFileSystem(const FilePath& file_path,
const FilePath::StringType& new_name,
const FileMoveCallback& callback,
GDataErrorCode status,
const GURL& document_url);
// directory at |file_path| on the client side.
// |callback| must not be null.
void RenameEntryLocally(const FilePath& file_path,
const FilePath::StringType& new_name,
const FileMoveCallback& callback,
GDataErrorCode status,
const GURL& document_url);
// Callback for handling an attempt to remove a file or directory from
// another directory. Removes a file or directory at |file_path| and moves it
// to root on in-memory snapshot of the file system.
void RemoveEntryFromDirectoryOnFileSystem(
// another directory. Moves a file or directory at |file_path| to root on
// the client side.
// |callback| must not be null.
void MoveEntryToRootDirectoryLocally(
const FileMoveCallback& callback,
const FilePath& file_path,
const FilePath& dir_path,
GDataErrorCode status,
const GURL& document_url);
// Removes a file or directory under |file_path| from in-memory snapshot of
// the file system and the corresponding file from cache if it exists.
// Return PLATFORM_FILE_OK if successful.
GDataFileError RemoveEntryFromFileSystem(const FilePath& file_path);
// Removes a file or directory under |file_path| on the client side and the
// corresponding file from cache if it exists. Returns PLATFORM_FILE_OK if
// successful.
GDataFileError RemoveEntryAndCacheLocally(const FilePath& file_path);
// Callback for GDataDirectoryService::MoveEntryToDirectory with
// FileMoveCallback.
void OnMoveEntryToDirectoryWithFileMoveCallback(
// Callback when an entry is moved to another directory on the client side.
// Notifies the directory change and runs |callback|.
// |callback| must not be null.
void NotifyAndRunFileMoveCallback(
const FileMoveCallback& callback,
GDataFileError error,
const FilePath& moved_file_path);
// Callback for GDataDirectoryService::MoveEntryToDirectory with
// FileOperationCallback.
// Callback when an entry is moved to another directory on the client side.
// Notifies the directory change and runs |callback|.
// |callback| must not be null.
void OnMoveEntryToDirectoryWithFileOperationCallback(
void NotifyAndRunFileOperationCallback(
const FileOperationCallback& callback,
GDataFileError error,
const FilePath& moved_file_path);
......
......@@ -336,7 +336,7 @@ class GDataFileSystemTest : public testing::Test {
}
bool RemoveEntry(const FilePath& file_path) {
return file_system_->RemoveEntryFromFileSystem(file_path) ==
return file_system_->RemoveEntryAndCacheLocally(file_path) ==
GDATA_FILE_OK;
}
......
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