Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/drive/chromeos/change_list_processor.h" | 5 #include "components/drive/chromeos/change_list_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 ChangeList::ChangeList(const google_apis::ChangeList& change_list) | 74 ChangeList::ChangeList(const google_apis::ChangeList& change_list) |
| 75 : next_url_(change_list.next_link()), | 75 : next_url_(change_list.next_link()), |
| 76 largest_changestamp_(change_list.largest_change_id()) { | 76 largest_changestamp_(change_list.largest_change_id()) { |
| 77 const std::vector<std::unique_ptr<google_apis::ChangeResource>>& items = | 77 const std::vector<std::unique_ptr<google_apis::ChangeResource>>& items = |
| 78 change_list.items(); | 78 change_list.items(); |
| 79 entries_.resize(items.size()); | 79 entries_.resize(items.size()); |
| 80 parent_resource_ids_.resize(items.size()); | 80 parent_resource_ids_.resize(items.size()); |
| 81 size_t entries_index = 0; | 81 size_t entries_index = 0; |
| 82 for (size_t i = 0; i < items.size(); ++i) { | 82 for (size_t i = 0; i < items.size(); ++i) { |
| 83 if (ConvertChangeResourceToResourceEntry( | 83 if (ConvertChangeResourceToResourceEntry( |
| 84 *items[i], | 84 *items[i], &entries_[entries_index], |
| 85 &entries_[entries_index], | |
| 86 &parent_resource_ids_[entries_index])) { | 85 &parent_resource_ids_[entries_index])) { |
| 87 ++entries_index; | 86 ++entries_index; |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 entries_.resize(entries_index); | 89 entries_.resize(entries_index); |
| 91 parent_resource_ids_.resize(entries_index); | 90 parent_resource_ids_.resize(entries_index); |
| 92 } | 91 } |
| 93 | 92 |
| 94 ChangeList::ChangeList(const google_apis::FileList& file_list) | 93 ChangeList::ChangeList(const google_apis::FileList& file_list) |
| 95 : next_url_(file_list.next_link()), | 94 : next_url_(file_list.next_link()), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 } | 300 } |
| 302 } | 301 } |
| 303 it = it_parent; | 302 it = it_parent; |
| 304 } | 303 } |
| 305 | 304 |
| 306 // Apply the parent first. | 305 // Apply the parent first. |
| 307 std::reverse(entries.begin(), entries.end()); | 306 std::reverse(entries.begin(), entries.end()); |
| 308 for (size_t i = 0; i < entries.size(); ++i) { | 307 for (size_t i = 0; i < entries.size(); ++i) { |
| 309 // Skip root entry in the change list. We don't expect servers to send | 308 // Skip root entry in the change list. We don't expect servers to send |
| 310 // root entry, but we should better be defensive (see crbug.com/297259). | 309 // root entry, but we should better be defensive (see crbug.com/297259). |
| 310 // TODO(yamaguchi): Apply this defensive logic to root directories of | |
| 311 // every Team Drive as well. | |
| 311 ResourceEntryMap::iterator it = entries[i]; | 312 ResourceEntryMap::iterator it = entries[i]; |
| 312 if (it->first != root.resource_id()) { | 313 if (it->first != root.resource_id()) { |
| 313 FileError error = ApplyEntry(it->second); | 314 FileError error = ApplyEntry(it->second); |
| 314 if (error != FILE_ERROR_OK) { | 315 if (error != FILE_ERROR_OK) { |
| 315 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) | 316 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) |
| 316 << ", title = " << it->second.title(); | 317 << ", title = " << it->second.title(); |
| 317 return error; | 318 return error; |
| 318 } | 319 } |
| 319 } | 320 } |
| 320 entry_map_.erase(it); | 321 entry_map_.erase(it); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 341 << ", resource_id = " << deleted_resource_ids[i]; | 342 << ", resource_id = " << deleted_resource_ids[i]; |
| 342 return error; | 343 return error; |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 | 346 |
| 346 return FILE_ERROR_OK; | 347 return FILE_ERROR_OK; |
| 347 } | 348 } |
| 348 | 349 |
| 349 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { | 350 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { |
| 350 DCHECK(!entry.deleted()); | 351 DCHECK(!entry.deleted()); |
| 352 DCHECK(!entry.resource_id().empty()); | |
| 351 DCHECK(parent_resource_id_map_.count(entry.resource_id())); | 353 DCHECK(parent_resource_id_map_.count(entry.resource_id())); |
| 352 const std::string& parent_resource_id = | |
| 353 parent_resource_id_map_[entry.resource_id()]; | |
| 354 | 354 |
| 355 ResourceEntry new_entry(entry); | 355 ResourceEntry new_entry(entry); |
| 356 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, | 356 // When |entry| is a root directory of a Team Drive, the parent directory of |
| 357 parent_resource_id); | 357 // it is "/team_drives", which doesn't have resource ID. |
| 358 if (error != FILE_ERROR_OK) | 358 if (entry.parent_local_id().compare(util::kDriveTeamDrivesDirLocalId) != 0) { |
|
hashimoto
2017/04/11 07:55:14
entry.parent_local_id() != util::kDriveTeamDrivesD
yamaguchi
2017/04/11 10:11:41
Done.
| |
| 359 return error; | 359 const std::string& parent_resource_id = |
| 360 parent_resource_id_map_[entry.resource_id()]; | |
| 361 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, | |
| 362 parent_resource_id); | |
| 363 if (error != FILE_ERROR_OK) | |
| 364 return error; | |
| 365 } | |
| 360 | 366 |
| 361 // Lookup the entry. | 367 // Lookup the entry. |
| 362 std::string local_id; | 368 std::string local_id; |
| 363 error = resource_metadata_->GetIdByResourceId(entry.resource_id(), &local_id); | 369 FileError error = |
| 370 resource_metadata_->GetIdByResourceId(entry.resource_id(), &local_id); | |
| 364 | 371 |
| 365 ResourceEntry existing_entry; | 372 ResourceEntry existing_entry; |
| 366 if (error == FILE_ERROR_OK) | 373 if (error == FILE_ERROR_OK) |
| 367 error = resource_metadata_->GetResourceEntryById(local_id, &existing_entry); | 374 error = resource_metadata_->GetResourceEntryById(local_id, &existing_entry); |
| 368 | 375 |
| 369 switch (error) { | 376 switch (error) { |
| 370 case FILE_ERROR_OK: | 377 case FILE_ERROR_OK: |
| 371 if (ShouldApplyChange(existing_entry, new_entry)) { | 378 if (ShouldApplyChange(existing_entry, new_entry)) { |
| 372 // Entry exists and needs to be refreshed. | 379 // Entry exists and needs to be refreshed. |
| 373 new_entry.set_local_id(local_id); | 380 new_entry.set_local_id(local_id); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 466 } |
| 460 return FILE_ERROR_OK; | 467 return FILE_ERROR_OK; |
| 461 } | 468 } |
| 462 | 469 |
| 463 // static | 470 // static |
| 464 FileError ChangeListProcessor::SetParentLocalIdOfEntry( | 471 FileError ChangeListProcessor::SetParentLocalIdOfEntry( |
| 465 ResourceMetadata* resource_metadata, | 472 ResourceMetadata* resource_metadata, |
| 466 ResourceEntry* entry, | 473 ResourceEntry* entry, |
| 467 const std::string& parent_resource_id) { | 474 const std::string& parent_resource_id) { |
| 468 std::string parent_local_id; | 475 std::string parent_local_id; |
| 469 if (parent_resource_id.empty()) { | 476 if (parent_resource_id.empty()) { |
|
hashimoto
2017/04/11 07:55:14
Please merge the team drive handling logic to this
yamaguchi
2017/04/11 10:11:41
Done.
| |
| 470 // Entries without parents should go under "other" directory. | 477 // Entries without parents should go under "other" directory. |
| 471 parent_local_id = util::kDriveOtherDirLocalId; | 478 parent_local_id = util::kDriveOtherDirLocalId; |
| 472 } else { | 479 } else { |
| 473 FileError error = resource_metadata->GetIdByResourceId( | 480 FileError error = resource_metadata->GetIdByResourceId( |
| 474 parent_resource_id, &parent_local_id); | 481 parent_resource_id, &parent_local_id); |
| 475 if (error != FILE_ERROR_OK) | 482 if (error != FILE_ERROR_OK) |
| 476 return error; | 483 return error; |
| 477 } | 484 } |
| 478 entry->set_parent_local_id(parent_local_id); | 485 entry->set_parent_local_id(parent_local_id); |
| 479 return FILE_ERROR_OK; | 486 return FILE_ERROR_OK; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 491 if (!file_path.empty()) { | 498 if (!file_path.empty()) { |
| 492 FileChange::ChangeType type = entry.deleted() | 499 FileChange::ChangeType type = entry.deleted() |
| 493 ? FileChange::CHANGE_TYPE_DELETE | 500 ? FileChange::CHANGE_TYPE_DELETE |
| 494 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; | 501 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; |
| 495 changed_files_->Update(file_path, entry, type); | 502 changed_files_->Update(file_path, entry, type); |
| 496 } | 503 } |
| 497 } | 504 } |
| 498 | 505 |
| 499 } // namespace internal | 506 } // namespace internal |
| 500 } // namespace drive | 507 } // namespace drive |
| OLD | NEW |