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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/synchronization/cancellation_flag.h" | 15 #include "base/synchronization/cancellation_flag.h" |
| 16 #include "components/drive/chromeos/resource_metadata.h" | 16 #include "components/drive/chromeos/resource_metadata.h" |
| 17 #include "components/drive/drive.pb.h" | 17 #include "components/drive/drive.pb.h" |
| 18 #include "components/drive/drive_api_util.h" | 18 #include "components/drive/drive_api_util.h" |
| 19 #include "components/drive/file_change.h" | 19 #include "components/drive/file_change.h" |
| 20 #include "components/drive/file_system_core_util.h" | 20 #include "components/drive/file_system_core_util.h" |
| 21 #include "components/drive/resource_entry_conversion.h" | 21 #include "components/drive/resource_entry_conversion.h" |
| 22 #include "google_apis/drive/drive_api_parser.h" | 22 #include "google_apis/drive/drive_api_parser.h" |
| 23 #include "google_apis/drive/drive_switches.h" | |
|
hashimoto
2017/04/10 11:01:24
No longer needed.
yamaguchi
2017/04/11 07:08:07
Done.
| |
| 23 | 24 |
| 24 namespace drive { | 25 namespace drive { |
| 25 namespace internal { | 26 namespace internal { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class ChangeListToEntryMapUMAStats { | 30 class ChangeListToEntryMapUMAStats { |
| 30 public: | 31 public: |
| 31 ChangeListToEntryMapUMAStats() | 32 ChangeListToEntryMapUMAStats() |
| 32 : num_regular_files_(0), | 33 : num_regular_files_(0), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 ChangeList::ChangeList(const google_apis::ChangeList& change_list) | 75 ChangeList::ChangeList(const google_apis::ChangeList& change_list) |
| 75 : next_url_(change_list.next_link()), | 76 : next_url_(change_list.next_link()), |
| 76 largest_changestamp_(change_list.largest_change_id()) { | 77 largest_changestamp_(change_list.largest_change_id()) { |
| 77 const std::vector<std::unique_ptr<google_apis::ChangeResource>>& items = | 78 const std::vector<std::unique_ptr<google_apis::ChangeResource>>& items = |
| 78 change_list.items(); | 79 change_list.items(); |
| 79 entries_.resize(items.size()); | 80 entries_.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; |
| 82 for (size_t i = 0; i < items.size(); ++i) { | 83 for (size_t i = 0; i < items.size(); ++i) { |
| 83 if (ConvertChangeResourceToResourceEntry( | 84 if (ConvertChangeResourceToResourceEntry( |
| 84 *items[i], | 85 *items[i], &entries_[entries_index], |
| 85 &entries_[entries_index], | |
| 86 &parent_resource_ids_[entries_index])) { | 86 &parent_resource_ids_[entries_index])) { |
| 87 ++entries_index; | 87 ++entries_index; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 entries_.resize(entries_index); | 90 entries_.resize(entries_index); |
| 91 parent_resource_ids_.resize(entries_index); | 91 parent_resource_ids_.resize(entries_index); |
| 92 } | 92 } |
| 93 | 93 |
| 94 ChangeList::ChangeList(const google_apis::FileList& file_list) | 94 ChangeList::ChangeList(const google_apis::FileList& file_list) |
| 95 : next_url_(file_list.next_link()), | 95 : next_url_(file_list.next_link()), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 it = it_parent; | 303 it = it_parent; |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Apply the parent first. | 306 // Apply the parent first. |
| 307 std::reverse(entries.begin(), entries.end()); | 307 std::reverse(entries.begin(), entries.end()); |
| 308 for (size_t i = 0; i < entries.size(); ++i) { | 308 for (size_t i = 0; i < entries.size(); ++i) { |
| 309 // Skip root entry in the change list. We don't expect servers to send | 309 // 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). | 310 // root entry, but we should better be defensive (see crbug.com/297259). |
| 311 // TODO(yamaguchi): Apply this defensive logic to root directories of | |
|
hashimoto
2017/04/10 11:01:24
Why do you need to do this?
yamaguchi
2017/04/11 07:08:07
According to crbug.com/297259, the root directory
hashimoto
2017/04/11 07:55:14
We are doing this for My Drive root because the sa
| |
| 312 // every Team Drive as well. | |
| 311 ResourceEntryMap::iterator it = entries[i]; | 313 ResourceEntryMap::iterator it = entries[i]; |
| 312 if (it->first != root.resource_id()) { | 314 if (it->first != root.resource_id()) { |
| 313 FileError error = ApplyEntry(it->second); | 315 FileError error = ApplyEntry(it->second); |
| 314 if (error != FILE_ERROR_OK) { | 316 if (error != FILE_ERROR_OK) { |
| 315 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) | 317 LOG(ERROR) << "ApplyEntry failed: " << FileErrorToString(error) |
| 316 << ", title = " << it->second.title(); | 318 << ", title = " << it->second.title(); |
| 317 return error; | 319 return error; |
| 318 } | 320 } |
| 319 } | 321 } |
| 320 entry_map_.erase(it); | 322 entry_map_.erase(it); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 341 << ", resource_id = " << deleted_resource_ids[i]; | 343 << ", resource_id = " << deleted_resource_ids[i]; |
| 342 return error; | 344 return error; |
| 343 } | 345 } |
| 344 } | 346 } |
| 345 | 347 |
| 346 return FILE_ERROR_OK; | 348 return FILE_ERROR_OK; |
| 347 } | 349 } |
| 348 | 350 |
| 349 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { | 351 FileError ChangeListProcessor::ApplyEntry(const ResourceEntry& entry) { |
| 350 DCHECK(!entry.deleted()); | 352 DCHECK(!entry.deleted()); |
| 353 DCHECK(!entry.resource_id().empty()); | |
| 351 DCHECK(parent_resource_id_map_.count(entry.resource_id())); | 354 DCHECK(parent_resource_id_map_.count(entry.resource_id())); |
| 352 const std::string& parent_resource_id = | 355 const std::string& parent_resource_id = |
| 353 parent_resource_id_map_[entry.resource_id()]; | 356 parent_resource_id_map_[entry.resource_id()]; |
| 354 | 357 |
| 355 ResourceEntry new_entry(entry); | 358 ResourceEntry new_entry(entry); |
| 356 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, | 359 FileError error = SetParentLocalIdOfEntry(resource_metadata_, &new_entry, |
| 357 parent_resource_id); | 360 parent_resource_id); |
| 358 if (error != FILE_ERROR_OK) | 361 if (error != FILE_ERROR_OK) |
| 359 return error; | 362 return error; |
| 360 | 363 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 if (!file_path.empty()) { | 494 if (!file_path.empty()) { |
| 492 FileChange::ChangeType type = entry.deleted() | 495 FileChange::ChangeType type = entry.deleted() |
| 493 ? FileChange::CHANGE_TYPE_DELETE | 496 ? FileChange::CHANGE_TYPE_DELETE |
| 494 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; | 497 : FileChange::CHANGE_TYPE_ADD_OR_UPDATE; |
| 495 changed_files_->Update(file_path, entry, type); | 498 changed_files_->Update(file_path, entry, type); |
| 496 } | 499 } |
| 497 } | 500 } |
| 498 | 501 |
| 499 } // namespace internal | 502 } // namespace internal |
| 500 } // namespace drive | 503 } // namespace drive |
| OLD | NEW |