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

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

Issue 10827211: Replace GDataDirectory::TakeEntry with GDataDirectoryService::AddEntryToDirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: expect/assert after RunBlockingTask Created 8 years, 4 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
===================================================================
--- chrome/browser/chromeos/gdata/gdata_file_system.cc (revision 150448)
+++ chrome/browser/chromeos/gdata/gdata_file_system.cc (working copy)
@@ -1116,7 +1116,7 @@
documents_service_->RenameResource(
GURL(entry_proto->edit_url()),
file_name,
- base::Bind(&GDataFileSystem::OnRenameResourceCompleted,
+ base::Bind(&GDataFileSystem::RenameFileOnFileSystem,
ui_weak_ptr_,
file_path,
file_name,
@@ -1267,7 +1267,7 @@
dir->content_url(),
entry->edit_url(),
entry->resource_id(),
- base::Bind(&GDataFileSystem::OnRemoveEntryFromDirectoryCompleted,
+ base::Bind(&GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem,
ui_weak_ptr_,
callback,
file_path,
@@ -2008,8 +2008,7 @@
// Note that there may be no change in the directory, but it's expensive to
// check if the new metadata matches the existing one, so we just always
// notify that the directory is changed.
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer,
- observers_, OnDirectoryChanged(directory_path));
+ OnDirectoryChanged(directory_path);
DVLOG(1) << "Directory refreshed: " << directory_path.value();
}
@@ -2406,23 +2405,6 @@
callback.Run(error);
}
-void GDataFileSystem::OnRenameResourceCompleted(
- const FilePath& file_path,
- const FilePath::StringType& new_name,
- const FilePathUpdateCallback& callback,
- GDataErrorCode status,
- const GURL& document_url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- FilePath updated_file_path;
- GDataFileError error = util::GDataToGDataFileError(status);
- if (error == GDATA_FILE_OK)
- error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path);
-
- if (!callback.is_null())
- callback.Run(error, updated_file_path);
-}
-
void GDataFileSystem::OnCopyDocumentCompleted(
const FilePath& dir_path,
const FileOperationCallback& callback,
@@ -2447,7 +2429,7 @@
}
GDataEntry* entry = GDataEntry::FromDocumentEntry(
- directory_service_->root(), doc_entry.get(), directory_service_.get());
+ NULL, doc_entry.get(), directory_service_.get());
if (!entry) {
if (!callback.is_null())
callback.Run(GDATA_FILE_ERROR_FAILED);
@@ -2475,7 +2457,12 @@
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
if (entry) {
DCHECK_EQ(directory_service_->root(), entry->parent());
- error = AddEntryToDirectoryOnFilesystem(entry, dir_path);
+ directory_service_->AddEntryToDirectory(dir_path, entry,
+ base::Bind(
+ &GDataFileSystem::OnAddEntryToDirectoryWithFileOperationCallback,
+ ui_weak_ptr_,
+ callback));
+ return;
} else {
error = GDATA_FILE_ERROR_NOT_FOUND;
}
@@ -2485,24 +2472,6 @@
callback.Run(error);
}
-void GDataFileSystem::OnRemoveEntryFromDirectoryCompleted(
- const FilePathUpdateCallback& callback,
- const FilePath& file_path,
- const FilePath& dir_path,
- GDataErrorCode status,
- const GURL& document_url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- FilePath updated_file_path = file_path;
- GDataFileError error = util::GDataToGDataFileError(status);
- if (error == GDATA_FILE_OK)
- error = RemoveEntryFromDirectoryOnFilesystem(file_path, dir_path,
- &updated_file_path);
-
- if (!callback.is_null())
- callback.Run(error, updated_file_path);
-}
-
void GDataFileSystem::OnRemovedDocument(
const FileOperationCallback& callback,
const FilePath& file_path,
@@ -2626,84 +2595,92 @@
// Nothing much to do here for now.
}
-GDataFileError GDataFileSystem::RenameFileOnFilesystem(
+void GDataFileSystem::RenameFileOnFileSystem(
const FilePath& file_path,
const FilePath::StringType& new_name,
- FilePath* updated_file_path) {
+ const FilePathUpdateCallback& callback,
+ GDataErrorCode status,
+ const GURL& document_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(updated_file_path);
+ const GDataFileError error = util::GDataToGDataFileError(status);
+ if (error != GDATA_FILE_OK) {
+ if (!callback.is_null())
+ callback.Run(error, FilePath());
+ return;
+ }
+
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
- if (!entry)
- return GDATA_FILE_ERROR_NOT_FOUND;
+ if (!entry) {
+ if (!callback.is_null())
+ callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
+ return;
+ }
DCHECK(entry->parent());
entry->set_title(new_name);
- // After changing the title of the entry, call TakeFile() to remove the
- // entry from its parent directory and then add it back in order to go
+ // After changing the title of the entry, call AddEntryToDirectory() to remove
+ // the entry from its parent directory and then add it back in order to go
// through the file name de-duplication.
// TODO(achuith/satorux/zel): This code is fragile. The title has been
- // changed, but not the file_name. TakeEntry removes the child based on the
- // old file_name, and then re-adds the child by first assigning the new title
- // to file_name. http://crbug.com/30157
- if (!entry->parent()->TakeEntry(entry))
- return GDATA_FILE_ERROR_FAILED;
-
- *updated_file_path = entry->GetFilePath();
-
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(updated_file_path->DirName()));
- return GDATA_FILE_OK;
+ // changed, but not the file_name. AddEntryToDirectory calls RemoveChild to
+ // remove the child based on the old file_name, and then re-adds the child by
+ // first assigning the new title to file_name. http://crbug.com/30157
+ directory_service_->AddEntryToDirectory(entry->parent()->GetFilePath(), entry,
satorux1 2012/08/08 23:25:01 nit: when it cannot fit one line, let's align para
achuithb 2012/08/09 00:12:51 Done.
+ base::Bind(&GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback,
+ ui_weak_ptr_,
+ callback));
}
-GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem(
- GDataEntry* entry, const FilePath& dir_path) {
+void GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem(
+ const FilePathUpdateCallback& callback,
+ const FilePath& file_path,
+ const FilePath& dir_path,
+ GDataErrorCode status,
+ const GURL& document_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(entry);
- GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path);
- if (!dir_entry)
- return GDATA_FILE_ERROR_NOT_FOUND;
+ const GDataFileError error = util::GDataToGDataFileError(status);
+ if (error != GDATA_FILE_OK) {
+ if (!callback.is_null())
+ callback.Run(error, FilePath());
+ return;
+ }
- GDataDirectory* dir = dir_entry->AsGDataDirectory();
- if (!dir)
- return GDATA_FILE_ERROR_NOT_A_DIRECTORY;
+ GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
+ if (!entry) {
+ if (!callback.is_null())
+ callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath());
+ return;
+ }
- if (!dir->TakeEntry(entry))
- return GDATA_FILE_ERROR_FAILED;
-
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(dir_path));
- return GDATA_FILE_OK;
+ directory_service_->AddEntryToDirectory(
+ directory_service_->root()->GetFilePath(), entry,
satorux1 2012/08/08 23:25:01 nit: move entry to the next line
achuithb 2012/08/09 00:12:51 Done.
+ base::Bind(&GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback,
+ ui_weak_ptr_,
+ callback));
}
-GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem(
- const FilePath& file_path, const FilePath& dir_path,
- FilePath* updated_file_path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(updated_file_path);
+void GDataFileSystem::OnAddEntryToDirectoryWithFileUpdateCallback(
+ const FilePathUpdateCallback& callback,
+ GDataFileError error,
+ const FilePath& updated_file_path) {
+ if (error == GDATA_FILE_OK)
+ OnDirectoryChanged(updated_file_path.DirName());
- GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
- if (!entry)
- return GDATA_FILE_ERROR_NOT_FOUND;
+ if (!callback.is_null())
+ callback.Run(error, updated_file_path);
+}
- GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path);
- if (!dir)
- return GDATA_FILE_ERROR_NOT_FOUND;
+void GDataFileSystem::OnAddEntryToDirectoryWithFileOperationCallback(
+ const FileOperationCallback& callback,
+ GDataFileError error,
+ const FilePath& updated_file_path) {
+ if (error == GDATA_FILE_OK)
+ OnDirectoryChanged(updated_file_path.DirName());
- if (!dir->AsGDataDirectory())
- return GDATA_FILE_ERROR_NOT_A_DIRECTORY;
-
- DCHECK_EQ(dir->AsGDataDirectory(), entry->parent());
-
- if (!directory_service_->root()->TakeEntry(entry))
- return GDATA_FILE_ERROR_FAILED;
-
- *updated_file_path = entry->GetFilePath();
-
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(updated_file_path->DirName()));
- return GDATA_FILE_OK;
+ if (!callback.is_null())
+ callback.Run(error);
}
GDataFileError GDataFileSystem::RemoveEntryFromFileSystem(
@@ -2794,14 +2771,13 @@
return GDATA_FILE_ERROR_FAILED;
GDataEntry* new_entry = GDataEntry::FromDocumentEntry(
- parent_dir, doc_entry.get(), directory_service_.get());
+ NULL, doc_entry.get(), directory_service_.get());
if (!new_entry)
return GDATA_FILE_ERROR_FAILED;
parent_dir->AddEntry(new_entry);
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(directory_path));
+ OnDirectoryChanged(directory_path);
return GDATA_FILE_OK;
}
@@ -2862,8 +2838,7 @@
GDataDirectory* parent_dir = entry->parent();
parent_dir->RemoveEntry(entry);
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(parent_dir->GetFilePath()));
+ OnDirectoryChanged(parent_dir->GetFilePath());
return GDATA_FILE_OK;
}
@@ -2919,7 +2894,7 @@
scoped_ptr<GDataEntry> new_entry(
GDataEntry::FromDocumentEntry(
- parent_dir, entry.get(), directory_service_.get()));
+ NULL, entry.get(), directory_service_.get()));
if (!new_entry.get())
return;
@@ -2936,8 +2911,7 @@
const std::string& md5 = file->file_md5();
parent_dir->AddEntry(new_entry.release());
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(virtual_dir_path));
+ OnDirectoryChanged(virtual_dir_path);
if (upload_mode == UPLOAD_NEW_FILE) {
// Add the file to the cache if we have uploaded a new file.
@@ -2968,8 +2942,7 @@
if (*pref_name == prefs::kDisableGDataHostedFiles) {
const FilePath root_path = directory_service_->root()->GetFilePath();
// Kick off directory refresh when this setting changes.
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
- OnDirectoryChanged(root_path));
+ OnDirectoryChanged(root_path);
}
} else {
NOTREACHED();

Powered by Google App Engine
This is Rietveld 408576698