Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
=================================================================== |
--- chrome/browser/chromeos/gdata/gdata_file_system.cc (revision 151008) |
+++ chrome/browser/chromeos/gdata/gdata_file_system.cc (working copy) |
@@ -1210,13 +1210,13 @@ |
// 3. Adds the file to the parent directory of |dest_file_path|, which |
// effectively moves the file from the root directory to the parent |
// directory of |dest_file_path|. |
- FileMoveCallback add_file_to_directory_callback = |
+ const FileMoveCallback add_file_to_directory_callback = |
base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
ui_weak_ptr_, |
dest_file_path.DirName(), |
callback); |
- FileMoveCallback remove_file_from_directory_callback = |
+ const FileMoveCallback remove_file_from_directory_callback = |
base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, |
ui_weak_ptr_, |
src_file_path.DirName(), |
@@ -1987,47 +1987,13 @@ |
return; |
} |
- directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, |
- base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, |
- ui_weak_ptr_, |
- directory_path, |
- params->directory_resource_id, |
- file_map)); |
+ directory_service_->RefreshDirectory( |
+ params->directory_resource_id, |
+ file_map, |
+ base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
+ ui_weak_ptr_)); |
} |
-void GDataFileSystem::RequestDirectoryRefreshByEntry( |
- const FilePath& directory_path, |
- const std::string& directory_resource_id, |
- const FileResourceIdMap& file_map, |
- GDataEntry* directory_entry) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- |
- if (!directory_entry || !directory_entry->AsGDataDirectory()) { |
- LOG(ERROR) << "Directory entry is gone: " << directory_path.value() |
- << ": " << directory_resource_id; |
- return; |
- } |
- GDataDirectory* directory = directory_entry->AsGDataDirectory(); |
- |
- // Remove the existing files. |
- directory->RemoveChildFiles(); |
- // Go through all entries generated by the feed and add files. |
- for (FileResourceIdMap::const_iterator it = file_map.begin(); |
- it != file_map.end(); ++it) { |
- scoped_ptr<GDataEntry> entry(it->second); |
- // Skip if it's not a file (i.e. directory). |
- if (!entry->AsGDataFile()) |
- continue; |
- directory->AddEntry(entry.release()); |
- } |
- |
- // 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. |
- OnDirectoryChanged(directory_path); |
- DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
-} |
- |
void GDataFileSystem::UpdateFileByResourceId( |
const std::string& resource_id, |
const FileOperationCallback& callback) { |
@@ -2486,11 +2452,13 @@ |
// |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 |
// destination directory by MoveEntryFromRootDirectory(). |
- directory_service_->root()->AddEntry(entry); |
- MoveEntryFromRootDirectory(dir_path, |
- callback, |
- GDATA_FILE_OK, |
- entry->GetFilePath()); |
+ directory_service_->AddEntryToDirectory( |
+ directory_service_->root(), |
+ entry, |
+ base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
+ ui_weak_ptr_, |
+ dir_path, |
+ callback)); |
} |
void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
@@ -2507,7 +2475,9 @@ |
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
if (entry) { |
DCHECK_EQ(directory_service_->root(), entry->parent()); |
- directory_service_->MoveEntryToDirectory(dir_path, entry, |
+ directory_service_->MoveEntryToDirectory( |
+ dir_path, |
+ entry, |
base::Bind( |
&GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback, |
ui_weak_ptr_, |
@@ -2736,6 +2706,13 @@ |
callback.Run(error); |
} |
+void GDataFileSystem::OnDirectoryChangeFileMoveCallback( |
+ GDataFileError error, |
+ const FilePath& directory_path) { |
+ if (error == GDATA_FILE_OK) |
+ OnDirectoryChanged(directory_path); |
+} |
+ |
GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( |
const FilePath& file_path) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -2752,14 +2729,14 @@ |
return GDATA_FILE_OK; |
} |
-// static |
void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, |
GDataDirectory* parent_dir, |
GDataEntry* existing_entry) { |
if (existing_entry && |
// This should always match, but just in case. |
existing_entry->parent() == parent_dir) { |
- parent_dir->RemoveEntry(existing_entry); |
+ directory_service_->RemoveEntryFromParent(existing_entry, |
+ FileMoveCallback()); |
} else { |
LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
} |
@@ -2828,9 +2805,12 @@ |
if (!new_entry) |
return GDATA_FILE_ERROR_FAILED; |
- parent_dir->AddEntry(new_entry); |
- |
- OnDirectoryChanged(directory_path); |
+ directory_service_->AddEntryToDirectory( |
+ parent_dir, |
+ new_entry, |
+ base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, |
+ ui_weak_ptr_, |
+ FileMoveCallback())); |
return GDATA_FILE_OK; |
} |
@@ -2888,10 +2868,10 @@ |
if (entry->AsGDataFile()) |
*resource_id = entry->AsGDataFile()->resource_id(); |
- GDataDirectory* parent_dir = entry->parent(); |
- parent_dir->RemoveEntry(entry); |
- |
- OnDirectoryChanged(parent_dir->GetFilePath()); |
+ directory_service_->RemoveEntryFromParent( |
+ entry, |
+ base::Bind(&GDataFileSystem::OnDirectoryChangeFileMoveCallback, |
+ ui_weak_ptr_)); |
return GDATA_FILE_OK; |
} |
@@ -2953,18 +2933,25 @@ |
if (upload_mode == UPLOAD_EXISTING_FILE) { |
// Remove an existing entry, which should be present. |
const std::string& resource_id = new_entry->resource_id(); |
- directory_service_->GetEntryByResourceIdAsync(resource_id, |
- base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); |
+ directory_service_->GetEntryByResourceIdAsync( |
+ resource_id, |
+ base::Bind(&GDataFileSystem::RemoveStaleEntryOnUpload, |
+ ui_weak_ptr_, |
+ resource_id, |
+ parent_dir)); |
satorux1
2012/08/13 22:35:53
This code path is rather worrisome. I think the or
achuithb
2012/08/14 00:18:44
Done.
|
} |
GDataFile* file = new_entry->AsGDataFile(); |
DCHECK(file); |
const std::string& resource_id = file->resource_id(); |
const std::string& md5 = file->file_md5(); |
- parent_dir->AddEntry(new_entry.release()); |
+ directory_service_->AddEntryToDirectory( |
+ parent_dir, |
+ new_entry.release(), |
+ base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, |
+ ui_weak_ptr_, |
+ FileMoveCallback())); |
- OnDirectoryChanged(virtual_dir_path); |
- |
if (upload_mode == UPLOAD_NEW_FILE) { |
// Add the file to the cache if we have uploaded a new file. |
cache_->StoreOnUIThread(resource_id, |