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