| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 base::ThreadTaskRunnerHandle::Get()->PostTask( | 541 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 542 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION, | 542 FROM_HERE, base::Bind(callback, DRIVE_NO_CONNECTION, |
| 543 base::Passed(std::unique_ptr<FileResource>()))); | 543 base::Passed(std::unique_ptr<FileResource>()))); |
| 544 return CancelCallback(); | 544 return CancelCallback(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 EntryInfo* entry = FindEntryByResourceId(resource_id); | 547 EntryInfo* entry = FindEntryByResourceId(resource_id); |
| 548 if (entry && entry->change_resource.file()) { | 548 if (entry && entry->change_resource.file()) { |
| 549 base::ThreadTaskRunnerHandle::Get()->PostTask( | 549 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 550 FROM_HERE, base::Bind(callback, HTTP_SUCCESS, | 550 FROM_HERE, base::Bind(callback, HTTP_SUCCESS, |
| 551 base::Passed(base::WrapUnique(new FileResource( | 551 base::Passed(base::MakeUnique<FileResource>( |
| 552 *entry->change_resource.file()))))); | 552 *entry->change_resource.file())))); |
| 553 return CancelCallback(); | 553 return CancelCallback(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 base::ThreadTaskRunnerHandle::Get()->PostTask( | 556 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 557 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, | 557 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, |
| 558 base::Passed(std::unique_ptr<FileResource>()))); | 558 base::Passed(std::unique_ptr<FileResource>()))); |
| 559 return CancelCallback(); | 559 return CancelCallback(); |
| 560 } | 560 } |
| 561 | 561 |
| 562 CancelCallback FakeDriveService::GetShareUrl( | 562 CancelCallback FakeDriveService::GetShareUrl( |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, | 829 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, |
| 830 base::Passed(std::unique_ptr<FileResource>()))); | 830 base::Passed(std::unique_ptr<FileResource>()))); |
| 831 return CancelCallback(); | 831 return CancelCallback(); |
| 832 } | 832 } |
| 833 | 833 |
| 834 // Make a copy and set the new resource ID and the new title. | 834 // Make a copy and set the new resource ID and the new title. |
| 835 std::unique_ptr<EntryInfo> copied_entry(new EntryInfo); | 835 std::unique_ptr<EntryInfo> copied_entry(new EntryInfo); |
| 836 copied_entry->content_data = entry->content_data; | 836 copied_entry->content_data = entry->content_data; |
| 837 copied_entry->share_url = entry->share_url; | 837 copied_entry->share_url = entry->share_url; |
| 838 copied_entry->change_resource.set_file( | 838 copied_entry->change_resource.set_file( |
| 839 base::WrapUnique(new FileResource(*entry->change_resource.file()))); | 839 base::MakeUnique<FileResource>(*entry->change_resource.file())); |
| 840 | 840 |
| 841 ChangeResource* new_change = &copied_entry->change_resource; | 841 ChangeResource* new_change = &copied_entry->change_resource; |
| 842 FileResource* new_file = new_change->mutable_file(); | 842 FileResource* new_file = new_change->mutable_file(); |
| 843 const std::string new_resource_id = GetNewResourceId(); | 843 const std::string new_resource_id = GetNewResourceId(); |
| 844 new_change->set_file_id(new_resource_id); | 844 new_change->set_file_id(new_resource_id); |
| 845 new_file->set_file_id(new_resource_id); | 845 new_file->set_file_id(new_resource_id); |
| 846 new_file->set_title(new_title); | 846 new_file->set_title(new_title); |
| 847 | 847 |
| 848 ParentReference parent; | 848 ParentReference parent; |
| 849 parent.set_file_id(parent_resource_id); | 849 parent.set_file_id(parent_resource_id); |
| 850 std::vector<ParentReference> parents; | 850 std::vector<ParentReference> parents; |
| 851 parents.push_back(parent); | 851 parents.push_back(parent); |
| 852 *new_file->mutable_parents() = parents; | 852 *new_file->mutable_parents() = parents; |
| 853 | 853 |
| 854 if (!last_modified.is_null()) | 854 if (!last_modified.is_null()) |
| 855 new_file->set_modified_date(last_modified); | 855 new_file->set_modified_date(last_modified); |
| 856 | 856 |
| 857 AddNewChangestamp(new_change); | 857 AddNewChangestamp(new_change); |
| 858 UpdateETag(new_file); | 858 UpdateETag(new_file); |
| 859 | 859 |
| 860 // Add the new entry to the map. | 860 // Add the new entry to the map. |
| 861 entries_[new_resource_id] = copied_entry.release(); | 861 entries_[new_resource_id] = copied_entry.release(); |
| 862 | 862 |
| 863 base::ThreadTaskRunnerHandle::Get()->PostTask( | 863 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 864 FROM_HERE, | 864 FROM_HERE, |
| 865 base::Bind(callback, HTTP_SUCCESS, | 865 base::Bind(callback, HTTP_SUCCESS, |
| 866 base::Passed(base::WrapUnique(new FileResource(*new_file))))); | 866 base::Passed(base::MakeUnique<FileResource>(*new_file)))); |
| 867 base::ThreadTaskRunnerHandle::Get()->PostTask( | 867 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 868 FROM_HERE, | 868 FROM_HERE, |
| 869 base::Bind(&FakeDriveService::NotifyObservers, | 869 base::Bind(&FakeDriveService::NotifyObservers, |
| 870 weak_ptr_factory_.GetWeakPtr())); | 870 weak_ptr_factory_.GetWeakPtr())); |
| 871 return CancelCallback(); | 871 return CancelCallback(); |
| 872 } | 872 } |
| 873 | 873 |
| 874 CancelCallback FakeDriveService::UpdateResource( | 874 CancelCallback FakeDriveService::UpdateResource( |
| 875 const std::string& resource_id, | 875 const std::string& resource_id, |
| 876 const std::string& parent_resource_id, | 876 const std::string& parent_resource_id, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 | 925 |
| 926 if (!last_viewed_by_me.is_null()) | 926 if (!last_viewed_by_me.is_null()) |
| 927 file->set_last_viewed_by_me_date(last_viewed_by_me); | 927 file->set_last_viewed_by_me_date(last_viewed_by_me); |
| 928 | 928 |
| 929 AddNewChangestamp(change); | 929 AddNewChangestamp(change); |
| 930 UpdateETag(file); | 930 UpdateETag(file); |
| 931 | 931 |
| 932 base::ThreadTaskRunnerHandle::Get()->PostTask( | 932 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 933 FROM_HERE, | 933 FROM_HERE, |
| 934 base::Bind(callback, HTTP_SUCCESS, | 934 base::Bind(callback, HTTP_SUCCESS, |
| 935 base::Passed(base::WrapUnique(new FileResource(*file))))); | 935 base::Passed(base::MakeUnique<FileResource>(*file)))); |
| 936 base::ThreadTaskRunnerHandle::Get()->PostTask( | 936 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 937 FROM_HERE, | 937 FROM_HERE, |
| 938 base::Bind(&FakeDriveService::NotifyObservers, | 938 base::Bind(&FakeDriveService::NotifyObservers, |
| 939 weak_ptr_factory_.GetWeakPtr())); | 939 weak_ptr_factory_.GetWeakPtr())); |
| 940 return CancelCallback(); | 940 return CancelCallback(); |
| 941 } | 941 } |
| 942 | 942 |
| 943 CancelCallback FakeDriveService::AddResourceToDirectory( | 943 CancelCallback FakeDriveService::AddResourceToDirectory( |
| 944 const std::string& parent_resource_id, | 944 const std::string& parent_resource_id, |
| 945 const std::string& resource_id, | 945 const std::string& resource_id, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 session->parent_resource_id, | 1212 session->parent_resource_id, |
| 1213 session->title, | 1213 session->title, |
| 1214 false); // shared_with_me | 1214 false); // shared_with_me |
| 1215 if (!new_entry) { | 1215 if (!new_entry) { |
| 1216 completion_callback.Run(HTTP_NOT_FOUND, std::unique_ptr<FileResource>()); | 1216 completion_callback.Run(HTTP_NOT_FOUND, std::unique_ptr<FileResource>()); |
| 1217 return CancelCallback(); | 1217 return CancelCallback(); |
| 1218 } | 1218 } |
| 1219 | 1219 |
| 1220 completion_callback.Run( | 1220 completion_callback.Run( |
| 1221 HTTP_CREATED, | 1221 HTTP_CREATED, |
| 1222 base::WrapUnique(new FileResource(*new_entry->change_resource.file()))); | 1222 base::MakeUnique<FileResource>(*new_entry->change_resource.file())); |
| 1223 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1223 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1224 FROM_HERE, | 1224 FROM_HERE, |
| 1225 base::Bind(&FakeDriveService::NotifyObservers, | 1225 base::Bind(&FakeDriveService::NotifyObservers, |
| 1226 weak_ptr_factory_.GetWeakPtr())); | 1226 weak_ptr_factory_.GetWeakPtr())); |
| 1227 return CancelCallback(); | 1227 return CancelCallback(); |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 EntryInfo* entry = FindEntryByResourceId(session->resource_id); | 1230 EntryInfo* entry = FindEntryByResourceId(session->resource_id); |
| 1231 if (!entry) { | 1231 if (!entry) { |
| 1232 completion_callback.Run(HTTP_NOT_FOUND, std::unique_ptr<FileResource>()); | 1232 completion_callback.Run(HTTP_NOT_FOUND, std::unique_ptr<FileResource>()); |
| 1233 return CancelCallback(); | 1233 return CancelCallback(); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 ChangeResource* change = &entry->change_resource; | 1236 ChangeResource* change = &entry->change_resource; |
| 1237 FileResource* file = change->mutable_file(); | 1237 FileResource* file = change->mutable_file(); |
| 1238 if (file->etag().empty() || session->etag != file->etag()) { | 1238 if (file->etag().empty() || session->etag != file->etag()) { |
| 1239 completion_callback.Run(HTTP_PRECONDITION, std::unique_ptr<FileResource>()); | 1239 completion_callback.Run(HTTP_PRECONDITION, std::unique_ptr<FileResource>()); |
| 1240 return CancelCallback(); | 1240 return CancelCallback(); |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 file->set_md5_checksum(base::MD5String(content_data)); | 1243 file->set_md5_checksum(base::MD5String(content_data)); |
| 1244 entry->content_data = content_data; | 1244 entry->content_data = content_data; |
| 1245 file->set_file_size(end_position); | 1245 file->set_file_size(end_position); |
| 1246 AddNewChangestamp(change); | 1246 AddNewChangestamp(change); |
| 1247 UpdateETag(file); | 1247 UpdateETag(file); |
| 1248 | 1248 |
| 1249 completion_callback.Run(HTTP_SUCCESS, | 1249 completion_callback.Run(HTTP_SUCCESS, base::MakeUnique<FileResource>(*file)); |
| 1250 base::WrapUnique(new FileResource(*file))); | |
| 1251 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1250 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1252 FROM_HERE, | 1251 FROM_HERE, |
| 1253 base::Bind(&FakeDriveService::NotifyObservers, | 1252 base::Bind(&FakeDriveService::NotifyObservers, |
| 1254 weak_ptr_factory_.GetWeakPtr())); | 1253 weak_ptr_factory_.GetWeakPtr())); |
| 1255 return CancelCallback(); | 1254 return CancelCallback(); |
| 1256 } | 1255 } |
| 1257 | 1256 |
| 1258 CancelCallback FakeDriveService::MultipartUploadNewFile( | 1257 CancelCallback FakeDriveService::MultipartUploadNewFile( |
| 1259 const std::string& content_type, | 1258 const std::string& content_type, |
| 1260 int64_t content_length, | 1259 int64_t content_length, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 shared_with_me); | 1401 shared_with_me); |
| 1403 if (!new_entry) { | 1402 if (!new_entry) { |
| 1404 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1403 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1405 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, | 1404 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND, |
| 1406 base::Passed(std::unique_ptr<FileResource>()))); | 1405 base::Passed(std::unique_ptr<FileResource>()))); |
| 1407 return; | 1406 return; |
| 1408 } | 1407 } |
| 1409 | 1408 |
| 1410 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1409 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1411 FROM_HERE, base::Bind(callback, HTTP_CREATED, | 1410 FROM_HERE, base::Bind(callback, HTTP_CREATED, |
| 1412 base::Passed(base::WrapUnique(new FileResource( | 1411 base::Passed(base::MakeUnique<FileResource>( |
| 1413 *new_entry->change_resource.file()))))); | 1412 *new_entry->change_resource.file())))); |
| 1414 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1413 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1415 FROM_HERE, | 1414 FROM_HERE, |
| 1416 base::Bind(&FakeDriveService::NotifyObservers, | 1415 base::Bind(&FakeDriveService::NotifyObservers, |
| 1417 weak_ptr_factory_.GetWeakPtr())); | 1416 weak_ptr_factory_.GetWeakPtr())); |
| 1418 } | 1417 } |
| 1419 | 1418 |
| 1420 CancelCallback FakeDriveService::AddNewDirectoryWithResourceId( | 1419 CancelCallback FakeDriveService::AddNewDirectoryWithResourceId( |
| 1421 const std::string& resource_id, | 1420 const std::string& resource_id, |
| 1422 const std::string& parent_resource_id, | 1421 const std::string& parent_resource_id, |
| 1423 const std::string& directory_title, | 1422 const std::string& directory_title, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1446 return CancelCallback(); | 1445 return CancelCallback(); |
| 1447 } | 1446 } |
| 1448 | 1447 |
| 1449 const google_apis::DriveApiErrorCode result = | 1448 const google_apis::DriveApiErrorCode result = |
| 1450 SetFileVisibility(new_entry->change_resource.file_id(), | 1449 SetFileVisibility(new_entry->change_resource.file_id(), |
| 1451 options.visibility); | 1450 options.visibility); |
| 1452 DCHECK_EQ(HTTP_SUCCESS, result); | 1451 DCHECK_EQ(HTTP_SUCCESS, result); |
| 1453 | 1452 |
| 1454 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1453 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1455 FROM_HERE, base::Bind(callback, HTTP_CREATED, | 1454 FROM_HERE, base::Bind(callback, HTTP_CREATED, |
| 1456 base::Passed(base::WrapUnique(new FileResource( | 1455 base::Passed(base::MakeUnique<FileResource>( |
| 1457 *new_entry->change_resource.file()))))); | 1456 *new_entry->change_resource.file())))); |
| 1458 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1457 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1459 FROM_HERE, | 1458 FROM_HERE, |
| 1460 base::Bind(&FakeDriveService::NotifyObservers, | 1459 base::Bind(&FakeDriveService::NotifyObservers, |
| 1461 weak_ptr_factory_.GetWeakPtr())); | 1460 weak_ptr_factory_.GetWeakPtr())); |
| 1462 return CancelCallback(); | 1461 return CancelCallback(); |
| 1463 } | 1462 } |
| 1464 | 1463 |
| 1465 void FakeDriveService::SetLastModifiedTime( | 1464 void FakeDriveService::SetLastModifiedTime( |
| 1466 const std::string& resource_id, | 1465 const std::string& resource_id, |
| 1467 const base::Time& last_modified_time, | 1466 const base::Time& last_modified_time, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1484 return; | 1483 return; |
| 1485 } | 1484 } |
| 1486 | 1485 |
| 1487 ChangeResource* change = &entry->change_resource; | 1486 ChangeResource* change = &entry->change_resource; |
| 1488 FileResource* file = change->mutable_file(); | 1487 FileResource* file = change->mutable_file(); |
| 1489 file->set_modified_date(last_modified_time); | 1488 file->set_modified_date(last_modified_time); |
| 1490 | 1489 |
| 1491 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1490 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1492 FROM_HERE, | 1491 FROM_HERE, |
| 1493 base::Bind(callback, HTTP_SUCCESS, | 1492 base::Bind(callback, HTTP_SUCCESS, |
| 1494 base::Passed(base::WrapUnique(new FileResource(*file))))); | 1493 base::Passed(base::MakeUnique<FileResource>(*file)))); |
| 1495 } | 1494 } |
| 1496 | 1495 |
| 1497 google_apis::DriveApiErrorCode FakeDriveService::SetUserPermission( | 1496 google_apis::DriveApiErrorCode FakeDriveService::SetUserPermission( |
| 1498 const std::string& resource_id, | 1497 const std::string& resource_id, |
| 1499 google_apis::drive::PermissionRole user_permission) { | 1498 google_apis::drive::PermissionRole user_permission) { |
| 1500 DCHECK(thread_checker_.CalledOnValidThread()); | 1499 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1501 | 1500 |
| 1502 EntryInfo* entry = FindEntryByResourceId(resource_id); | 1501 EntryInfo* entry = FindEntryByResourceId(resource_id); |
| 1503 if (!entry) | 1502 if (!entry) |
| 1504 return HTTP_NOT_FOUND; | 1503 return HTTP_NOT_FOUND; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 // already incremented. | 1711 // already incremented. |
| 1713 if (start_offset > 0 && num_entries_matched <= start_offset) | 1712 if (start_offset > 0 && num_entries_matched <= start_offset) |
| 1714 should_exclude = true; | 1713 should_exclude = true; |
| 1715 | 1714 |
| 1716 if (!should_exclude) { | 1715 if (!should_exclude) { |
| 1717 std::unique_ptr<ChangeResource> entry_copied(new ChangeResource); | 1716 std::unique_ptr<ChangeResource> entry_copied(new ChangeResource); |
| 1718 entry_copied->set_change_id(entry.change_id()); | 1717 entry_copied->set_change_id(entry.change_id()); |
| 1719 entry_copied->set_file_id(entry.file_id()); | 1718 entry_copied->set_file_id(entry.file_id()); |
| 1720 entry_copied->set_deleted(entry.is_deleted()); | 1719 entry_copied->set_deleted(entry.is_deleted()); |
| 1721 if (entry.file()) { | 1720 if (entry.file()) { |
| 1722 entry_copied->set_file( | 1721 entry_copied->set_file(base::MakeUnique<FileResource>(*entry.file())); |
| 1723 base::WrapUnique(new FileResource(*entry.file()))); | |
| 1724 } | 1722 } |
| 1725 entry_copied->set_modification_date(entry.modification_date()); | 1723 entry_copied->set_modification_date(entry.modification_date()); |
| 1726 entries.push_back(entry_copied.release()); | 1724 entries.push_back(entry_copied.release()); |
| 1727 } | 1725 } |
| 1728 } | 1726 } |
| 1729 | 1727 |
| 1730 std::unique_ptr<ChangeList> change_list(new ChangeList); | 1728 std::unique_ptr<ChangeList> change_list(new ChangeList); |
| 1731 if (start_changestamp > 0 && start_offset == 0) { | 1729 if (start_changestamp > 0 && start_offset == 0) { |
| 1732 change_list->set_largest_change_id(about_resource_->largest_change_id()); | 1730 change_list->set_largest_change_id(about_resource_->largest_change_id()); |
| 1733 } | 1731 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 | 1790 |
| 1793 NOTREACHED(); | 1791 NOTREACHED(); |
| 1794 return std::unique_ptr<BatchRequestConfiguratorInterface>(); | 1792 return std::unique_ptr<BatchRequestConfiguratorInterface>(); |
| 1795 } | 1793 } |
| 1796 | 1794 |
| 1797 void FakeDriveService::NotifyObservers() { | 1795 void FakeDriveService::NotifyObservers() { |
| 1798 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); | 1796 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); |
| 1799 } | 1797 } |
| 1800 | 1798 |
| 1801 } // namespace drive | 1799 } // namespace drive |
| OLD | NEW |