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