| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 parent->SetString("id", parents_[i]); | 410 parent->SetString("id", parents_[i]); |
| 411 parents_value->Append(parent); | 411 parents_value->Append(parent); |
| 412 } | 412 } |
| 413 root.Set("parents", parents_value); | 413 root.Set("parents", parents_value); |
| 414 } | 414 } |
| 415 | 415 |
| 416 if (!title_.empty()) | 416 if (!title_.empty()) |
| 417 root.SetString("title", title_); | 417 root.SetString("title", title_); |
| 418 | 418 |
| 419 AttachProperties(properties_, &root); | 419 AttachProperties(properties_, &root); |
| 420 base::JSONWriter::Write(&root, upload_content); | 420 base::JSONWriter::Write(root, upload_content); |
| 421 | 421 |
| 422 DVLOG(1) << "FilesInsert data: " << *upload_content_type << ", [" | 422 DVLOG(1) << "FilesInsert data: " << *upload_content_type << ", [" |
| 423 << *upload_content << "]"; | 423 << *upload_content << "]"; |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 | 426 |
| 427 GURL FilesInsertRequest::GetURLInternal() const { | 427 GURL FilesInsertRequest::GetURLInternal() const { |
| 428 return url_generator_.GetFilesInsertUrl(); | 428 return url_generator_.GetFilesInsertUrl(); |
| 429 } | 429 } |
| 430 | 430 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 base::ListValue* parents_value = new base::ListValue; | 484 base::ListValue* parents_value = new base::ListValue; |
| 485 for (size_t i = 0; i < parents_.size(); ++i) { | 485 for (size_t i = 0; i < parents_.size(); ++i) { |
| 486 base::DictionaryValue* parent = new base::DictionaryValue; | 486 base::DictionaryValue* parent = new base::DictionaryValue; |
| 487 parent->SetString("id", parents_[i]); | 487 parent->SetString("id", parents_[i]); |
| 488 parents_value->Append(parent); | 488 parents_value->Append(parent); |
| 489 } | 489 } |
| 490 root.Set("parents", parents_value); | 490 root.Set("parents", parents_value); |
| 491 } | 491 } |
| 492 | 492 |
| 493 AttachProperties(properties_, &root); | 493 AttachProperties(properties_, &root); |
| 494 base::JSONWriter::Write(&root, upload_content); | 494 base::JSONWriter::Write(root, upload_content); |
| 495 | 495 |
| 496 DVLOG(1) << "FilesPatch data: " << *upload_content_type << ", [" | 496 DVLOG(1) << "FilesPatch data: " << *upload_content_type << ", [" |
| 497 << *upload_content << "]"; | 497 << *upload_content << "]"; |
| 498 return true; | 498 return true; |
| 499 } | 499 } |
| 500 | 500 |
| 501 //============================= FilesCopyRequest ============================== | 501 //============================= FilesCopyRequest ============================== |
| 502 | 502 |
| 503 FilesCopyRequest::FilesCopyRequest( | 503 FilesCopyRequest::FilesCopyRequest( |
| 504 RequestSender* sender, | 504 RequestSender* sender, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 base::DictionaryValue* parent = new base::DictionaryValue; | 538 base::DictionaryValue* parent = new base::DictionaryValue; |
| 539 parent->SetString("id", parents_[i]); | 539 parent->SetString("id", parents_[i]); |
| 540 parents_value->Append(parent); | 540 parents_value->Append(parent); |
| 541 } | 541 } |
| 542 root.Set("parents", parents_value); | 542 root.Set("parents", parents_value); |
| 543 } | 543 } |
| 544 | 544 |
| 545 if (!title_.empty()) | 545 if (!title_.empty()) |
| 546 root.SetString("title", title_); | 546 root.SetString("title", title_); |
| 547 | 547 |
| 548 base::JSONWriter::Write(&root, upload_content); | 548 base::JSONWriter::Write(root, upload_content); |
| 549 DVLOG(1) << "FilesCopy data: " << *upload_content_type << ", [" | 549 DVLOG(1) << "FilesCopy data: " << *upload_content_type << ", [" |
| 550 << *upload_content << "]"; | 550 << *upload_content << "]"; |
| 551 return true; | 551 return true; |
| 552 } | 552 } |
| 553 | 553 |
| 554 //============================= FilesListRequest ============================= | 554 //============================= FilesListRequest ============================= |
| 555 | 555 |
| 556 FilesListRequest::FilesListRequest( | 556 FilesListRequest::FilesListRequest( |
| 557 RequestSender* sender, | 557 RequestSender* sender, |
| 558 const DriveApiUrlGenerator& url_generator, | 558 const DriveApiUrlGenerator& url_generator, |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 return url_generator_.GetChildrenInsertUrl(folder_id_); | 748 return url_generator_.GetChildrenInsertUrl(folder_id_); |
| 749 } | 749 } |
| 750 | 750 |
| 751 bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type, | 751 bool ChildrenInsertRequest::GetContentData(std::string* upload_content_type, |
| 752 std::string* upload_content) { | 752 std::string* upload_content) { |
| 753 *upload_content_type = util::kContentTypeApplicationJson; | 753 *upload_content_type = util::kContentTypeApplicationJson; |
| 754 | 754 |
| 755 base::DictionaryValue root; | 755 base::DictionaryValue root; |
| 756 root.SetString("id", id_); | 756 root.SetString("id", id_); |
| 757 | 757 |
| 758 base::JSONWriter::Write(&root, upload_content); | 758 base::JSONWriter::Write(root, upload_content); |
| 759 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", [" | 759 DVLOG(1) << "InsertResource data: " << *upload_content_type << ", [" |
| 760 << *upload_content << "]"; | 760 << *upload_content << "]"; |
| 761 return true; | 761 return true; |
| 762 } | 762 } |
| 763 | 763 |
| 764 //========================== ChildrenDeleteRequest ============================ | 764 //========================== ChildrenDeleteRequest ============================ |
| 765 | 765 |
| 766 ChildrenDeleteRequest::ChildrenDeleteRequest( | 766 ChildrenDeleteRequest::ChildrenDeleteRequest( |
| 767 RequestSender* sender, | 767 RequestSender* sender, |
| 768 const DriveApiUrlGenerator& url_generator, | 768 const DriveApiUrlGenerator& url_generator, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 | 827 |
| 828 if (!modified_date_.is_null()) | 828 if (!modified_date_.is_null()) |
| 829 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); | 829 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); |
| 830 | 830 |
| 831 if (!last_viewed_by_me_date_.is_null()) { | 831 if (!last_viewed_by_me_date_.is_null()) { |
| 832 root.SetString("lastViewedByMeDate", | 832 root.SetString("lastViewedByMeDate", |
| 833 util::FormatTimeAsString(last_viewed_by_me_date_)); | 833 util::FormatTimeAsString(last_viewed_by_me_date_)); |
| 834 } | 834 } |
| 835 | 835 |
| 836 AttachProperties(properties_, &root); | 836 AttachProperties(properties_, &root); |
| 837 base::JSONWriter::Write(&root, upload_content); | 837 base::JSONWriter::Write(root, upload_content); |
| 838 | 838 |
| 839 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" | 839 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" |
| 840 << *upload_content << "]"; | 840 << *upload_content << "]"; |
| 841 return true; | 841 return true; |
| 842 } | 842 } |
| 843 | 843 |
| 844 //===================== InitiateUploadExistingFileRequest ==================== | 844 //===================== InitiateUploadExistingFileRequest ==================== |
| 845 | 845 |
| 846 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest( | 846 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest( |
| 847 RequestSender* sender, | 847 RequestSender* sender, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 if (!last_viewed_by_me_date_.is_null()) { | 899 if (!last_viewed_by_me_date_.is_null()) { |
| 900 root.SetString("lastViewedByMeDate", | 900 root.SetString("lastViewedByMeDate", |
| 901 util::FormatTimeAsString(last_viewed_by_me_date_)); | 901 util::FormatTimeAsString(last_viewed_by_me_date_)); |
| 902 } | 902 } |
| 903 | 903 |
| 904 AttachProperties(properties_, &root); | 904 AttachProperties(properties_, &root); |
| 905 if (root.empty()) | 905 if (root.empty()) |
| 906 return false; | 906 return false; |
| 907 | 907 |
| 908 *upload_content_type = util::kContentTypeApplicationJson; | 908 *upload_content_type = util::kContentTypeApplicationJson; |
| 909 base::JSONWriter::Write(&root, upload_content); | 909 base::JSONWriter::Write(root, upload_content); |
| 910 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type | 910 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type |
| 911 << ", [" << *upload_content << "]"; | 911 << ", [" << *upload_content << "]"; |
| 912 return true; | 912 return true; |
| 913 } | 913 } |
| 914 | 914 |
| 915 //============================ ResumeUploadRequest =========================== | 915 //============================ ResumeUploadRequest =========================== |
| 916 | 916 |
| 917 ResumeUploadRequest::ResumeUploadRequest( | 917 ResumeUploadRequest::ResumeUploadRequest( |
| 918 RequestSender* sender, | 918 RequestSender* sender, |
| 919 const GURL& upload_location, | 919 const GURL& upload_location, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 case PERMISSION_ROLE_COMMENTER: | 1151 case PERMISSION_ROLE_COMMENTER: |
| 1152 root.SetString("role", "reader"); | 1152 root.SetString("role", "reader"); |
| 1153 { | 1153 { |
| 1154 base::ListValue* list = new base::ListValue; | 1154 base::ListValue* list = new base::ListValue; |
| 1155 list->AppendString("commenter"); | 1155 list->AppendString("commenter"); |
| 1156 root.Set("additionalRoles", list); | 1156 root.Set("additionalRoles", list); |
| 1157 } | 1157 } |
| 1158 break; | 1158 break; |
| 1159 } | 1159 } |
| 1160 root.SetString("value", value_); | 1160 root.SetString("value", value_); |
| 1161 base::JSONWriter::Write(&root, upload_content); | 1161 base::JSONWriter::Write(root, upload_content); |
| 1162 return true; | 1162 return true; |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 //======================= SingleBatchableDelegateRequest ======================= | 1165 //======================= SingleBatchableDelegateRequest ======================= |
| 1166 | 1166 |
| 1167 SingleBatchableDelegateRequest::SingleBatchableDelegateRequest( | 1167 SingleBatchableDelegateRequest::SingleBatchableDelegateRequest( |
| 1168 RequestSender* sender, | 1168 RequestSender* sender, |
| 1169 BatchableDelegate* delegate) | 1169 BatchableDelegate* delegate) |
| 1170 : UrlFetchRequestBase(sender), | 1170 : UrlFetchRequestBase(sender), |
| 1171 delegate_(delegate), | 1171 delegate_(delegate), |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 } else if (last_progress_value_ < child->data_offset + child->data_size && | 1435 } else if (last_progress_value_ < child->data_offset + child->data_size && |
| 1436 child->data_offset + child->data_size < current) { | 1436 child->data_offset + child->data_size < current) { |
| 1437 child->request->NotifyUploadProgress(source, child->data_size, | 1437 child->request->NotifyUploadProgress(source, child->data_size, |
| 1438 child->data_size); | 1438 child->data_size); |
| 1439 } | 1439 } |
| 1440 } | 1440 } |
| 1441 last_progress_value_ = current; | 1441 last_progress_value_ = current; |
| 1442 } | 1442 } |
| 1443 } // namespace drive | 1443 } // namespace drive |
| 1444 } // namespace google_apis | 1444 } // namespace google_apis |
| OLD | NEW |