| 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 "chrome/browser/google_apis/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 return; | 770 return; |
| 771 } | 771 } |
| 772 } | 772 } |
| 773 | 773 |
| 774 scoped_ptr<ResourceEntry> null; | 774 scoped_ptr<ResourceEntry> null; |
| 775 MessageLoop::current()->PostTask( | 775 MessageLoop::current()->PostTask( |
| 776 FROM_HERE, | 776 FROM_HERE, |
| 777 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); | 777 base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null))); |
| 778 } | 778 } |
| 779 | 779 |
| 780 void FakeDriveService::InitiateUpload( | 780 void FakeDriveService::InitiateUploadNewFile( |
| 781 const InitiateUploadParams& params, | 781 const FilePath& drive_file_path, |
| 782 const std::string& content_type, |
| 783 int64 content_length, |
| 784 const GURL& parent_upload_url, |
| 785 const std::string& title, |
| 782 const InitiateUploadCallback& callback) { | 786 const InitiateUploadCallback& callback) { |
| 783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 784 DCHECK(!callback.is_null()); | 788 DCHECK(!callback.is_null()); |
| 785 | 789 |
| 786 if (offline_) { | 790 if (offline_) { |
| 787 MessageLoop::current()->PostTask( | 791 MessageLoop::current()->PostTask( |
| 788 FROM_HERE, | 792 FROM_HERE, |
| 789 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | 793 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 790 return; | 794 return; |
| 791 } | 795 } |
| 792 | 796 |
| 793 DictionaryValue* entry = FindEntryByUploadUrl(params.upload_location); | 797 DictionaryValue* entry = FindEntryByUploadUrl(parent_upload_url); |
| 794 if (!entry) { | 798 if (!entry) { |
| 795 MessageLoop::current()->PostTask( | 799 MessageLoop::current()->PostTask( |
| 796 FROM_HERE, | 800 FROM_HERE, |
| 797 base::Bind(callback, HTTP_NOT_FOUND, GURL())); | 801 base::Bind(callback, HTTP_NOT_FOUND, GURL())); |
| 798 return; | 802 return; |
| 799 } | 803 } |
| 800 | 804 |
| 801 if (params.upload_mode == UPLOAD_EXISTING_FILE) { | |
| 802 std::string etag; | |
| 803 entry->GetString("gd$etag", &etag); | |
| 804 if (params.etag != etag) { | |
| 805 MessageLoop::current()->PostTask( | |
| 806 FROM_HERE, | |
| 807 base::Bind(callback, HTTP_PRECONDITION, GURL())); | |
| 808 return; | |
| 809 } | |
| 810 MessageLoop::current()->PostTask( | |
| 811 FROM_HERE, | |
| 812 base::Bind(callback, HTTP_SUCCESS, params.upload_location)); | |
| 813 return; | |
| 814 } | |
| 815 | |
| 816 // If the title was set, the upload_location is the location of the parent | 805 // If the title was set, the upload_location is the location of the parent |
| 817 // directory of the file that will be uploaded. The file does not yet exist | 806 // directory of the file that will be uploaded. The file does not yet exist |
| 818 // and it must be created. Its title will be the passed title param. | 807 // and it must be created. Its title will be the passed title param. |
| 819 std::string parent_resource_id; | 808 std::string parent_resource_id; |
| 820 entry->GetString("gd$resourceId.$t", &parent_resource_id); | 809 entry->GetString("gd$resourceId.$t", &parent_resource_id); |
| 821 | 810 |
| 822 std::string resource_id = GetNewResourceId(); | 811 std::string resource_id = GetNewResourceId(); |
| 823 GURL upload_url = GURL("https://xxx/upload/" + resource_id); | 812 GURL upload_url = GURL("https://xxx/upload/" + resource_id); |
| 824 | 813 |
| 825 scoped_ptr<base::DictionaryValue> new_entry(new base::DictionaryValue); | 814 scoped_ptr<base::DictionaryValue> new_entry(new base::DictionaryValue); |
| 826 // Set the resource ID and the title | 815 // Set the resource ID and the title |
| 827 new_entry->SetString("gd$resourceId.$t", resource_id); | 816 new_entry->SetString("gd$resourceId.$t", resource_id); |
| 828 new_entry->SetString("title.$t", params.title); | 817 new_entry->SetString("title.$t", title); |
| 829 new_entry->SetString("docs$filename", params.title); | 818 new_entry->SetString("docs$filename", title); |
| 830 new_entry->SetString("docs$size", "0"); | 819 new_entry->SetString("docs$size", "0"); |
| 831 new_entry->SetString("docs$md5Checksum.$t", | 820 new_entry->SetString("docs$md5Checksum.$t", |
| 832 "3b4385ebefec6e743574c76bbd0575de"); | 821 "3b4385ebefec6e743574c76bbd0575de"); |
| 833 | 822 |
| 834 // Add "category" which sets the resource type to file. | 823 // Add "category" which sets the resource type to file. |
| 835 base::ListValue* categories = new base::ListValue; | 824 base::ListValue* categories = new base::ListValue; |
| 836 base::DictionaryValue* category = new base::DictionaryValue; | 825 base::DictionaryValue* category = new base::DictionaryValue; |
| 837 category->SetString("label", "test/foo"); | 826 category->SetString("label", "test/foo"); |
| 838 category->SetString("scheme", "http://schemas.google.com/g/2005#kind"); | 827 category->SetString("scheme", "http://schemas.google.com/g/2005#kind"); |
| 839 category->SetString("term", "http://schemas.google.com/docs/2007#file"); | 828 category->SetString("term", "http://schemas.google.com/docs/2007#file"); |
| 840 categories->Append(category); | 829 categories->Append(category); |
| 841 new_entry->Set("category", categories); | 830 new_entry->Set("category", categories); |
| 842 | 831 |
| 843 // Add "content" which sets the content URL. | 832 // Add "content" which sets the content URL. |
| 844 base::DictionaryValue* content = new base::DictionaryValue; | 833 base::DictionaryValue* content = new base::DictionaryValue; |
| 845 content->SetString("src", "https://xxx/content/" + resource_id); | 834 content->SetString("src", "https://xxx/content/" + resource_id); |
| 846 content->SetString("type", params.content_type); | 835 content->SetString("type", content_type); |
| 847 new_entry->Set("content", content); | 836 new_entry->Set("content", content); |
| 848 | 837 |
| 849 // Add "link" which sets the parent URL, the edit URL and the upload URL. | 838 // Add "link" which sets the parent URL, the edit URL and the upload URL. |
| 850 base::ListValue* links = new base::ListValue; | 839 base::ListValue* links = new base::ListValue; |
| 851 if (parent_resource_id != GetRootResourceId()) { | 840 if (parent_resource_id != GetRootResourceId()) { |
| 852 base::DictionaryValue* parent_link = new base::DictionaryValue; | 841 base::DictionaryValue* parent_link = new base::DictionaryValue; |
| 853 parent_link->SetString("href", GetFakeLinkUrl(parent_resource_id).spec()); | 842 parent_link->SetString("href", GetFakeLinkUrl(parent_resource_id).spec()); |
| 854 parent_link->SetString("rel", | 843 parent_link->SetString("rel", |
| 855 "http://schemas.google.com/docs/2007#parent"); | 844 "http://schemas.google.com/docs/2007#parent"); |
| 856 links->Append(parent_link); | 845 links->Append(parent_link); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 883 resource_list_dict->Set("entry", new ListValue); | 872 resource_list_dict->Set("entry", new ListValue); |
| 884 | 873 |
| 885 if (resource_list_dict->GetList("entry", &entries)) | 874 if (resource_list_dict->GetList("entry", &entries)) |
| 886 entries->Append(new_entry.release()); | 875 entries->Append(new_entry.release()); |
| 887 | 876 |
| 888 MessageLoop::current()->PostTask( | 877 MessageLoop::current()->PostTask( |
| 889 FROM_HERE, | 878 FROM_HERE, |
| 890 base::Bind(callback, HTTP_SUCCESS, upload_url)); | 879 base::Bind(callback, HTTP_SUCCESS, upload_url)); |
| 891 } | 880 } |
| 892 | 881 |
| 882 void FakeDriveService::InitiateUploadExistingFile( |
| 883 const FilePath& drive_file_path, |
| 884 const std::string& content_type, |
| 885 int64 content_length, |
| 886 const GURL& upload_url, |
| 887 const std::string& etag, |
| 888 const InitiateUploadCallback& callback) { |
| 889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 890 DCHECK(!callback.is_null()); |
| 891 |
| 892 if (offline_) { |
| 893 MessageLoop::current()->PostTask( |
| 894 FROM_HERE, |
| 895 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 896 return; |
| 897 } |
| 898 |
| 899 DictionaryValue* entry = FindEntryByUploadUrl(upload_url); |
| 900 if (!entry) { |
| 901 MessageLoop::current()->PostTask( |
| 902 FROM_HERE, |
| 903 base::Bind(callback, HTTP_NOT_FOUND, GURL())); |
| 904 return; |
| 905 } |
| 906 |
| 907 std::string entry_etag; |
| 908 entry->GetString("gd$etag", &entry_etag); |
| 909 if (etag != entry_etag) { |
| 910 MessageLoop::current()->PostTask( |
| 911 FROM_HERE, |
| 912 base::Bind(callback, HTTP_PRECONDITION, GURL())); |
| 913 return; |
| 914 } |
| 915 MessageLoop::current()->PostTask( |
| 916 FROM_HERE, |
| 917 base::Bind(callback, HTTP_SUCCESS, upload_url)); |
| 918 } |
| 919 |
| 893 void FakeDriveService::GetUploadStatus( | 920 void FakeDriveService::GetUploadStatus( |
| 894 UploadMode upload_mode, | 921 UploadMode upload_mode, |
| 895 const base::FilePath& drive_file_path, | 922 const base::FilePath& drive_file_path, |
| 896 const GURL& upload_url, | 923 const GURL& upload_url, |
| 897 int64 content_length, | 924 int64 content_length, |
| 898 const UploadRangeCallback& callback) { | 925 const UploadRangeCallback& callback) { |
| 899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 900 DCHECK(!callback.is_null()); | 927 DCHECK(!callback.is_null()); |
| 901 } | 928 } |
| 902 | 929 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 return base::StringPrintf("resource_id_%d", resource_id_count_); | 1082 return base::StringPrintf("resource_id_%d", resource_id_count_); |
| 1056 } | 1083 } |
| 1057 | 1084 |
| 1058 void FakeDriveService::AddNewChangestamp(base::DictionaryValue* entry) { | 1085 void FakeDriveService::AddNewChangestamp(base::DictionaryValue* entry) { |
| 1059 ++largest_changestamp_; | 1086 ++largest_changestamp_; |
| 1060 entry->SetString("docs$changestamp.value", | 1087 entry->SetString("docs$changestamp.value", |
| 1061 base::Int64ToString(largest_changestamp_)); | 1088 base::Int64ToString(largest_changestamp_)); |
| 1062 } | 1089 } |
| 1063 | 1090 |
| 1064 } // namespace google_apis | 1091 } // namespace google_apis |
| OLD | NEW |