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 "google_apis/drive/drive_api_requests.h" | 5 #include "google_apis/drive/drive_api_requests.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 google_apis::util::FormatTimeAsString(modified_date)); | 123 google_apis::util::FormatTimeAsString(modified_date)); |
124 } | 124 } |
125 | 125 |
126 if (!last_viewed_by_me_date.is_null()) { | 126 if (!last_viewed_by_me_date.is_null()) { |
127 root.SetString("lastViewedByMeDate", google_apis::util::FormatTimeAsString( | 127 root.SetString("lastViewedByMeDate", google_apis::util::FormatTimeAsString( |
128 last_viewed_by_me_date)); | 128 last_viewed_by_me_date)); |
129 } | 129 } |
130 | 130 |
131 AttachProperties(properties, &root); | 131 AttachProperties(properties, &root); |
132 std::string json_string; | 132 std::string json_string; |
133 base::JSONWriter::Write(&root, &json_string); | 133 base::JSONWriter::Write(root, &json_string); |
134 return json_string; | 134 return json_string; |
135 } | 135 } |
136 | 136 |
137 // Splits |string| into lines by |kHttpBr|. | 137 // Splits |string| into lines by |kHttpBr|. |
138 // Each line does not include |kHttpBr|. | 138 // Each line does not include |kHttpBr|. |
139 void SplitIntoLines(const std::string& string, | 139 void SplitIntoLines(const std::string& string, |
140 std::vector<base::StringPiece>* output) { | 140 std::vector<base::StringPiece>* output) { |
141 const size_t br_size = std::string(kHttpBr).size(); | 141 const size_t br_size = std::string(kHttpBr).size(); |
142 std::string::const_iterator it = string.begin(); | 142 std::string::const_iterator it = string.begin(); |
143 std::vector<base::StringPiece> lines; | 143 std::vector<base::StringPiece> lines; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 parent->SetString("id", parents_[i]); | 407 parent->SetString("id", parents_[i]); |
408 parents_value->Append(parent); | 408 parents_value->Append(parent); |
409 } | 409 } |
410 root.Set("parents", parents_value); | 410 root.Set("parents", parents_value); |
411 } | 411 } |
412 | 412 |
413 if (!title_.empty()) | 413 if (!title_.empty()) |
414 root.SetString("title", title_); | 414 root.SetString("title", title_); |
415 | 415 |
416 AttachProperties(properties_, &root); | 416 AttachProperties(properties_, &root); |
417 base::JSONWriter::Write(&root, upload_content); | 417 base::JSONWriter::Write(root, upload_content); |
418 | 418 |
419 DVLOG(1) << "FilesInsert data: " << *upload_content_type << ", [" | 419 DVLOG(1) << "FilesInsert data: " << *upload_content_type << ", [" |
420 << *upload_content << "]"; | 420 << *upload_content << "]"; |
421 return true; | 421 return true; |
422 } | 422 } |
423 | 423 |
424 GURL FilesInsertRequest::GetURLInternal() const { | 424 GURL FilesInsertRequest::GetURLInternal() const { |
425 return url_generator_.GetFilesInsertUrl(); | 425 return url_generator_.GetFilesInsertUrl(); |
426 } | 426 } |
427 | 427 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 base::ListValue* parents_value = new base::ListValue; | 481 base::ListValue* parents_value = new base::ListValue; |
482 for (size_t i = 0; i < parents_.size(); ++i) { | 482 for (size_t i = 0; i < parents_.size(); ++i) { |
483 base::DictionaryValue* parent = new base::DictionaryValue; | 483 base::DictionaryValue* parent = new base::DictionaryValue; |
484 parent->SetString("id", parents_[i]); | 484 parent->SetString("id", parents_[i]); |
485 parents_value->Append(parent); | 485 parents_value->Append(parent); |
486 } | 486 } |
487 root.Set("parents", parents_value); | 487 root.Set("parents", parents_value); |
488 } | 488 } |
489 | 489 |
490 AttachProperties(properties_, &root); | 490 AttachProperties(properties_, &root); |
491 base::JSONWriter::Write(&root, upload_content); | 491 base::JSONWriter::Write(root, upload_content); |
492 | 492 |
493 DVLOG(1) << "FilesPatch data: " << *upload_content_type << ", [" | 493 DVLOG(1) << "FilesPatch data: " << *upload_content_type << ", [" |
494 << *upload_content << "]"; | 494 << *upload_content << "]"; |
495 return true; | 495 return true; |
496 } | 496 } |
497 | 497 |
498 //============================= FilesCopyRequest ============================== | 498 //============================= FilesCopyRequest ============================== |
499 | 499 |
500 FilesCopyRequest::FilesCopyRequest( | 500 FilesCopyRequest::FilesCopyRequest( |
501 RequestSender* sender, | 501 RequestSender* sender, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 base::DictionaryValue* parent = new base::DictionaryValue; | 535 base::DictionaryValue* parent = new base::DictionaryValue; |
536 parent->SetString("id", parents_[i]); | 536 parent->SetString("id", parents_[i]); |
537 parents_value->Append(parent); | 537 parents_value->Append(parent); |
538 } | 538 } |
539 root.Set("parents", parents_value); | 539 root.Set("parents", parents_value); |
540 } | 540 } |
541 | 541 |
542 if (!title_.empty()) | 542 if (!title_.empty()) |
543 root.SetString("title", title_); | 543 root.SetString("title", title_); |
544 | 544 |
545 base::JSONWriter::Write(&root, upload_content); | 545 base::JSONWriter::Write(root, upload_content); |
546 DVLOG(1) << "FilesCopy data: " << *upload_content_type << ", [" | 546 DVLOG(1) << "FilesCopy data: " << *upload_content_type << ", [" |
547 << *upload_content << "]"; | 547 << *upload_content << "]"; |
548 return true; | 548 return true; |
549 } | 549 } |
550 | 550 |
551 //============================= FilesListRequest ============================= | 551 //============================= FilesListRequest ============================= |
552 | 552 |
553 FilesListRequest::FilesListRequest( | 553 FilesListRequest::FilesListRequest( |
554 RequestSender* sender, | 554 RequestSender* sender, |
555 const DriveApiUrlGenerator& url_generator, | 555 const DriveApiUrlGenerator& url_generator, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 return url_generator_.GetChildrenInsertUrl(folder_id_); | 745 return url_generator_.GetChildrenInsertUrl(folder_id_); |
746 } | 746 } |
747 | 747 |
748 bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type, | 748 bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type, |
749 std::string* upload_content) { | 749 std::string* upload_content) { |
750 *upload_content_type = util::kContentTypeApplicationJson; | 750 *upload_content_type = util::kContentTypeApplicationJson; |
751 | 751 |
752 base::DictionaryValue root; | 752 base::DictionaryValue root; |
753 root.SetString("id", id_); | 753 root.SetString("id", id_); |
754 | 754 |
755 base::JSONWriter::Write(&root, upload_content); | 755 base::JSONWriter::Write(root, upload_content); |
756 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", [" | 756 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", [" |
757 << *upload_content << "]"; | 757 << *upload_content << "]"; |
758 return true; | 758 return true; |
759 } | 759 } |
760 | 760 |
761 //========================== ChildrenDeleteRequest ============================ | 761 //========================== ChildrenDeleteRequest ============================ |
762 | 762 |
763 ChildrenDeleteRequest::ChildrenDeleteRequest( | 763 ChildrenDeleteRequest::ChildrenDeleteRequest( |
764 RequestSender* sender, | 764 RequestSender* sender, |
765 const DriveApiUrlGenerator& url_generator, | 765 const DriveApiUrlGenerator& url_generator, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 824 |
825 if (!modified_date_.is_null()) | 825 if (!modified_date_.is_null()) |
826 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); | 826 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); |
827 | 827 |
828 if (!last_viewed_by_me_date_.is_null()) { | 828 if (!last_viewed_by_me_date_.is_null()) { |
829 root.SetString("lastViewedByMeDate", | 829 root.SetString("lastViewedByMeDate", |
830 util::FormatTimeAsString(last_viewed_by_me_date_)); | 830 util::FormatTimeAsString(last_viewed_by_me_date_)); |
831 } | 831 } |
832 | 832 |
833 AttachProperties(properties_, &root); | 833 AttachProperties(properties_, &root); |
834 base::JSONWriter::Write(&root, upload_content); | 834 base::JSONWriter::Write(root, upload_content); |
835 | 835 |
836 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" | 836 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" |
837 << *upload_content << "]"; | 837 << *upload_content << "]"; |
838 return true; | 838 return true; |
839 } | 839 } |
840 | 840 |
841 //===================== InitiateUploadExistingFileRequest ==================== | 841 //===================== InitiateUploadExistingFileRequest ==================== |
842 | 842 |
843 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest( | 843 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest( |
844 RequestSender* sender, | 844 RequestSender* sender, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 if (!last_viewed_by_me_date_.is_null()) { | 896 if (!last_viewed_by_me_date_.is_null()) { |
897 root.SetString("lastViewedByMeDate", | 897 root.SetString("lastViewedByMeDate", |
898 util::FormatTimeAsString(last_viewed_by_me_date_)); | 898 util::FormatTimeAsString(last_viewed_by_me_date_)); |
899 } | 899 } |
900 | 900 |
901 AttachProperties(properties_, &root); | 901 AttachProperties(properties_, &root); |
902 if (root.empty()) | 902 if (root.empty()) |
903 return false; | 903 return false; |
904 | 904 |
905 *upload_content_type = util::kContentTypeApplicationJson; | 905 *upload_content_type = util::kContentTypeApplicationJson; |
906 base::JSONWriter::Write(&root, upload_content); | 906 base::JSONWriter::Write(root, upload_content); |
907 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type | 907 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type |
908 << ", [" << *upload_content << "]"; | 908 << ", [" << *upload_content << "]"; |
909 return true; | 909 return true; |
910 } | 910 } |
911 | 911 |
912 //============================ ResumeUploadRequest =========================== | 912 //============================ ResumeUploadRequest =========================== |
913 | 913 |
914 ResumeUploadRequest::ResumeUploadRequest( | 914 ResumeUploadRequest::ResumeUploadRequest( |
915 RequestSender* sender, | 915 RequestSender* sender, |
916 const GURL& upload_location, | 916 const GURL& upload_location, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 case PERMISSION_ROLE_COMMENTER: | 1148 case PERMISSION_ROLE_COMMENTER: |
1149 root.SetString("role", "reader"); | 1149 root.SetString("role", "reader"); |
1150 { | 1150 { |
1151 base::ListValue* list = new base::ListValue; | 1151 base::ListValue* list = new base::ListValue; |
1152 list->AppendString("commenter"); | 1152 list->AppendString("commenter"); |
1153 root.Set("additionalRoles", list); | 1153 root.Set("additionalRoles", list); |
1154 } | 1154 } |
1155 break; | 1155 break; |
1156 } | 1156 } |
1157 root.SetString("value", value_); | 1157 root.SetString("value", value_); |
1158 base::JSONWriter::Write(&root, upload_content); | 1158 base::JSONWriter::Write(root, upload_content); |
1159 return true; | 1159 return true; |
1160 } | 1160 } |
1161 | 1161 |
1162 //========================== BatchUploadRequest ========================== | 1162 //========================== BatchUploadRequest ========================== |
1163 | 1163 |
1164 BatchUploadRequest::BatchUploadRequest( | 1164 BatchUploadRequest::BatchUploadRequest( |
1165 RequestSender* sender, | 1165 RequestSender* sender, |
1166 const DriveApiUrlGenerator& url_generator) | 1166 const DriveApiUrlGenerator& url_generator) |
1167 : UrlFetchRequestBase(sender), | 1167 : UrlFetchRequestBase(sender), |
1168 sender_(sender), | 1168 sender_(sender), |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 } else if (last_progress_value_ < child.data_offset + child.data_size && | 1370 } else if (last_progress_value_ < child.data_offset + child.data_size && |
1371 child.data_offset + child.data_size < current) { | 1371 child.data_offset + child.data_size < current) { |
1372 child.request->OnURLFetchUploadProgress(source, child.data_size, | 1372 child.request->OnURLFetchUploadProgress(source, child.data_size, |
1373 child.data_size); | 1373 child.data_size); |
1374 } | 1374 } |
1375 } | 1375 } |
1376 last_progress_value_ = current; | 1376 last_progress_value_ = current; |
1377 } | 1377 } |
1378 } // namespace drive | 1378 } // namespace drive |
1379 } // namespace google_apis | 1379 } // namespace google_apis |
OLD | NEW |