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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 response.start_position_received, | 106 response.start_position_received, |
107 response.end_position_received), | 107 response.end_position_received), |
108 scoped_ptr<FileResource>()); | 108 scoped_ptr<FileResource>()); |
109 return; | 109 return; |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 callback.Run(response, file_resource.Pass()); | 113 callback.Run(response, file_resource.Pass()); |
114 } | 114 } |
115 | 115 |
| 116 // Creates a Parents value which can be used as a part of request body. |
| 117 scoped_ptr<base::DictionaryValue> CreateParentValue( |
| 118 const std::string& file_id) { |
| 119 scoped_ptr<base::DictionaryValue> parent(new base::DictionaryValue); |
| 120 parent->SetString("kind", kParentLinkKind); |
| 121 parent->SetString("id", file_id); |
| 122 return parent.Pass(); |
| 123 } |
| 124 |
116 } // namespace | 125 } // namespace |
117 | 126 |
118 namespace drive { | 127 namespace drive { |
119 | 128 |
120 //============================ DriveApiDataRequest =========================== | 129 //============================ DriveApiDataRequest =========================== |
121 | 130 |
122 DriveApiDataRequest::DriveApiDataRequest(RequestSender* sender, | 131 DriveApiDataRequest::DriveApiDataRequest(RequestSender* sender, |
123 const GetDataCallback& callback) | 132 const GetDataCallback& callback) |
124 : GetDataRequest(sender, callback) { | 133 : GetDataRequest(sender, callback) { |
125 } | 134 } |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 content_type, | 604 content_type, |
596 content_length), | 605 content_length), |
597 url_generator_(url_generator), | 606 url_generator_(url_generator), |
598 parent_resource_id_(parent_resource_id), | 607 parent_resource_id_(parent_resource_id), |
599 title_(title) { | 608 title_(title) { |
600 } | 609 } |
601 | 610 |
602 InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() {} | 611 InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() {} |
603 | 612 |
604 GURL InitiateUploadNewFileRequest::GetURL() const { | 613 GURL InitiateUploadNewFileRequest::GetURL() const { |
605 return url_generator_.GetInitiateUploadNewFileUrl(); | 614 return url_generator_.GetInitiateUploadNewFileUrl(!modified_date_.is_null()); |
606 } | 615 } |
607 | 616 |
608 net::URLFetcher::RequestType | 617 net::URLFetcher::RequestType |
609 InitiateUploadNewFileRequest::GetRequestType() const { | 618 InitiateUploadNewFileRequest::GetRequestType() const { |
610 return net::URLFetcher::POST; | 619 return net::URLFetcher::POST; |
611 } | 620 } |
612 | 621 |
613 bool InitiateUploadNewFileRequest::GetContentData( | 622 bool InitiateUploadNewFileRequest::GetContentData( |
614 std::string* upload_content_type, | 623 std::string* upload_content_type, |
615 std::string* upload_content) { | 624 std::string* upload_content) { |
616 *upload_content_type = kContentTypeApplicationJson; | 625 *upload_content_type = kContentTypeApplicationJson; |
617 | 626 |
618 base::DictionaryValue root; | 627 base::DictionaryValue root; |
619 root.SetString("title", title_); | 628 root.SetString("title", title_); |
620 | 629 |
621 // Fill parent link. | 630 // Fill parent link. |
622 { | 631 scoped_ptr<base::ListValue> parents(new base::ListValue); |
623 scoped_ptr<base::DictionaryValue> parent(new base::DictionaryValue); | 632 parents->Append(CreateParentValue(parent_resource_id_).release()); |
624 parent->SetString("kind", kParentLinkKind); | 633 root.Set("parents", parents.release()); |
625 parent->SetString("id", parent_resource_id_); | |
626 | 634 |
627 scoped_ptr<base::ListValue> parents(new base::ListValue); | 635 if (!modified_date_.is_null()) |
628 parents->Append(parent.release()); | 636 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); |
629 | 637 |
630 root.Set("parents", parents.release()); | 638 if (!last_viewed_by_me_date_.is_null()) { |
| 639 root.SetString("lastViewedByMeDate", |
| 640 util::FormatTimeAsString(last_viewed_by_me_date_)); |
631 } | 641 } |
632 | 642 |
633 base::JSONWriter::Write(&root, upload_content); | 643 base::JSONWriter::Write(&root, upload_content); |
634 | 644 |
635 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" | 645 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type << ", [" |
636 << *upload_content << "]"; | 646 << *upload_content << "]"; |
637 return true; | 647 return true; |
638 } | 648 } |
639 | 649 |
640 //===================== InitiateUploadExistingFileRequest ==================== | 650 //===================== InitiateUploadExistingFileRequest ==================== |
(...skipping 11 matching lines...) Expand all Loading... |
652 content_type, | 662 content_type, |
653 content_length), | 663 content_length), |
654 url_generator_(url_generator), | 664 url_generator_(url_generator), |
655 resource_id_(resource_id), | 665 resource_id_(resource_id), |
656 etag_(etag) { | 666 etag_(etag) { |
657 } | 667 } |
658 | 668 |
659 InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() {} | 669 InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() {} |
660 | 670 |
661 GURL InitiateUploadExistingFileRequest::GetURL() const { | 671 GURL InitiateUploadExistingFileRequest::GetURL() const { |
662 return url_generator_.GetInitiateUploadExistingFileUrl(resource_id_); | 672 return url_generator_.GetInitiateUploadExistingFileUrl( |
| 673 resource_id_, !modified_date_.is_null()); |
663 } | 674 } |
664 | 675 |
665 net::URLFetcher::RequestType | 676 net::URLFetcher::RequestType |
666 InitiateUploadExistingFileRequest::GetRequestType() const { | 677 InitiateUploadExistingFileRequest::GetRequestType() const { |
667 return net::URLFetcher::PUT; | 678 return net::URLFetcher::PUT; |
668 } | 679 } |
669 | 680 |
670 std::vector<std::string> | 681 std::vector<std::string> |
671 InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const { | 682 InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const { |
672 std::vector<std::string> headers( | 683 std::vector<std::string> headers( |
673 InitiateUploadRequestBase::GetExtraRequestHeaders()); | 684 InitiateUploadRequestBase::GetExtraRequestHeaders()); |
674 headers.push_back(util::GenerateIfMatchHeader(etag_)); | 685 headers.push_back(util::GenerateIfMatchHeader(etag_)); |
675 return headers; | 686 return headers; |
676 } | 687 } |
677 | 688 |
| 689 bool InitiateUploadExistingFileRequest::GetContentData( |
| 690 std::string* upload_content_type, |
| 691 std::string* upload_content) { |
| 692 base::DictionaryValue root; |
| 693 if (!parent_resource_id_.empty()) { |
| 694 scoped_ptr<base::ListValue> parents(new base::ListValue); |
| 695 parents->Append(CreateParentValue(parent_resource_id_).release()); |
| 696 root.Set("parents", parents.release()); |
| 697 } |
| 698 |
| 699 if (!title_.empty()) |
| 700 root.SetString("title", title_); |
| 701 |
| 702 if (!modified_date_.is_null()) |
| 703 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); |
| 704 |
| 705 if (!last_viewed_by_me_date_.is_null()) { |
| 706 root.SetString("lastViewedByMeDate", |
| 707 util::FormatTimeAsString(last_viewed_by_me_date_)); |
| 708 } |
| 709 |
| 710 if (root.empty()) |
| 711 return false; |
| 712 |
| 713 *upload_content_type = kContentTypeApplicationJson; |
| 714 base::JSONWriter::Write(&root, upload_content); |
| 715 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type |
| 716 << ", [" << *upload_content << "]"; |
| 717 return true; |
| 718 } |
| 719 |
678 //============================ ResumeUploadRequest =========================== | 720 //============================ ResumeUploadRequest =========================== |
679 | 721 |
680 ResumeUploadRequest::ResumeUploadRequest( | 722 ResumeUploadRequest::ResumeUploadRequest( |
681 RequestSender* sender, | 723 RequestSender* sender, |
682 const GURL& upload_location, | 724 const GURL& upload_location, |
683 int64 start_position, | 725 int64 start_position, |
684 int64 end_position, | 726 int64 end_position, |
685 int64 content_length, | 727 int64 content_length, |
686 const std::string& content_type, | 728 const std::string& content_type, |
687 const base::FilePath& local_file_path, | 729 const base::FilePath& local_file_path, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 progress_callback, | 796 progress_callback, |
755 url_generator.GenerateDownloadFileUrl(resource_id), | 797 url_generator.GenerateDownloadFileUrl(resource_id), |
756 output_file_path) { | 798 output_file_path) { |
757 } | 799 } |
758 | 800 |
759 DownloadFileRequest::~DownloadFileRequest() { | 801 DownloadFileRequest::~DownloadFileRequest() { |
760 } | 802 } |
761 | 803 |
762 } // namespace drive | 804 } // namespace drive |
763 } // namespace google_apis | 805 } // namespace google_apis |
OLD | NEW |