| 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/service/fake_drive_service.h" | 5 #include "components/drive/service/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if (!change_list) { | 125 if (!change_list) { |
| 126 callback.Run(error, std::move(file_list)); | 126 callback.Run(error, std::move(file_list)); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 file_list.reset(new FileList); | 130 file_list.reset(new FileList); |
| 131 file_list->set_next_link(change_list->next_link()); | 131 file_list->set_next_link(change_list->next_link()); |
| 132 for (size_t i = 0; i < change_list->items().size(); ++i) { | 132 for (size_t i = 0; i < change_list->items().size(); ++i) { |
| 133 const ChangeResource& entry = *change_list->items()[i]; | 133 const ChangeResource& entry = *change_list->items()[i]; |
| 134 if (entry.file()) | 134 if (entry.file()) |
| 135 file_list->mutable_items()->push_back(new FileResource(*entry.file())); | 135 file_list->mutable_items()->push_back( |
| 136 base::MakeUnique<FileResource>(*entry.file())); |
| 136 } | 137 } |
| 137 callback.Run(error, std::move(file_list)); | 138 callback.Run(error, std::move(file_list)); |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool UserHasWriteAccess(google_apis::drive::PermissionRole user_permission) { | 141 bool UserHasWriteAccess(google_apis::drive::PermissionRole user_permission) { |
| 141 switch (user_permission) { | 142 switch (user_permission) { |
| 142 case google_apis::drive::PERMISSION_ROLE_OWNER: | 143 case google_apis::drive::PERMISSION_ROLE_OWNER: |
| 143 case google_apis::drive::PERMISSION_ROLE_WRITER: | 144 case google_apis::drive::PERMISSION_ROLE_WRITER: |
| 144 return true; | 145 return true; |
| 145 case google_apis::drive::PERMISSION_ROLE_READER: | 146 case google_apis::drive::PERMISSION_ROLE_READER: |
| (...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 const ChangeListCallback& callback) { | 1656 const ChangeListCallback& callback) { |
| 1656 if (offline_) { | 1657 if (offline_) { |
| 1657 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1658 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1658 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION, | 1659 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION, |
| 1659 base::Passed(std::unique_ptr<ChangeList>()))); | 1660 base::Passed(std::unique_ptr<ChangeList>()))); |
| 1660 return; | 1661 return; |
| 1661 } | 1662 } |
| 1662 | 1663 |
| 1663 // Filter out entries per parameters like |directory_resource_id| and | 1664 // Filter out entries per parameters like |directory_resource_id| and |
| 1664 // |search_query|. | 1665 // |search_query|. |
| 1665 ScopedVector<ChangeResource> entries; | 1666 std::vector<std::unique_ptr<ChangeResource>> entries; |
| 1666 int num_entries_matched = 0; | 1667 int num_entries_matched = 0; |
| 1667 for (auto it = entries_.begin(); it != entries_.end(); ++it) { | 1668 for (auto it = entries_.begin(); it != entries_.end(); ++it) { |
| 1668 const ChangeResource& entry = it->second->change_resource; | 1669 const ChangeResource& entry = it->second->change_resource; |
| 1669 bool should_exclude = false; | 1670 bool should_exclude = false; |
| 1670 | 1671 |
| 1671 // If |directory_resource_id| is set, exclude the entry if it's not in | 1672 // If |directory_resource_id| is set, exclude the entry if it's not in |
| 1672 // the target directory. | 1673 // the target directory. |
| 1673 if (!directory_resource_id.empty()) { | 1674 if (!directory_resource_id.empty()) { |
| 1674 // Get the parent resource ID of the entry. | 1675 // Get the parent resource ID of the entry. |
| 1675 std::string parent_resource_id; | 1676 std::string parent_resource_id; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 | 1714 |
| 1714 if (!should_exclude) { | 1715 if (!should_exclude) { |
| 1715 std::unique_ptr<ChangeResource> entry_copied(new ChangeResource); | 1716 std::unique_ptr<ChangeResource> entry_copied(new ChangeResource); |
| 1716 entry_copied->set_change_id(entry.change_id()); | 1717 entry_copied->set_change_id(entry.change_id()); |
| 1717 entry_copied->set_file_id(entry.file_id()); | 1718 entry_copied->set_file_id(entry.file_id()); |
| 1718 entry_copied->set_deleted(entry.is_deleted()); | 1719 entry_copied->set_deleted(entry.is_deleted()); |
| 1719 if (entry.file()) { | 1720 if (entry.file()) { |
| 1720 entry_copied->set_file(base::MakeUnique<FileResource>(*entry.file())); | 1721 entry_copied->set_file(base::MakeUnique<FileResource>(*entry.file())); |
| 1721 } | 1722 } |
| 1722 entry_copied->set_modification_date(entry.modification_date()); | 1723 entry_copied->set_modification_date(entry.modification_date()); |
| 1723 entries.push_back(entry_copied.release()); | 1724 entries.push_back(std::move(entry_copied)); |
| 1724 } | 1725 } |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 std::unique_ptr<ChangeList> change_list(new ChangeList); | 1728 std::unique_ptr<ChangeList> change_list(new ChangeList); |
| 1728 if (start_changestamp > 0 && start_offset == 0) { | 1729 if (start_changestamp > 0 && start_offset == 0) { |
| 1729 change_list->set_largest_change_id(about_resource_->largest_change_id()); | 1730 change_list->set_largest_change_id(about_resource_->largest_change_id()); |
| 1730 } | 1731 } |
| 1731 | 1732 |
| 1732 // If |max_results| is set, trim the entries if the number exceeded the max | 1733 // If |max_results| is set, trim the entries if the number exceeded the max |
| 1733 // results. | 1734 // results. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 NOTREACHED(); | 1791 NOTREACHED(); |
| 1791 return std::unique_ptr<BatchRequestConfiguratorInterface>(); | 1792 return std::unique_ptr<BatchRequestConfiguratorInterface>(); |
| 1792 } | 1793 } |
| 1793 | 1794 |
| 1794 void FakeDriveService::NotifyObservers() { | 1795 void FakeDriveService::NotifyObservers() { |
| 1795 for (auto& observer : change_observers_) | 1796 for (auto& observer : change_observers_) |
| 1796 observer.OnNewChangeAvailable(); | 1797 observer.OnNewChangeAvailable(); |
| 1797 } | 1798 } |
| 1798 | 1799 |
| 1799 } // namespace drive | 1800 } // namespace drive |
| OLD | NEW |