Chromium Code Reviews| 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) |
| @@ -390,6 +390,17 @@ |
| callback.Run(error, path, entry_proto.Pass()); |
| } |
| +// Callback for AddEntryToDirectoryFilePathCallbackRunner. |
| +typedef base::Callback<void(const FilePath&)> |
| + AddEntryToDirectoryCallback; |
|
satorux1
2012/08/10 16:14:44
nit: add a blank line here.
achuithb
2012/08/11 00:37:45
This is gone.
|
| +// This callback for GDataDirectoryService::AddEntryToDirectory passes |
| +// the entry's file path to its callback. |
| +void AddEntryToDirectoryFilePathCallbackRunner(GDataEntry* entry, |
| + const AddEntryToDirectoryCallback& callback) { |
| + DCHECK(!callback.is_null()); |
| + callback.Run(entry->GetFilePath()); |
| +} |
| + |
| } // namespace |
| // GDataFileSystem::CreateDirectoryParams struct implementation. |
| @@ -1987,47 +1998,14 @@ |
| return; |
| } |
| - directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, |
| - base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, |
| + directory_service_->RefreshDirectory( |
| + params->directory_resource_id, |
| + file_map, |
| + base::Bind(&GDataFileSystem::OnDirectoryChanged, |
| ui_weak_ptr_, |
| - directory_path, |
| - params->directory_resource_id, |
| - file_map)); |
| + directory_path)); |
| } |
| -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 +2464,16 @@ |
| // |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, |
|
satorux1
2012/08/10 23:05:55
would it be possible for this function to take GDa
satorux1
2012/08/11 00:12:21
Filed a bug crbug.com/142048
achuithb
2012/08/11 00:37:45
I'll file a bug and add a TODO.
|
| + base::Bind(&AddEntryToDirectoryFilePathCallbackRunner, |
| + entry, |
| + base::Bind(&GDataFileSystem::MoveEntryFromRootDirectory, |
| + ui_weak_ptr_, |
| + dir_path, |
| + callback, |
| + GDATA_FILE_OK))); |
| } |
| void GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted( |
| @@ -2752,14 +2735,13 @@ |
| 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, base::Closure()); |
| } else { |
| LOG(ERROR) << "Entry for the existing file not found: " << resource_id; |
| } |
| @@ -2828,9 +2810,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::OnDirectoryChanged, |
| + ui_weak_ptr_, |
| + directory_path)); |
| return GDATA_FILE_OK; |
| } |
| @@ -2889,9 +2874,11 @@ |
| *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::OnDirectoryChanged, |
| + ui_weak_ptr_, |
| + parent_dir->GetFilePath())); |
| return GDATA_FILE_OK; |
| } |
| @@ -2953,18 +2940,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)); |
| } |
| 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::OnDirectoryChanged, |
| + ui_weak_ptr_, |
| + 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. |
| cache_->StoreOnUIThread(resource_id, |