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) |
@@ -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(); |
} |
@@ -2414,13 +2413,8 @@ |
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); |
+ if (util::GDataToGDataFileError(status) == GDATA_FILE_OK) |
satorux1
2012/08/08 16:04:10
Previously, |callback| was called if != GDATA_FILE
achuithb
2012/08/08 22:08:41
Thank you for catching this. I made this error in
|
+ RenameFileOnFilesystem(file_path, new_name, callback); |
} |
void GDataFileSystem::OnCopyDocumentCompleted( |
@@ -2447,7 +2441,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 +2469,10 @@ |
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::OnAddEntryToDirectory2, ui_weak_ptr_, |
+ callback)); |
+ return; |
} else { |
error = GDATA_FILE_ERROR_NOT_FOUND; |
} |
@@ -2493,14 +2490,8 @@ |
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); |
+ if (util::GDataToGDataFileError(status) == GDATA_FILE_OK) |
+ RemoveEntryFromDirectoryOnFilesystem(file_path, callback); |
} |
void GDataFileSystem::OnRemovedDocument( |
@@ -2626,84 +2617,72 @@ |
// Nothing much to do here for now. |
} |
-GDataFileError GDataFileSystem::RenameFileOnFilesystem( |
+void GDataFileSystem::RenameFileOnFilesystem( |
satorux1
2012/08/08 16:04:10
Filesystem -> FileSystem. could you rename while y
achuithb
2012/08/08 22:08:41
Done.
|
const FilePath& file_path, |
const FilePath::StringType& new_name, |
- FilePath* updated_file_path) { |
+ const FilePathUpdateCallback& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(updated_file_path); |
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, |
+ base::Bind(&GDataFileSystem::OnAddEntryToDirectory, |
+ ui_weak_ptr_, |
+ callback)); |
} |
-GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( |
- GDataEntry* entry, const FilePath& dir_path) { |
+void GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( |
+ const FilePath& file_path, |
+ const FilePathUpdateCallback& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(entry); |
- GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); |
- if (!dir_entry) |
- return GDATA_FILE_ERROR_NOT_FOUND; |
+ GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
+ if (!entry) { |
+ if (!callback.is_null()) |
+ callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); |
+ return; |
+ } |
- GDataDirectory* dir = dir_entry->AsGDataDirectory(); |
- if (!dir) |
- return GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
+ directory_service_->AddEntryToDirectory( |
+ directory_service_->root()->GetFilePath(), entry, |
+ base::Bind(&GDataFileSystem::OnAddEntryToDirectory, |
+ ui_weak_ptr_, callback)); |
+} |
- if (!dir->TakeEntry(entry)) |
- return GDATA_FILE_ERROR_FAILED; |
+void GDataFileSystem::OnAddEntryToDirectory( |
+ const FilePathUpdateCallback& callback, |
+ GDataFileError error, |
+ const FilePath& updated_file_path) { |
+ if (error == GDATA_FILE_OK) |
+ OnDirectoryChanged(updated_file_path.DirName()); |
- FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
- OnDirectoryChanged(dir_path)); |
- return GDATA_FILE_OK; |
+ if (!callback.is_null()) |
+ callback.Run(error, updated_file_path); |
} |
-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::OnAddEntryToDirectory2( |
+ const FileOperationCallback& 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; |
- |
- GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); |
- if (!dir) |
- return GDATA_FILE_ERROR_NOT_FOUND; |
- |
- 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 +2773,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 +2840,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 +2896,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 +2913,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 +2944,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(); |