Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(975)

Unified Diff: chrome/browser/chromeos/drive/drive_resource_metadata.cc

Issue 11227020: Set root resource ID upon full feed update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/drive/drive_resource_metadata.cc
diff --git a/chrome/browser/chromeos/drive/drive_resource_metadata.cc b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
index 11b4a66670c05d4f5451648ce2c6471c1a13aa42..cee565f64c758e4192b5138bb5455a71f996dcaa 100644
--- a/chrome/browser/chromeos/drive/drive_resource_metadata.cc
+++ b/chrome/browser/chromeos/drive/drive_resource_metadata.cc
@@ -195,8 +195,8 @@ DriveResourceMetadata::DriveResourceMetadata()
origin_(UNINITIALIZED),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
root_ = CreateDriveDirectory().Pass();
- if (!google_apis::util::IsDriveV2ApiEnabled())
- InitializeRootEntry(kDriveRootDirectoryResourceId);
+ root_->set_title(kDriveRootDirectory);
+ root_->SetBaseNameFromTitle();
}
DriveResourceMetadata::~DriveResourceMetadata() {
@@ -229,11 +229,9 @@ scoped_ptr<DriveDirectory> DriveResourceMetadata::CreateDriveDirectory() {
return scoped_ptr<DriveDirectory>(new DriveDirectory(this));
}
-void DriveResourceMetadata::InitializeRootEntry(const std::string& root_id) {
- root_ = CreateDriveDirectory().Pass();
- root_->set_title(kDriveRootDirectory);
- root_->SetBaseNameFromTitle();
- root_->set_resource_id(root_id);
+void DriveResourceMetadata::InitializeRootEntry(const std::string& id) {
+ DCHECK(root_->resource_id().empty());
+ root_->set_resource_id(id);
AddEntryToResourceMap(root_.get());
}
@@ -241,11 +239,17 @@ void DriveResourceMetadata::ClearRoot() {
if (!root_.get())
return;
+ // The root is not yet initialized.
+ if (root_->resource_id().empty())
+ return;
+
// Note that children have a reference to root_,
// so we need to delete them here.
root_->RemoveChildren();
RemoveEntryFromResourceMap(root_->resource_id());
DCHECK(resource_map_.empty());
+ // The resource_map_ should be empty here, but to make sure for non-Debug
+ // build.
resource_map_.clear();
root_.reset();
}
@@ -362,7 +366,7 @@ void DriveResourceMetadata::RemoveEntryFromParent(
DCHECK(!callback.is_null());
// Disallow deletion of root.
- if (resource_id == kDriveRootDirectoryResourceId) {
+ if (resource_id == root_->resource_id()) {
PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_ACCESS_DENIED);
return;
}
@@ -649,7 +653,6 @@ void DriveResourceMetadata::InitResourceMap(
DCHECK(!resource_metadata_db_.get());
DCHECK(!callback.is_null());
-
SerializedMap* serialized_resources = &create_params->serialized_resources;
resource_metadata_db_ = create_params->db.Pass();
if (serialized_resources->empty()) {
@@ -657,6 +660,8 @@ void DriveResourceMetadata::InitResourceMap(
return;
}
+ // Save root directory resource ID as ClearRoot() resets |root_|.
+ std::string saved_root_resource_id = root_->resource_id();
ClearRoot();
// Version check.
@@ -718,7 +723,7 @@ void DriveResourceMetadata::InitResourceMap(
} else {
NOTREACHED() << "Parent is not a directory " << parent->resource_id();
}
- } else if (entry->resource_id() == kDriveRootDirectoryResourceId) {
+ } else if (entry->resource_id() == saved_root_resource_id) {
root_.reset(entry->AsDriveDirectory());
DCHECK(root_.get());
AddEntryToResourceMap(root_.get());
@@ -804,6 +809,8 @@ bool DriveResourceMetadata::ParseFromString(
}
root_->FromProto(proto.drive_directory());
+ // Root resource ID is already set from proto.
satorux1 2012/10/29 05:28:35 Maybe: // Call AddEntryToResourceMap() instead of
kochi 2012/10/29 05:52:39 Thanks for clarification. Applied.
+ AddEntryToResourceMap(root_.get());
origin_ = INITIALIZED;
largest_changestamp_ = proto.largest_changestamp();

Powered by Google App Engine
This is Rietveld 408576698