diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 07:25:42 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 07:25:42 +0000 |
commit | 54facd633172b6d39c4f22edd9b976a39f468c45 (patch) | |
tree | c66e3d287dc23ab4084fd0a9ccb97d5078eed479 /google_apis/drive/drive_api_requests.cc | |
parent | 9bd35ea58e998fd1405579c61e06fe23225a0aa9 (diff) | |
download | chromium_src-54facd633172b6d39c4f22edd9b976a39f468c45.zip chromium_src-54facd633172b6d39c4f22edd9b976a39f468c45.tar.gz chromium_src-54facd633172b6d39c4f22edd9b976a39f468c45.tar.bz2 |
drive: Add metadata parameters to InitiateUpload* methods
It is allowed to send metadata and file contents at the same time with Drive API.
BUG=260539
TEST=unit_tests
Review URL: https://codereview.chromium.org/139153006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/drive/drive_api_requests.cc')
-rw-r--r-- | google_apis/drive/drive_api_requests.cc | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc index 79ef01a..25d7be1 100644 --- a/google_apis/drive/drive_api_requests.cc +++ b/google_apis/drive/drive_api_requests.cc @@ -113,6 +113,15 @@ void ParseFileResourceWithUploadRangeAndRun( callback.Run(response, file_resource.Pass()); } +// Creates a Parents value which can be used as a part of request body. +scoped_ptr<base::DictionaryValue> CreateParentValue( + const std::string& file_id) { + scoped_ptr<base::DictionaryValue> parent(new base::DictionaryValue); + parent->SetString("kind", kParentLinkKind); + parent->SetString("id", file_id); + return parent.Pass(); +} + } // namespace namespace drive { @@ -602,7 +611,7 @@ InitiateUploadNewFileRequest::InitiateUploadNewFileRequest( InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() {} GURL InitiateUploadNewFileRequest::GetURL() const { - return url_generator_.GetInitiateUploadNewFileUrl(); + return url_generator_.GetInitiateUploadNewFileUrl(!modified_date_.is_null()); } net::URLFetcher::RequestType @@ -619,15 +628,16 @@ bool InitiateUploadNewFileRequest::GetContentData( root.SetString("title", title_); // Fill parent link. - { - scoped_ptr<base::DictionaryValue> parent(new base::DictionaryValue); - parent->SetString("kind", kParentLinkKind); - parent->SetString("id", parent_resource_id_); + scoped_ptr<base::ListValue> parents(new base::ListValue); + parents->Append(CreateParentValue(parent_resource_id_).release()); + root.Set("parents", parents.release()); - scoped_ptr<base::ListValue> parents(new base::ListValue); - parents->Append(parent.release()); + if (!modified_date_.is_null()) + root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); - root.Set("parents", parents.release()); + if (!last_viewed_by_me_date_.is_null()) { + root.SetString("lastViewedByMeDate", + util::FormatTimeAsString(last_viewed_by_me_date_)); } base::JSONWriter::Write(&root, upload_content); @@ -659,7 +669,8 @@ InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest( InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() {} GURL InitiateUploadExistingFileRequest::GetURL() const { - return url_generator_.GetInitiateUploadExistingFileUrl(resource_id_); + return url_generator_.GetInitiateUploadExistingFileUrl( + resource_id_, !modified_date_.is_null()); } net::URLFetcher::RequestType @@ -675,6 +686,37 @@ InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const { return headers; } +bool InitiateUploadExistingFileRequest::GetContentData( + std::string* upload_content_type, + std::string* upload_content) { + base::DictionaryValue root; + if (!parent_resource_id_.empty()) { + scoped_ptr<base::ListValue> parents(new base::ListValue); + parents->Append(CreateParentValue(parent_resource_id_).release()); + root.Set("parents", parents.release()); + } + + if (!title_.empty()) + root.SetString("title", title_); + + if (!modified_date_.is_null()) + root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); + + if (!last_viewed_by_me_date_.is_null()) { + root.SetString("lastViewedByMeDate", + util::FormatTimeAsString(last_viewed_by_me_date_)); + } + + if (root.empty()) + return false; + + *upload_content_type = kContentTypeApplicationJson; + base::JSONWriter::Write(&root, upload_content); + DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type + << ", [" << *upload_content << "]"; + return true; +} + //============================ ResumeUploadRequest =========================== ResumeUploadRequest::ResumeUploadRequest( |