Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: chrome/browser/drive/fake_drive_service.cc

Issue 216433002: drive: Make FileResource copyable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/drive/fake_drive_service.h" 5 #include "chrome/browser/drive/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 const std::string& parent_resource_id = in_parent_resource_id.empty() ? 718 const std::string& parent_resource_id = in_parent_resource_id.empty() ?
719 GetRootResourceId() : in_parent_resource_id; 719 GetRootResourceId() : in_parent_resource_id;
720 720
721 EntryInfo* entry = FindEntryByResourceId(resource_id); 721 EntryInfo* entry = FindEntryByResourceId(resource_id);
722 if (entry) { 722 if (entry) {
723 // Make a copy and set the new resource ID and the new title. 723 // Make a copy and set the new resource ID and the new title.
724 scoped_ptr<EntryInfo> copied_entry(new EntryInfo); 724 scoped_ptr<EntryInfo> copied_entry(new EntryInfo);
725 copied_entry->content_data = entry->content_data; 725 copied_entry->content_data = entry->content_data;
726 copied_entry->share_url = entry->share_url; 726 copied_entry->share_url = entry->share_url;
727
728 // TODO(hashimoto): Implement a proper way to copy FileResource.
729 scoped_ptr<ResourceEntry> copied_resource_entry =
730 util::ConvertChangeResourceToResourceEntry(entry->change_resource);
731 copied_entry->change_resource.set_file( 727 copied_entry->change_resource.set_file(
732 util::ConvertResourceEntryToFileResource(*copied_resource_entry)); 728 make_scoped_ptr(new FileResource(*entry->change_resource.file())));
733 729
734 ChangeResource* new_change = &copied_entry->change_resource; 730 ChangeResource* new_change = &copied_entry->change_resource;
735 FileResource* new_file = new_change->mutable_file(); 731 FileResource* new_file = new_change->mutable_file();
736 const std::string new_resource_id = GetNewResourceId(); 732 const std::string new_resource_id = GetNewResourceId();
737 new_change->set_file_id(new_resource_id); 733 new_change->set_file_id(new_resource_id);
738 new_file->set_file_id(new_resource_id); 734 new_file->set_file_id(new_resource_id);
739 new_file->set_title(new_title); 735 new_file->set_title(new_title);
740 736
741 scoped_ptr<ParentReference> parent(new ParentReference); 737 ParentReference parent;
742 parent->set_file_id(parent_resource_id); 738 parent.set_file_id(parent_resource_id);
743 parent->set_parent_link(GetFakeLinkUrl(parent_resource_id)); 739 parent.set_parent_link(GetFakeLinkUrl(parent_resource_id));
744 parent->set_is_root(parent_resource_id == GetRootResourceId()); 740 parent.set_is_root(parent_resource_id == GetRootResourceId());
745 ScopedVector<ParentReference> parents; 741 std::vector<ParentReference> parents;
746 parents.push_back(parent.release()); 742 parents.push_back(parent);
747 new_file->set_parents(parents.Pass()); 743 *new_file->mutable_parents() = parents;
748 744
749 if (!last_modified.is_null()) 745 if (!last_modified.is_null())
750 new_file->set_modified_date(last_modified); 746 new_file->set_modified_date(last_modified);
751 747
752 AddNewChangestamp(new_change); 748 AddNewChangestamp(new_change);
753 UpdateETag(new_file); 749 UpdateETag(new_file);
754 750
755 scoped_ptr<ResourceEntry> resource_entry = 751 scoped_ptr<ResourceEntry> resource_entry =
756 util::ConvertChangeResourceToResourceEntry(*new_change); 752 util::ConvertChangeResourceToResourceEntry(*new_change);
757 // Add the new entry to the map. 753 // Add the new entry to the map.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 786 }
791 787
792 EntryInfo* entry = FindEntryByResourceId(resource_id); 788 EntryInfo* entry = FindEntryByResourceId(resource_id);
793 if (entry) { 789 if (entry) {
794 ChangeResource* change = &entry->change_resource; 790 ChangeResource* change = &entry->change_resource;
795 FileResource* file = change->mutable_file(); 791 FileResource* file = change->mutable_file();
796 file->set_title(new_title); 792 file->set_title(new_title);
797 793
798 // Set parent if necessary. 794 // Set parent if necessary.
799 if (!parent_resource_id.empty()) { 795 if (!parent_resource_id.empty()) {
800 scoped_ptr<ParentReference> parent(new ParentReference); 796 ParentReference parent;
801 parent->set_file_id(parent_resource_id); 797 parent.set_file_id(parent_resource_id);
802 parent->set_parent_link(GetFakeLinkUrl(parent_resource_id)); 798 parent.set_parent_link(GetFakeLinkUrl(parent_resource_id));
803 parent->set_is_root(parent_resource_id == GetRootResourceId()); 799 parent.set_is_root(parent_resource_id == GetRootResourceId());
804 800
805 ScopedVector<ParentReference> parents; 801 std::vector<ParentReference> parents;
806 parents.push_back(parent.release()); 802 parents.push_back(parent);
807 file->set_parents(parents.Pass()); 803 *file->mutable_parents() = parents;
808 } 804 }
809 805
810 if (!last_modified.is_null()) 806 if (!last_modified.is_null())
811 file->set_modified_date(last_modified); 807 file->set_modified_date(last_modified);
812 808
813 if (!last_viewed_by_me.is_null()) 809 if (!last_viewed_by_me.is_null())
814 file->set_last_viewed_by_me_date(last_viewed_by_me); 810 file->set_last_viewed_by_me_date(last_viewed_by_me);
815 811
816 AddNewChangestamp(change); 812 AddNewChangestamp(change);
817 UpdateETag(file); 813 UpdateETag(file);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 return CancelCallback(); 852 return CancelCallback();
857 } 853 }
858 854
859 EntryInfo* entry = FindEntryByResourceId(resource_id); 855 EntryInfo* entry = FindEntryByResourceId(resource_id);
860 if (entry) { 856 if (entry) {
861 ChangeResource* change = &entry->change_resource; 857 ChangeResource* change = &entry->change_resource;
862 // On the real Drive server, resources do not necessary shape a tree 858 // On the real Drive server, resources do not necessary shape a tree
863 // structure. That is, each resource can have multiple parent. 859 // structure. That is, each resource can have multiple parent.
864 // We mimic the behavior here; AddResourceToDirectoy just adds 860 // We mimic the behavior here; AddResourceToDirectoy just adds
865 // one more parent, not overwriting old ones. 861 // one more parent, not overwriting old ones.
866 scoped_ptr<ParentReference> parent(new ParentReference); 862 ParentReference parent;
867 parent->set_file_id(parent_resource_id); 863 parent.set_file_id(parent_resource_id);
868 parent->set_parent_link(GetFakeLinkUrl(parent_resource_id)); 864 parent.set_parent_link(GetFakeLinkUrl(parent_resource_id));
869 parent->set_is_root(parent_resource_id == GetRootResourceId()); 865 parent.set_is_root(parent_resource_id == GetRootResourceId());
870 change->mutable_file()->mutable_parents()->push_back(parent.release()); 866 change->mutable_file()->mutable_parents()->push_back(parent);
871 867
872 AddNewChangestamp(change); 868 AddNewChangestamp(change);
873 base::MessageLoop::current()->PostTask( 869 base::MessageLoop::current()->PostTask(
874 FROM_HERE, base::Bind(callback, HTTP_SUCCESS)); 870 FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
875 return CancelCallback(); 871 return CancelCallback();
876 } 872 }
877 873
878 base::MessageLoop::current()->PostTask( 874 base::MessageLoop::current()->PostTask(
879 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); 875 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
880 return CancelCallback(); 876 return CancelCallback();
881 } 877 }
882 878
883 CancelCallback FakeDriveService::RemoveResourceFromDirectory( 879 CancelCallback FakeDriveService::RemoveResourceFromDirectory(
884 const std::string& parent_resource_id, 880 const std::string& parent_resource_id,
885 const std::string& resource_id, 881 const std::string& resource_id,
886 const EntryActionCallback& callback) { 882 const EntryActionCallback& callback) {
887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
888 DCHECK(!callback.is_null()); 884 DCHECK(!callback.is_null());
889 885
890 if (offline_) { 886 if (offline_) {
891 base::MessageLoop::current()->PostTask( 887 base::MessageLoop::current()->PostTask(
892 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION)); 888 FROM_HERE, base::Bind(callback, GDATA_NO_CONNECTION));
893 return CancelCallback(); 889 return CancelCallback();
894 } 890 }
895 891
896 EntryInfo* entry = FindEntryByResourceId(resource_id); 892 EntryInfo* entry = FindEntryByResourceId(resource_id);
897 if (entry) { 893 if (entry) {
898 ChangeResource* change = &entry->change_resource; 894 ChangeResource* change = &entry->change_resource;
899 FileResource* file = change->mutable_file(); 895 FileResource* file = change->mutable_file();
900 ScopedVector<ParentReference>* parents = file->mutable_parents(); 896 std::vector<ParentReference>* parents = file->mutable_parents();
901 for (size_t i = 0; i < parents->size(); ++i) { 897 for (size_t i = 0; i < parents->size(); ++i) {
902 if ((*parents)[i]->file_id() == parent_resource_id) { 898 if ((*parents)[i].file_id() == parent_resource_id) {
903 parents->erase(parents->begin() + i); 899 parents->erase(parents->begin() + i);
904 AddNewChangestamp(change); 900 AddNewChangestamp(change);
905 base::MessageLoop::current()->PostTask( 901 base::MessageLoop::current()->PostTask(
906 FROM_HERE, base::Bind(callback, HTTP_NO_CONTENT)); 902 FROM_HERE, base::Bind(callback, HTTP_NO_CONTENT));
907 return CancelCallback(); 903 return CancelCallback();
908 } 904 }
909 } 905 }
910 } 906 }
911 907
912 base::MessageLoop::current()->PostTask( 908 base::MessageLoop::current()->PostTask(
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 // Set current time to mark the file as shared_with_me. 1411 // Set current time to mark the file as shared_with_me.
1416 new_file->set_shared_with_me_date(base::Time::Now()); 1412 new_file->set_shared_with_me_date(base::Time::Now());
1417 } 1413 }
1418 1414
1419 std::string escaped_resource_id = net::EscapePath(resource_id); 1415 std::string escaped_resource_id = net::EscapePath(resource_id);
1420 1416
1421 // Set mime type. 1417 // Set mime type.
1422 new_file->set_mime_type(content_type); 1418 new_file->set_mime_type(content_type);
1423 1419
1424 // Set parents. 1420 // Set parents.
1425 scoped_ptr<ParentReference> parent(new ParentReference); 1421 ParentReference parent;
1426 if (parent_resource_id.empty()) 1422 if (parent_resource_id.empty())
1427 parent->set_file_id(GetRootResourceId()); 1423 parent.set_file_id(GetRootResourceId());
1428 else 1424 else
1429 parent->set_file_id(parent_resource_id); 1425 parent.set_file_id(parent_resource_id);
1430 parent->set_parent_link(GetFakeLinkUrl(parent->file_id())); 1426 parent.set_parent_link(GetFakeLinkUrl(parent.file_id()));
1431 parent->set_is_root(parent->file_id() == GetRootResourceId()); 1427 parent.set_is_root(parent.file_id() == GetRootResourceId());
1432 ScopedVector<ParentReference> parents; 1428 std::vector<ParentReference> parents;
1433 parents.push_back(parent.release()); 1429 parents.push_back(parent);
1434 new_file->set_parents(parents.Pass()); 1430 *new_file->mutable_parents() = parents;
1435 1431
1436 new_entry->share_url = net::AppendOrReplaceQueryParameter( 1432 new_entry->share_url = net::AppendOrReplaceQueryParameter(
1437 share_url_base_, "name", title); 1433 share_url_base_, "name", title);
1438 1434
1439 AddNewChangestamp(new_change); 1435 AddNewChangestamp(new_change);
1440 UpdateETag(new_file); 1436 UpdateETag(new_file);
1441 1437
1442 base::Time published_date = 1438 base::Time published_date =
1443 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_); 1439 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_);
1444 new_file->set_created_date(published_date); 1440 new_file->set_created_date(published_date);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 google_apis::drive::PermissionRole role, 1577 google_apis::drive::PermissionRole role,
1582 const google_apis::EntryActionCallback& callback) { 1578 const google_apis::EntryActionCallback& callback) {
1583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1584 DCHECK(!callback.is_null()); 1580 DCHECK(!callback.is_null());
1585 1581
1586 NOTREACHED(); 1582 NOTREACHED();
1587 return CancelCallback(); 1583 return CancelCallback();
1588 } 1584 }
1589 1585
1590 } // namespace drive 1586 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util_unittest.cc ('k') | chrome/browser/sync_file_system/drive_backend/drive_backend_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698