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

Unified Diff: components/drive/chromeos/change_list_processor.cc

Issue 2799603002: Process TeamDrive change in change list. (Closed)
Patch Set: Add test for update. Created 3 years, 8 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: components/drive/chromeos/change_list_processor.cc
diff --git a/components/drive/chromeos/change_list_processor.cc b/components/drive/chromeos/change_list_processor.cc
index 3eb96bb1c81a47f9d7de103166f40b752d7b951f..6c3551d90f590786475c1c2417d6150e2d847a27 100644
--- a/components/drive/chromeos/change_list_processor.cc
+++ b/components/drive/chromeos/change_list_processor.cc
@@ -77,17 +77,24 @@ ChangeList::ChangeList(const google_apis::ChangeList& change_list)
const std::vector<std::unique_ptr<google_apis::ChangeResource>>& items =
change_list.items();
entries_.resize(items.size());
+ team_drives_.resize(items.size());
parent_resource_ids_.resize(items.size());
size_t entries_index = 0;
+ size_t team_drives_index = 0;
for (size_t i = 0; i < items.size(); ++i) {
- if (ConvertChangeResourceToResourceEntry(
- *items[i],
- &entries_[entries_index],
- &parent_resource_ids_[entries_index])) {
+ if (items[i]->type() == google_apis::ChangeResource::TEAM_DRIVE) {
hashimoto 2017/04/06 10:23:36 I think Team Drive change can be also converted to
yamaguchi 2017/04/07 03:57:43 Changed to directly convert to ResourceEntry. Howe
+ if (ConvertChangeResourceToTeamDriveChange(
+ *items[i], &team_drives_[team_drives_index])) {
+ ++team_drives_index;
+ }
+ } else if (ConvertChangeResourceToResourceEntry(
+ *items[i], &entries_[entries_index],
+ &parent_resource_ids_[entries_index])) {
++entries_index;
}
}
entries_.resize(entries_index);
+ team_drives_.resize(team_drives_index);
parent_resource_ids_.resize(entries_index);
}
@@ -149,6 +156,12 @@ FileError ChangeListProcessor::Apply(
for (size_t i = 0; i < change_lists.size(); ++i) {
ChangeList* change_list = change_lists[i].get();
+ const std::vector<TeamDriveChange>& team_drives =
+ change_list->team_drives();
+ for (size_t i = 0; i < team_drives.size(); ++i) {
+ ApplyTeamDriveChange(team_drives.at(i));
+ }
+
std::vector<ResourceEntry>* entries = change_list->mutable_entries();
for (size_t i = 0; i < entries->size(); ++i) {
ResourceEntry* entry = &(*entries)[i];
@@ -196,6 +209,20 @@ FileError ChangeListProcessor::Apply(
return FILE_ERROR_OK;
}
+FileError ChangeListProcessor::ApplyTeamDriveChange(
+ const TeamDriveChange& change) {
+ ResourceEntry entry;
+ FileError error =
+ resource_metadata_->GetResourceEntryById(change.id(), &entry);
+ if (error == FILE_ERROR_OK) {
+ return resource_metadata_->RefreshTeamDrive(change.id(), change.name());
+ }
+ if (error == FILE_ERROR_NOT_FOUND) {
+ return resource_metadata_->AddTeamDrive(change.id(), change.name());
+ }
+ return error;
+}
+
FileError ChangeListProcessor::ApplyEntryMap(
int64_t changestamp,
std::unique_ptr<google_apis::AboutResource> about_resource) {
@@ -308,6 +335,8 @@ FileError ChangeListProcessor::ApplyEntryMap(
for (size_t i = 0; i < entries.size(); ++i) {
// Skip root entry in the change list. We don't expect servers to send
// root entry, but we should better be defensive (see crbug.com/297259).
+ // TODO(yamaguchi): Apply this defensive logic to root directories of
+ // every Team Drive as well.
ResourceEntryMap::iterator it = entries[i];
if (it->first != root.resource_id()) {
FileError error = ApplyEntry(it->second);
@@ -348,6 +377,7 @@ FileError ChangeListProcessor::ApplyEntryMap(
FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) {
DCHECK(!entry.deleted());
+ DCHECK(!entry.resource_id().empty());
DCHECK(parent_resource_id_map_.count(entry.resource_id()));
const std::string& parent_resource_id =
parent_resource_id_map_[entry.resource_id()];

Powered by Google App Engine
This is Rietveld 408576698