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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 70 } |
71 | 71 |
72 ChangeList::ChangeList() {} | 72 ChangeList::ChangeList() {} |
73 | 73 |
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 team_drives_.resize(items.size()); | |
80 parent_resource_ids_.resize(items.size()); | 81 parent_resource_ids_.resize(items.size()); |
81 size_t entries_index = 0; | 82 size_t entries_index = 0; |
83 size_t team_drives_index = 0; | |
82 for (size_t i = 0; i < items.size(); ++i) { | 84 for (size_t i = 0; i < items.size(); ++i) { |
83 if (ConvertChangeResourceToResourceEntry( | 85 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
| |
84 *items[i], | 86 if (ConvertChangeResourceToTeamDriveChange( |
85 &entries_[entries_index], | 87 *items[i], &team_drives_[team_drives_index])) { |
86 &parent_resource_ids_[entries_index])) { | 88 ++team_drives_index; |
89 } | |
90 } else if (ConvertChangeResourceToResourceEntry( | |
91 *items[i], &entries_[entries_index], | |
92 &parent_resource_ids_[entries_index])) { | |
87 ++entries_index; | 93 ++entries_index; |
88 } | 94 } |
89 } | 95 } |
90 entries_.resize(entries_index); | 96 entries_.resize(entries_index); |
97 team_drives_.resize(team_drives_index); | |
91 parent_resource_ids_.resize(entries_index); | 98 parent_resource_ids_.resize(entries_index); |
92 } | 99 } |
93 | 100 |
94 ChangeList::ChangeList(const google_apis::FileList& file_list) | 101 ChangeList::ChangeList(const google_apis::FileList& file_list) |
95 : next_url_(file_list.next_link()), | 102 : next_url_(file_list.next_link()), |
96 largest_changestamp_(0) { | 103 largest_changestamp_(0) { |
97 const std::vector<std::unique_ptr<google_apis::FileResource>>& items = | 104 const std::vector<std::unique_ptr<google_apis::FileResource>>& items = |
98 file_list.items(); | 105 file_list.items(); |
99 entries_.resize(items.size()); | 106 entries_.resize(items.size()); |
100 parent_resource_ids_.resize(items.size()); | 107 parent_resource_ids_.resize(items.size()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 149 |
143 DVLOG(1) << "Root folder ID is " << about_resource->root_folder_id(); | 150 DVLOG(1) << "Root folder ID is " << about_resource->root_folder_id(); |
144 DCHECK(!about_resource->root_folder_id().empty()); | 151 DCHECK(!about_resource->root_folder_id().empty()); |
145 } | 152 } |
146 | 153 |
147 // Convert ChangeList to map. | 154 // Convert ChangeList to map. |
148 ChangeListToEntryMapUMAStats uma_stats; | 155 ChangeListToEntryMapUMAStats uma_stats; |
149 for (size_t i = 0; i < change_lists.size(); ++i) { | 156 for (size_t i = 0; i < change_lists.size(); ++i) { |
150 ChangeList* change_list = change_lists[i].get(); | 157 ChangeList* change_list = change_lists[i].get(); |
151 | 158 |
159 const std::vector<TeamDriveChange>& team_drives = | |
160 change_list->team_drives(); | |
161 for (size_t i = 0; i < team_drives.size(); ++i) { | |
162 ApplyTeamDriveChange(team_drives.at(i)); | |
163 } | |
164 | |
152 std::vector<ResourceEntry>* entries = change_list->mutable_entries(); | 165 std::vector<ResourceEntry>* entries = change_list->mutable_entries(); |
153 for (size_t i = 0; i < entries->size(); ++i) { | 166 for (size_t i = 0; i < entries->size(); ++i) { |
154 ResourceEntry* entry = &(*entries)[i]; | 167 ResourceEntry* entry = &(*entries)[i]; |
155 | 168 |
156 // Count the number of files. | 169 // Count the number of files. |
157 if (!entry->file_info().is_directory()) { | 170 if (!entry->file_info().is_directory()) { |
158 uma_stats.IncrementNumFiles( | 171 uma_stats.IncrementNumFiles( |
159 entry->file_specific_info().is_hosted_document()); | 172 entry->file_specific_info().is_hosted_document()); |
160 } | 173 } |
161 parent_resource_id_map_[entry->resource_id()] = | 174 parent_resource_id_map_[entry->resource_id()] = |
(...skipping 27 matching lines...) Expand all Loading... | |
189 return error; | 202 return error; |
190 } | 203 } |
191 | 204 |
192 // Shouldn't record histograms when processing delta update. | 205 // Shouldn't record histograms when processing delta update. |
193 if (!is_delta_update) | 206 if (!is_delta_update) |
194 uma_stats.UpdateFileCountUmaHistograms(); | 207 uma_stats.UpdateFileCountUmaHistograms(); |
195 | 208 |
196 return FILE_ERROR_OK; | 209 return FILE_ERROR_OK; |
197 } | 210 } |
198 | 211 |
212 FileError ChangeListProcessor::ApplyTeamDriveChange( | |
213 const TeamDriveChange& change) { | |
214 ResourceEntry entry; | |
215 FileError error = | |
216 resource_metadata_->GetResourceEntryById(change.id(), &entry); | |
217 if (error == FILE_ERROR_OK) { | |
218 return resource_metadata_->RefreshTeamDrive(change.id(), change.name()); | |
219 } | |
220 if (error == FILE_ERROR_NOT_FOUND) { | |
221 return resource_metadata_->AddTeamDrive(change.id(), change.name()); | |
222 } | |
223 return error; | |
224 } | |
225 | |
199 FileError ChangeListProcessor::ApplyEntryMap( | 226 FileError ChangeListProcessor::ApplyEntryMap( |
200 int64_t changestamp, | 227 int64_t changestamp, |
201 std::unique_ptr<google_apis::AboutResource> about_resource) { | 228 std::unique_ptr<google_apis::AboutResource> about_resource) { |
202 DCHECK(about_resource); | 229 DCHECK(about_resource); |
203 | 230 |
204 // Create the entry for "My Drive" directory with the latest changestamp. | 231 // Create the entry for "My Drive" directory with the latest changestamp. |
205 ResourceEntry root; | 232 ResourceEntry root; |
206 FileError error = resource_metadata_->GetResourceEntryByPath( | 233 FileError error = resource_metadata_->GetResourceEntryByPath( |
207 util::GetDriveMyDriveRootPath(), &root); | 234 util::GetDriveMyDriveRootPath(), &root); |
208 if (error != FILE_ERROR_OK) { | 235 if (error != FILE_ERROR_OK) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 } | 328 } |
302 } | 329 } |
303 it = it_parent; | 330 it = it_parent; |
304 } | 331 } |
305 | 332 |
306 // Apply the parent first. | 333 // Apply the parent first. |
307 std::reverse(entries.begin(), entries.end()); | 334 std::reverse(entries.begin(), entries.end()); |
308 for (size_t i = 0; i < entries.size(); ++i) { | 335 for (size_t i = 0; i < entries.size(); ++i) { |
309 // Skip root entry in the change list. We don't expect servers to send | 336 // 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). | 337 // root entry, but we should better be defensive (see crbug.com/297259). |
338 // TODO(yamaguchi): Apply this defensive logic to root directories of | |
339 // every Team Drive as well. | |
311 ResourceEntryMap::iterator it = entries[i]; | 340 ResourceEntryMap::iterator it = entries[i]; |
312 if (it->first != root.resource_id()) { | 341 if (it->first != root.resource_id()) { |
313 FileError error = ApplyEntry(it->second); | 342 FileError error = ApplyEntry(it->second); |
314 if (error != FILE_ERROR_OK) { | 343 if (error != FILE_ERROR_OK) { |
315 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) | 344 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) |
316 << ", title = " << it->second.title(); | 345 << ", title = " << it->second.title(); |
317 return error; | 346 return error; |
318 } | 347 } |
319 } | 348 } |
320 entry_map_.erase(it); | 349 entry_map_.erase(it); |
(...skipping 20 matching lines...) Expand all Loading... | |
341 << ", resource_id = " << deleted_resource_ids[i]; | 370 << ", resource_id = " << deleted_resource_ids[i]; |
342 return error; | 371 return error; |
343 } | 372 } |
344 } | 373 } |
345 | 374 |
346 return FILE_ERROR_OK; | 375 return FILE_ERROR_OK; |
347 } | 376 } |
348 | 377 |
349 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { | 378 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { |
350 DCHECK(!entry.deleted()); | 379 DCHECK(!entry.deleted()); |
380 DCHECK(!entry.resource_id().empty()); | |
351 DCHECK(parent_resource_id_map_.count(entry.resource_id())); | 381 DCHECK(parent_resource_id_map_.count(entry.resource_id())); |
352 const std::string& parent_resource_id = | 382 const std::string& parent_resource_id = |
353 parent_resource_id_map_[entry.resource_id()]; | 383 parent_resource_id_map_[entry.resource_id()]; |
354 | 384 |
355 ResourceEntry new_entry(entry); | 385 ResourceEntry new_entry(entry); |
356 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, | 386 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, |
357 parent_resource_id); | 387 parent_resource_id); |
358 if (error != FILE_ERROR_OK) | 388 if (error != FILE_ERROR_OK) |
359 return error; | 389 return error; |
360 | 390 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 if (!file_path.empty()) { | 521 if (!file_path.empty()) { |
492 FileChange::ChangeType type = entry.deleted() | 522 FileChange::ChangeType type = entry.deleted() |
493 ? FileChange::CHANGE_TYPE_DELETE | 523 ? FileChange::CHANGE_TYPE_DELETE |
494 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; | 524 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; |
495 changed_files_->Update(file_path, entry, type); | 525 changed_files_->Update(file_path, entry, type); |
496 } | 526 } |
497 } | 527 } |
498 | 528 |
499 } // namespace internal | 529 } // namespace internal |
500 } // namespace drive | 530 } // namespace drive |
OLD | NEW |