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

Side by Side Diff: components/drive/chromeos/change_list_processor.cc

Issue 2799603002: Process TeamDrive change in change list. (Closed)
Patch Set: Remove unnecessary return value, as the TeamDriveResource conversion always succeeds. 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 unified diff | Download patch
OLDNEW
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
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 << ", resource_id = " << deleted_resource_ids[i]; 340 << ", resource_id = " << deleted_resource_ids[i];
342 return error; 341 return error;
343 } 342 }
344 } 343 }
345 344
346 return FILE_ERROR_OK; 345 return FILE_ERROR_OK;
347 } 346 }
348 347
349 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { 348 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) {
350 DCHECK(!entry.deleted()); 349 DCHECK(!entry.deleted());
350 DCHECK(!entry.resource_id().empty());
351 DCHECK(parent_resource_id_map_.count(entry.resource_id())); 351 DCHECK(parent_resource_id_map_.count(entry.resource_id()));
352 const std::string& parent_resource_id = 352 const std::string& parent_resource_id =
353 parent_resource_id_map_[entry.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 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry,
357 parent_resource_id); 357 parent_resource_id);
358 if (error != FILE_ERROR_OK) 358 if (error != FILE_ERROR_OK)
359 return error; 359 return error;
360 360
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 out_refreshed_entries->push_back(result_entry); 458 out_refreshed_entries->push_back(result_entry);
459 } 459 }
460 return FILE_ERROR_OK; 460 return FILE_ERROR_OK;
461 } 461 }
462 462
463 // static 463 // static
464 FileError ChangeListProcessor::SetParentLocalIdOfEntry( 464 FileError ChangeListProcessor::SetParentLocalIdOfEntry(
465 ResourceMetadata* resource_metadata, 465 ResourceMetadata* resource_metadata,
466 ResourceEntry* entry, 466 ResourceEntry* entry,
467 const std::string& parent_resource_id) { 467 const std::string& parent_resource_id) {
468 if (entry->parent_local_id() == util::kDriveTeamDrivesDirLocalId) {
469 // When |entry| is a root directory of a Team Drive, the parent directory
470 // of it is "/team_drives", which doesn't have resource ID.
471 return FILE_ERROR_OK;
472 }
468 std::string parent_local_id; 473 std::string parent_local_id;
469 if (parent_resource_id.empty()) { 474 if (parent_resource_id.empty()) {
470 // Entries without parents should go under "other" directory. 475 // Entries without parents should go under "other" directory.
471 parent_local_id = util::kDriveOtherDirLocalId; 476 parent_local_id = util::kDriveOtherDirLocalId;
472 } else { 477 } else {
473 FileError error = resource_metadata->GetIdByResourceId( 478 FileError error = resource_metadata->GetIdByResourceId(
474 parent_resource_id, &parent_local_id); 479 parent_resource_id, &parent_local_id);
475 if (error != FILE_ERROR_OK) 480 if (error != FILE_ERROR_OK)
476 return error; 481 return error;
477 } 482 }
(...skipping 13 matching lines...) Expand all
491 if (!file_path.empty()) { 496 if (!file_path.empty()) {
492 FileChange::ChangeType type = entry.deleted() 497 FileChange::ChangeType type = entry.deleted()
493 ? FileChange::CHANGE_TYPE_DELETE 498 ? FileChange::CHANGE_TYPE_DELETE
494 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; 499 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE;
495 changed_files_->Update(file_path, entry, type); 500 changed_files_->Update(file_path, entry, type);
496 } 501 }
497 } 502 }
498 503
499 } // namespace internal 504 } // namespace internal
500 } // namespace drive 505 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/chromeos/change_list_processor.h ('k') | components/drive/file_system_core_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698