summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-07 12:51:20 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-07 12:51:20 +0000
commit00975f356c48736cfa137ab6f2f996bed09e7da7 (patch)
tree626c1090da4e6b35085749b2fc79ea072b77dd53
parent7e70fed631016d3e0f4f916137d7e40fb2e61751 (diff)
downloadchromium_src-00975f356c48736cfa137ab6f2f996bed09e7da7.zip
chromium_src-00975f356c48736cfa137ab6f2f996bed09e7da7.tar.gz
chromium_src-00975f356c48736cfa137ab6f2f996bed09e7da7.tar.bz2
chromeos: Remove DriveEntry::parent_
There is no need to maintain parent_ and parent_resource_id_ at the same time. BUG=137375 TEST=unit_tests Review URL: https://chromiumcodereview.appspot.com/12513007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186693 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/drive_files.cc23
-rw-r--r--chrome/browser/chromeos/drive/drive_files.h7
-rw-r--r--chrome/browser/chromeos/drive/drive_resource_metadata.cc22
3 files changed, 30 insertions, 22 deletions
diff --git a/chrome/browser/chromeos/drive/drive_files.cc b/chrome/browser/chromeos/drive/drive_files.cc
index fd724a64..a082a86 100644
--- a/chrome/browser/chromeos/drive/drive_files.cc
+++ b/chrome/browser/chromeos/drive/drive_files.cc
@@ -19,8 +19,7 @@ namespace drive {
// DriveEntry class.
DriveEntry::DriveEntry(DriveResourceMetadata* resource_metadata)
- : parent_(NULL),
- resource_metadata_(resource_metadata),
+ : resource_metadata_(resource_metadata),
deleted_(false) {
DCHECK(resource_metadata);
}
@@ -48,15 +47,16 @@ const DriveDirectory* DriveEntry::AsDriveDirectoryConst() const {
base::FilePath DriveEntry::GetFilePath() const {
base::FilePath path;
- if (parent())
- path = parent()->GetFilePath();
+ DriveEntry* parent = parent_resource_id_.empty() ? NULL :
+ resource_metadata_->GetEntryByResourceId(parent_resource_id_);
+ if (parent)
+ path = parent->GetFilePath();
path = path.Append(base_name());
return path;
}
-void DriveEntry::SetParent(DriveDirectory* parent) {
- parent_ = parent;
- parent_resource_id_ = parent ? parent->resource_id() : "";
+void DriveEntry::set_parent_resource_id(const std::string& parent_resource_id) {
+ parent_resource_id_ = parent_resource_id;
}
void DriveEntry::SetBaseNameFromTitle() {
@@ -104,7 +104,8 @@ DriveDirectory* DriveDirectory::AsDriveDirectory() {
}
void DriveDirectory::AddEntry(DriveEntry* entry) {
- DCHECK(!entry->parent());
+ DCHECK(entry->parent_resource_id().empty() ||
+ entry->parent_resource_id() == resource_id_);
// Try to add the entry to resource map.
if (!resource_metadata_->AddEntryToResourceMap(entry)) {
@@ -151,7 +152,7 @@ void DriveDirectory::AddEntry(DriveEntry* entry) {
if (entry->AsDriveDirectory())
child_directories_.insert(std::make_pair(entry->base_name(),
entry->resource_id()));
- entry->SetParent(this);
+ entry->set_parent_resource_id(resource_id_);
}
void DriveDirectory::TakeOverEntries(DriveDirectory* dir) {
@@ -172,7 +173,7 @@ void DriveDirectory::TakeOverEntry(const std::string& resource_id) {
DriveEntry* entry = resource_metadata_->GetEntryByResourceId(resource_id);
DCHECK(entry);
resource_metadata_->RemoveEntryFromResourceMap(resource_id);
- entry->SetParent(NULL);
+ entry->set_parent_resource_id(std::string());
AddEntry(entry);
}
@@ -209,7 +210,7 @@ void DriveDirectory::RemoveChild(DriveEntry* entry) {
child_files_.erase(base_name);
child_directories_.erase(base_name);
- entry->SetParent(NULL);
+ entry->set_parent_resource_id(std::string());
}
void DriveDirectory::RemoveChildren() {
diff --git a/chrome/browser/chromeos/drive/drive_files.h b/chrome/browser/chromeos/drive/drive_files.h
index 1ad4821..6a1d780 100644
--- a/chrome/browser/chromeos/drive/drive_files.h
+++ b/chrome/browser/chromeos/drive/drive_files.h
@@ -55,8 +55,6 @@ class DriveEntry {
// DriveEntryProto.
void ToProtoFull(DriveEntryProto* proto) const;
- // Return the parent of this entry. NULL for root.
- DriveDirectory* parent() const { return parent_; }
const base::PlatformFileInfo& file_info() const { return file_info_; }
// This is not the full path, use GetFilePath for that.
@@ -105,14 +103,14 @@ class DriveEntry {
virtual void SetBaseNameFromTitle();
protected:
- // For access to SetParent from AddEntry.
+ // For access to set_parent_resource_id() from AddEntry.
friend class DriveDirectory;
explicit DriveEntry(DriveResourceMetadata* resource_metadata);
// Sets the parent directory of this file system entry.
// It is intended to be used by DriveDirectory::AddEntry() only.
- void SetParent(DriveDirectory* parent);
+ void set_parent_resource_id(const std::string& parent_resource_id);
base::PlatformFileInfo file_info_;
// Title of this file (i.e. the 'title' attribute associated with a regular
@@ -137,7 +135,6 @@ class DriveEntry {
// due to de-duplication (See AddEntry).
base::FilePath::StringType base_name_;
- DriveDirectory* parent_;
// Weak pointer to DriveResourceMetadata.
DriveResourceMetadata* resource_metadata_;
bool deleted_;
diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.cc b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
index 7cbeb39..4581ecb 100644
--- a/chrome/browser/chromeos/drive/drive_resource_metadata.cc
+++ b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
@@ -283,8 +283,11 @@ void DriveResourceMetadata::MoveEntryToDirectory(
} else if (!destination->AsDriveDirectory()) {
error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY;
} else {
- if (entry->parent())
- entry->parent()->RemoveChild(entry);
+ DriveDirectory* parent =
+ entry->parent_resource_id().empty() ? NULL :
+ GetEntryByResourceId(entry->parent_resource_id())->AsDriveDirectory();
+ if (parent)
+ parent->RemoveChild(entry);
destination->AsDriveDirectory()->AddEntry(entry);
moved_file_path = entry->GetFilePath();
@@ -317,7 +320,9 @@ void DriveResourceMetadata::RenameEntry(
}
entry->set_title(new_name);
- DCHECK(entry->parent());
+
+ DriveEntry* parent = GetEntryByResourceId(entry->parent_resource_id());
+ DCHECK(parent);
// After changing the title of the entry, call MoveEntryToDirectory to
// remove the entry from its parent directory and then add it back in order to
// go through the file name de-duplication.
@@ -325,7 +330,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, entry->parent()->GetFilePath(), callback);
+ MoveEntryToDirectory(file_path, parent->GetFilePath(), callback);
}
void DriveResourceMetadata::RemoveEntryFromParent(
@@ -346,7 +351,8 @@ void DriveResourceMetadata::RemoveEntryFromParent(
return;
}
- DriveDirectory* parent = entry->parent();
+ DriveDirectory* parent =
+ GetEntryByResourceId(entry->parent_resource_id())->AsDriveDirectory();
DCHECK(parent);
DVLOG(1) << "RemoveEntryFromParent " << entry->GetFilePath().value();
@@ -508,7 +514,11 @@ void DriveResourceMetadata::RefreshEntry(
}
DriveEntry* old_entry = GetEntryByResourceId(drive_entry->resource_id());
- DriveDirectory* old_parent = old_entry ? old_entry->parent() : NULL;
+ DriveDirectory* old_parent = NULL;
+ if (old_entry && !old_entry->parent_resource_id().empty()) {
+ old_parent = GetEntryByResourceId(
+ old_entry->parent_resource_id())->AsDriveDirectory();
+ }
DriveDirectory* new_parent = GetParent(entry_proto.parent_resource_id());
scoped_ptr<DriveEntryProto> result_entry_proto(new DriveEntryProto);