| Index: chrome/browser/chromeos/gdata/gdata_files.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/gdata/gdata_files.cc (revision 151008)
|
| +++ chrome/browser/chromeos/gdata/gdata_files.cc (working copy)
|
| @@ -5,7 +5,6 @@
|
| #include "chrome/browser/chromeos/gdata/gdata_files.h"
|
|
|
| #include <leveldb/db.h>
|
| -#include <vector>
|
|
|
| #include "base/message_loop_proxy.h"
|
| #include "base/platform_file.h"
|
| @@ -254,6 +253,8 @@
|
| }
|
|
|
| void GDataDirectory::AddEntry(GDataEntry* entry) {
|
| + DCHECK(!entry->parent());
|
| +
|
| // The entry name may have been changed due to prior name de-duplication.
|
| // We need to first restore the file name based on the title before going
|
| // through name de-duplication again when it is added to another directory.
|
| @@ -296,14 +297,18 @@
|
| bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) {
|
| for (GDataFileCollection::iterator iter = dir->child_files_.begin();
|
| iter != dir->child_files_.end(); ++iter) {
|
| - AddEntry(iter->second);
|
| + GDataEntry* entry = iter->second;
|
| + entry->SetParent(NULL);
|
| + AddEntry(entry);
|
| }
|
| dir->child_files_.clear();
|
|
|
| for (GDataDirectoryCollection::iterator iter =
|
| dir->child_directories_.begin();
|
| iter != dir->child_directories_.end(); ++iter) {
|
| - AddEntry(iter->second);
|
| + GDataEntry* entry = iter->second;
|
| + entry->SetParent(NULL);
|
| + AddEntry(entry);
|
| }
|
| dir->child_directories_.clear();
|
| return true;
|
| @@ -355,6 +360,8 @@
|
| // Then delete it from tree.
|
| child_files_.erase(base_name);
|
| child_directories_.erase(base_name);
|
| +
|
| + entry->SetParent(NULL);
|
| }
|
|
|
| void GDataDirectory::RemoveChildren() {
|
| @@ -563,6 +570,20 @@
|
| root_.reset();
|
| }
|
|
|
| +void GDataDirectoryService::AddEntryToDirectory(
|
| + GDataDirectory* directory,
|
| + GDataEntry* new_entry,
|
| + const FileMoveCallback& callback) {
|
| + DCHECK(directory);
|
| + DCHECK(new_entry);
|
| + DCHECK(!callback.is_null());
|
| +
|
| + directory->AddEntry(new_entry);
|
| + DVLOG(1) << "AddEntryToDirectory " << new_entry->GetFilePath().value();
|
| + base::MessageLoopProxy::current()->PostTask(FROM_HERE,
|
| + base::Bind(callback, GDATA_FILE_OK, new_entry->GetFilePath()));
|
| +}
|
| +
|
| void GDataDirectoryService::MoveEntryToDirectory(
|
| const FilePath& directory_path,
|
| GDataEntry* entry,
|
| @@ -585,12 +606,27 @@
|
| moved_file_path = entry->GetFilePath();
|
| error = GDATA_FILE_OK;
|
| }
|
| + DVLOG(1) << "MoveEntryToDirectory " << moved_file_path.value();
|
| if (!callback.is_null()) {
|
| base::MessageLoopProxy::current()->PostTask(
|
| FROM_HERE, base::Bind(callback, error, moved_file_path));
|
| }
|
| }
|
|
|
| +void GDataDirectoryService::RemoveEntryFromParent(
|
| + GDataEntry* entry,
|
| + const FileMoveCallback& callback) {
|
| + GDataDirectory* parent = entry->parent();
|
| + DCHECK(parent);
|
| + DVLOG(1) << "RemoveEntryFromParent " << entry->GetFilePath().value();
|
| +
|
| + parent->RemoveEntry(entry);
|
| + if (!callback.is_null()) {
|
| + base::MessageLoopProxy::current()->PostTask(FROM_HERE,
|
| + base::Bind(callback, GDATA_FILE_OK, parent->GetFilePath()));
|
| + }
|
| +}
|
| +
|
| void GDataDirectoryService::AddEntryToResourceMap(GDataEntry* entry) {
|
| // GDataFileSystem has already locked.
|
| DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id();
|
| @@ -734,6 +770,46 @@
|
| }
|
| }
|
|
|
| +void GDataDirectoryService::RefreshDirectory(
|
| + const std::string& directory_resource_id,
|
| + const ResourceMap& file_map,
|
| + const FileMoveCallback& callback) {
|
| + DCHECK(!callback.is_null());
|
| + GetEntryByResourceIdAsync(
|
| + directory_resource_id,
|
| + base::Bind(&GDataDirectoryService::RefreshDirectoryInternal,
|
| + file_map,
|
| + callback));
|
| +}
|
| +
|
| +// static
|
| +void GDataDirectoryService::RefreshDirectoryInternal(
|
| + const ResourceMap& file_map,
|
| + const FileMoveCallback& callback,
|
| + GDataEntry* directory_entry) {
|
| + DCHECK(!callback.is_null());
|
| +
|
| + if (!directory_entry || !directory_entry->AsGDataDirectory()) {
|
| + LOG(ERROR) << "RefreshDirectoryInternal: Failed to find directory";
|
| + return;
|
| + }
|
| +
|
| + GDataDirectory* directory = directory_entry->AsGDataDirectory();
|
| +
|
| + directory->RemoveChildFiles();
|
| + // Add files from file_map.
|
| + for (ResourceMap::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());
|
| + }
|
| +
|
| + callback.Run(GDATA_FILE_OK, directory->GetFilePath());
|
| +}
|
| +
|
| void GDataDirectoryService::InitFromDB(
|
| const FilePath& db_path,
|
| base::SequencedTaskRunner* blocking_task_runner,
|
|
|