summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/drive/drive_files.cc34
-rw-r--r--chrome/browser/chromeos/drive/drive_files.h16
-rw-r--r--chrome/browser/chromeos/drive/drive_resource_metadata.cc58
-rw-r--r--chrome/browser/chromeos/drive/drive_resource_metadata.h7
4 files changed, 56 insertions, 59 deletions
diff --git a/chrome/browser/chromeos/drive/drive_files.cc b/chrome/browser/chromeos/drive/drive_files.cc
index 343d7de..3f6a890 100644
--- a/chrome/browser/chromeos/drive/drive_files.cc
+++ b/chrome/browser/chromeos/drive/drive_files.cc
@@ -14,9 +14,7 @@ namespace drive {
// DriveEntry class.
-DriveEntry::DriveEntry(DriveResourceMetadata* resource_metadata)
- : resource_metadata_(resource_metadata) {
- DCHECK(resource_metadata);
+DriveEntry::DriveEntry() {
}
DriveEntry::~DriveEntry() {
@@ -26,16 +24,6 @@ DriveDirectory* DriveEntry::AsDriveDirectory() {
return NULL;
}
-base::FilePath DriveEntry::GetFilePath() const {
- base::FilePath path;
- DriveEntry* parent = proto_.parent_resource_id().empty() ? NULL :
- resource_metadata_->GetEntryByResourceId(proto_.parent_resource_id());
- if (parent)
- path = parent->GetFilePath();
- path = path.Append(proto_.base_name());
- return path;
-}
-
void DriveEntry::set_parent_resource_id(const std::string& parent_resource_id) {
proto_.set_parent_resource_id(parent_resource_id);
}
@@ -53,7 +41,7 @@ void DriveEntry::SetBaseNameFromTitle() {
// DriveDirectory class implementation.
DriveDirectory::DriveDirectory(DriveResourceMetadata* resource_metadata)
- : DriveEntry(resource_metadata) {
+ : resource_metadata_(resource_metadata) {
proto_.mutable_file_info()->set_is_directory(true);
}
@@ -109,11 +97,6 @@ void DriveDirectory::AddEntry(DriveEntry* entry) {
}
entry->set_base_name(full_file_name.value());
- DVLOG(1) << "AddEntry: dir = " << GetFilePath().value()
- << ", file = " + entry->base_name()
- << ", parent resource = " << entry->parent_resource_id()
- << ", resource = " + entry->resource_id();
-
// Setup child and parent links.
children_.insert(std::make_pair(entry->base_name(),
entry->resource_id()));
@@ -203,19 +186,6 @@ void DriveDirectory::RemoveChildDirectories() {
}
}
-void DriveDirectory::GetChildDirectoryPaths(
- std::set<base::FilePath>* child_dirs) {
- for (ChildMap::const_iterator iter = children_.begin();
- iter != children_.end(); ++iter) {
- DriveDirectory* dir = resource_metadata_->GetEntryByResourceId(
- iter->second)->AsDriveDirectory();
- if (dir) {
- child_dirs->insert(dir->GetFilePath());
- dir->GetChildDirectoryPaths(child_dirs);
- }
- }
-}
-
// Convert to/from proto.
void DriveEntry::FromProto(const DriveEntryProto& proto) {
diff --git a/chrome/browser/chromeos/drive/drive_files.h b/chrome/browser/chromeos/drive/drive_files.h
index dab8a58..92235da 100644
--- a/chrome/browser/chromeos/drive/drive_files.h
+++ b/chrome/browser/chromeos/drive/drive_files.h
@@ -66,11 +66,6 @@ class DriveEntry {
return proto_.parent_resource_id();
}
- // Returns virtual file path representing this file system entry. This path
- // corresponds to file path expected by public methods of DriveFileSystem
- // class.
- base::FilePath GetFilePath() const;
-
// Sets |base_name_| based on the value of |title_| without name
// de-duplication (see AddEntry() for details on de-duplication).
virtual void SetBaseNameFromTitle();
@@ -80,7 +75,7 @@ class DriveEntry {
// For access to set_parent_resource_id() from AddEntry.
friend class DriveDirectory;
- explicit DriveEntry(DriveResourceMetadata* resource_metadata);
+ DriveEntry();
// Sets the parent directory of this file system entry.
// It is intended to be used by DriveDirectory::AddEntry() only.
@@ -88,9 +83,6 @@ class DriveEntry {
DriveEntryProto proto_;
- // Weak pointer to DriveResourceMetadata.
- DriveResourceMetadata* resource_metadata_;
-
private:
DISALLOW_COPY_AND_ASSIGN(DriveEntry);
};
@@ -153,14 +145,14 @@ class DriveDirectory : public DriveEntry {
void RemoveChildFiles();
void RemoveChildDirectories();
- // Recursively extracts the paths set of all sub-directories.
- void GetChildDirectoryPaths(std::set<base::FilePath>* child_dirs);
-
// Map between base_name and resource_id of files and directories.
typedef std::map<base::FilePath::StringType, std::string> ChildMap;
// Collection of children.
ChildMap children_;
+ // Weak pointer to DriveResourceMetadata.
+ DriveResourceMetadata* resource_metadata_;
+
DISALLOW_COPY_AND_ASSIGN(DriveDirectory);
};
diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.cc b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
index 2b2be33..1fc91a9 100644
--- a/chrome/browser/chromeos/drive/drive_resource_metadata.cc
+++ b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
@@ -87,7 +87,7 @@ DriveResourceMetadata::~DriveResourceMetadata() {
}
scoped_ptr<DriveEntry> DriveResourceMetadata::CreateDriveEntry() {
- return scoped_ptr<DriveEntry>(new DriveEntry(this));
+ return scoped_ptr<DriveEntry>(new DriveEntry());
}
scoped_ptr<DriveDirectory> DriveResourceMetadata::CreateDriveDirectory() {
@@ -157,7 +157,7 @@ void DriveResourceMetadata::MoveEntryToDirectory(
parent->RemoveChild(entry);
destination->AsDriveDirectory()->AddEntry(entry);
- moved_file_path = entry->GetFilePath();
+ moved_file_path = GetFilePath(entry->proto());
error = DRIVE_FILE_OK;
}
DVLOG(1) << "MoveEntryToDirectory " << moved_file_path.value();
@@ -197,7 +197,7 @@ void DriveResourceMetadata::RenameEntry(
// changed, but not the file_name. MoveEntryToDirectory 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
- MoveEntryToDirectory(file_path, parent->GetFilePath(), callback);
+ MoveEntryToDirectory(file_path, GetFilePath(parent->proto()), callback);
}
void DriveResourceMetadata::RemoveEntryFromParent(
@@ -222,11 +222,11 @@ void DriveResourceMetadata::RemoveEntryFromParent(
GetEntryByResourceId(entry->parent_resource_id())->AsDriveDirectory();
DCHECK(parent);
- DVLOG(1) << "RemoveEntryFromParent " << entry->GetFilePath().value();
+ DVLOG(1) << "RemoveEntryFromParent " << GetFilePath(entry->proto()).value();
parent->RemoveEntry(entry);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
- base::Bind(callback, DRIVE_FILE_OK, parent->GetFilePath()));
+ base::Bind(callback, DRIVE_FILE_OK, GetFilePath(parent->proto())));
}
bool DriveResourceMetadata::AddEntryToResourceMap(DriveEntry* entry) {
@@ -248,7 +248,7 @@ void DriveResourceMetadata::RemoveEntryFromResourceMap(
DriveEntry* DriveResourceMetadata::FindEntryByPathSync(
const base::FilePath& file_path) {
- if (file_path == root_->GetFilePath())
+ if (file_path == GetFilePath(root_->proto()))
return root_.get();
std::vector<base::FilePath::StringType> components;
@@ -292,7 +292,7 @@ void DriveResourceMetadata::GetEntryInfoByResourceId(
if (entry) {
entry_proto.reset(new DriveEntryProto(entry->proto()));
error = DRIVE_FILE_OK;
- drive_file_path = entry->GetFilePath();
+ drive_file_path = GetFilePath(entry->proto());
} else {
error = DRIVE_FILE_ERROR_NOT_FOUND;
}
@@ -416,7 +416,7 @@ void DriveResourceMetadata::RefreshEntry(
new_parent->AddEntry(new_entry); // Transfers ownership.
}
- DVLOG(1) << "RefreshEntry " << new_entry->GetFilePath().value();
+ DVLOG(1) << "RefreshEntry " << GetFilePath(new_entry->proto()).value();
// Note that base_name is not the same for new_entry and entry_proto.
scoped_ptr<DriveEntryProto> result_entry_proto(
new DriveEntryProto(new_entry->proto()));
@@ -424,7 +424,7 @@ void DriveResourceMetadata::RefreshEntry(
FROM_HERE,
base::Bind(callback,
DRIVE_FILE_OK,
- new_entry->GetFilePath(),
+ GetFilePath(new_entry->proto()),
base::Passed(&result_entry_proto)));
}
@@ -463,7 +463,7 @@ void DriveResourceMetadata::RefreshDirectory(
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
- base::Bind(callback, DRIVE_FILE_OK, directory->GetFilePath()));
+ base::Bind(callback, DRIVE_FILE_OK, GetFilePath(directory->proto())));
}
void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto,
@@ -485,9 +485,10 @@ void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto,
DriveEntry* added_entry = new_entry.release();
parent->AddEntry(added_entry); // Transfers ownership.
- DVLOG(1) << "AddEntry " << added_entry->GetFilePath().value();
- base::MessageLoopProxy::current()->PostTask(FROM_HERE,
- base::Bind(callback, DRIVE_FILE_OK, added_entry->GetFilePath()));
+ DVLOG(1) << "AddEntry " << GetFilePath(added_entry->proto()).value();
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, DRIVE_FILE_OK, GetFilePath(added_entry->proto())));
}
DriveDirectory* DriveResourceMetadata::GetParent(
@@ -501,6 +502,17 @@ DriveDirectory* DriveResourceMetadata::GetParent(
return entry ? entry->AsDriveDirectory() : NULL;
}
+base::FilePath DriveResourceMetadata::GetFilePath(
+ const DriveEntryProto& entry) {
+ base::FilePath path;
+ DriveEntry* parent = entry.parent_resource_id().empty() ? NULL :
+ GetEntryByResourceId(entry.parent_resource_id());
+ if (parent)
+ path = GetFilePath(parent->proto());
+ path = path.Append(entry.base_name());
+ return path;
+}
+
void DriveResourceMetadata::GetChildDirectories(
const std::string& resource_id,
const GetChildDirectoriesCallback& changed_dirs_callback) {
@@ -509,14 +521,30 @@ void DriveResourceMetadata::GetChildDirectories(
std::set<base::FilePath> changed_directories;
DriveEntry* entry = GetEntryByResourceId(resource_id);
- if (entry && entry->AsDriveDirectory())
- entry->AsDriveDirectory()->GetChildDirectoryPaths(&changed_directories);
+ DriveDirectory* directory = entry ? entry->AsDriveDirectory() : NULL;
+ if (directory)
+ GetDescendantDirectoryPaths(*directory, &changed_directories);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(changed_dirs_callback, changed_directories));
}
+void DriveResourceMetadata::GetDescendantDirectoryPaths(
+ const DriveDirectory& directory,
+ std::set<base::FilePath>* child_directories) {
+ for (DriveDirectory::ChildMap::const_iterator iter =
+ directory.children_.begin();
+ iter != directory.children_.end(); ++iter) {
+ DriveDirectory* dir =
+ GetEntryByResourceId(iter->second)->AsDriveDirectory();
+ if (dir) {
+ child_directories->insert(GetFilePath(dir->proto()));
+ GetDescendantDirectoryPaths(*dir, child_directories);
+ }
+ }
+}
+
void DriveResourceMetadata::RemoveAll(const base::Closure& callback) {
root_->RemoveChildren();
base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback);
diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.h b/chrome/browser/chromeos/drive/drive_resource_metadata.h
index 6871875..bb187fe 100644
--- a/chrome/browser/chromeos/drive/drive_resource_metadata.h
+++ b/chrome/browser/chromeos/drive/drive_resource_metadata.h
@@ -353,6 +353,13 @@ class DriveResourceMetadata : public DriveResourceMetadataInterface {
// directory.
DriveDirectory* GetParent(const std::string& parent_resource_id);
+ // Returns virtual file path of the entry.
+ base::FilePath GetFilePath(const DriveEntryProto& entry);
+
+ // Recursively extracts the paths set of all sub-directories.
+ void GetDescendantDirectoryPaths(const DriveDirectory& directory,
+ std::set<base::FilePath>* child_directories);
+
// Private data members.
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;