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
3 // found in the LICENSE file.
5 #include "google_apis/drive/drive_api_requests.h"
8 #include "base/callback.h"
9 #include "base/json/json_writer.h"
10 #include "base/location.h"
11 #include "base/sequenced_task_runner.h"
12 #include "base/task_runner_util.h"
13 #include "base/values.h"
14 #include "google_apis/drive/request_sender.h"
15 #include "google_apis/drive/request_util.h"
16 #include "google_apis/drive/time_util.h"
17 #include "net/base/url_util.h"
19 namespace google_apis
{
22 // Parses the JSON value to FileResource instance and runs |callback| on the
23 // UI thread once parsing is done.
24 // This is customized version of ParseJsonAndRun defined above to adapt the
25 // remaining response type.
26 void ParseFileResourceWithUploadRangeAndRun(
27 const drive::UploadRangeCallback
& callback
,
28 const UploadRangeResponse
& response
,
29 scoped_ptr
<base::Value
> value
) {
30 DCHECK(!callback
.is_null());
32 scoped_ptr
<FileResource
> file_resource
;
34 file_resource
= FileResource::CreateFrom(*value
);
37 UploadRangeResponse(GDATA_PARSE_ERROR
,
38 response
.start_position_received
,
39 response
.end_position_received
),
40 scoped_ptr
<FileResource
>());
45 callback
.Run(response
, file_resource
.Pass());
52 //============================ DriveApiPartialFieldRequest ====================
54 DriveApiPartialFieldRequest::DriveApiPartialFieldRequest(
55 RequestSender
* sender
) : UrlFetchRequestBase(sender
) {
58 DriveApiPartialFieldRequest::~DriveApiPartialFieldRequest() {
61 GURL
DriveApiPartialFieldRequest::GetURL() const {
62 GURL url
= GetURLInternal();
64 url
= net::AppendOrReplaceQueryParameter(url
, "fields", fields_
);
68 //=============================== FilesGetRequest =============================
70 FilesGetRequest::FilesGetRequest(
71 RequestSender
* sender
,
72 const DriveApiUrlGenerator
& url_generator
,
73 bool use_internal_endpoint
,
74 const FileResourceCallback
& callback
)
75 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
76 url_generator_(url_generator
),
77 use_internal_endpoint_(use_internal_endpoint
) {
78 DCHECK(!callback
.is_null());
81 FilesGetRequest::~FilesGetRequest() {}
83 GURL
FilesGetRequest::GetURLInternal() const {
84 return url_generator_
.GetFilesGetUrl(file_id_
,
85 use_internal_endpoint_
,
89 //============================ FilesAuthorizeRequest ===========================
91 FilesAuthorizeRequest::FilesAuthorizeRequest(
92 RequestSender
* sender
,
93 const DriveApiUrlGenerator
& url_generator
,
94 const FileResourceCallback
& callback
)
95 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
96 url_generator_(url_generator
) {
97 DCHECK(!callback
.is_null());
100 FilesAuthorizeRequest::~FilesAuthorizeRequest() {}
102 net::URLFetcher::RequestType
FilesAuthorizeRequest::GetRequestType() const {
103 return net::URLFetcher::POST
;
106 GURL
FilesAuthorizeRequest::GetURLInternal() const {
107 return url_generator_
.GetFilesAuthorizeUrl(file_id_
, app_id_
);
110 //============================ FilesInsertRequest ============================
112 FilesInsertRequest::FilesInsertRequest(
113 RequestSender
* sender
,
114 const DriveApiUrlGenerator
& url_generator
,
115 const FileResourceCallback
& callback
)
116 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
117 url_generator_(url_generator
) {
118 DCHECK(!callback
.is_null());
121 FilesInsertRequest::~FilesInsertRequest() {}
123 net::URLFetcher::RequestType
FilesInsertRequest::GetRequestType() const {
124 return net::URLFetcher::POST
;
127 bool FilesInsertRequest::GetContentData(std::string
* upload_content_type
,
128 std::string
* upload_content
) {
129 *upload_content_type
= util::kContentTypeApplicationJson
;
131 base::DictionaryValue root
;
133 if (!last_viewed_by_me_date_
.is_null()) {
134 root
.SetString("lastViewedByMeDate",
135 util::FormatTimeAsString(last_viewed_by_me_date_
));
138 if (!mime_type_
.empty())
139 root
.SetString("mimeType", mime_type_
);
141 if (!modified_date_
.is_null())
142 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
144 if (!parents_
.empty()) {
145 base::ListValue
* parents_value
= new base::ListValue
;
146 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
147 base::DictionaryValue
* parent
= new base::DictionaryValue
;
148 parent
->SetString("id", parents_
[i
]);
149 parents_value
->Append(parent
);
151 root
.Set("parents", parents_value
);
155 root
.SetString("title", title_
);
157 base::JSONWriter::Write(&root
, upload_content
);
158 DVLOG(1) << "FilesInsert data: " << *upload_content_type
<< ", ["
159 << *upload_content
<< "]";
163 GURL
FilesInsertRequest::GetURLInternal() const {
164 return url_generator_
.GetFilesInsertUrl();
167 //============================== FilesPatchRequest ============================
169 FilesPatchRequest::FilesPatchRequest(
170 RequestSender
* sender
,
171 const DriveApiUrlGenerator
& url_generator
,
172 const FileResourceCallback
& callback
)
173 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
174 url_generator_(url_generator
),
175 set_modified_date_(false),
176 update_viewed_date_(true) {
177 DCHECK(!callback
.is_null());
180 FilesPatchRequest::~FilesPatchRequest() {}
182 net::URLFetcher::RequestType
FilesPatchRequest::GetRequestType() const {
183 return net::URLFetcher::PATCH
;
186 std::vector
<std::string
> FilesPatchRequest::GetExtraRequestHeaders() const {
187 std::vector
<std::string
> headers
;
188 headers
.push_back(util::kIfMatchAllHeader
);
192 GURL
FilesPatchRequest::GetURLInternal() const {
193 return url_generator_
.GetFilesPatchUrl(
194 file_id_
, set_modified_date_
, update_viewed_date_
);
197 bool FilesPatchRequest::GetContentData(std::string
* upload_content_type
,
198 std::string
* upload_content
) {
199 if (title_
.empty() &&
200 modified_date_
.is_null() &&
201 last_viewed_by_me_date_
.is_null() &&
205 *upload_content_type
= util::kContentTypeApplicationJson
;
207 base::DictionaryValue root
;
209 root
.SetString("title", title_
);
211 if (!modified_date_
.is_null())
212 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
214 if (!last_viewed_by_me_date_
.is_null()) {
215 root
.SetString("lastViewedByMeDate",
216 util::FormatTimeAsString(last_viewed_by_me_date_
));
219 if (!parents_
.empty()) {
220 base::ListValue
* parents_value
= new base::ListValue
;
221 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
222 base::DictionaryValue
* parent
= new base::DictionaryValue
;
223 parent
->SetString("id", parents_
[i
]);
224 parents_value
->Append(parent
);
226 root
.Set("parents", parents_value
);
229 base::JSONWriter::Write(&root
, upload_content
);
230 DVLOG(1) << "FilesPatch data: " << *upload_content_type
<< ", ["
231 << *upload_content
<< "]";
235 //============================= FilesCopyRequest ==============================
237 FilesCopyRequest::FilesCopyRequest(
238 RequestSender
* sender
,
239 const DriveApiUrlGenerator
& url_generator
,
240 const FileResourceCallback
& callback
)
241 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
242 url_generator_(url_generator
) {
243 DCHECK(!callback
.is_null());
246 FilesCopyRequest::~FilesCopyRequest() {
249 net::URLFetcher::RequestType
FilesCopyRequest::GetRequestType() const {
250 return net::URLFetcher::POST
;
253 GURL
FilesCopyRequest::GetURLInternal() const {
254 return url_generator_
.GetFilesCopyUrl(file_id_
);
257 bool FilesCopyRequest::GetContentData(std::string
* upload_content_type
,
258 std::string
* upload_content
) {
259 if (parents_
.empty() && title_
.empty())
262 *upload_content_type
= util::kContentTypeApplicationJson
;
264 base::DictionaryValue root
;
266 if (!modified_date_
.is_null())
267 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
269 if (!parents_
.empty()) {
270 base::ListValue
* parents_value
= new base::ListValue
;
271 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
272 base::DictionaryValue
* parent
= new base::DictionaryValue
;
273 parent
->SetString("id", parents_
[i
]);
274 parents_value
->Append(parent
);
276 root
.Set("parents", parents_value
);
280 root
.SetString("title", title_
);
282 base::JSONWriter::Write(&root
, upload_content
);
283 DVLOG(1) << "FilesCopy data: " << *upload_content_type
<< ", ["
284 << *upload_content
<< "]";
288 //============================= FilesListRequest =============================
290 FilesListRequest::FilesListRequest(
291 RequestSender
* sender
,
292 const DriveApiUrlGenerator
& url_generator
,
293 const FileListCallback
& callback
)
294 : DriveApiDataRequest
<FileList
>(sender
, callback
),
295 url_generator_(url_generator
),
297 DCHECK(!callback
.is_null());
300 FilesListRequest::~FilesListRequest() {}
302 GURL
FilesListRequest::GetURLInternal() const {
303 return url_generator_
.GetFilesListUrl(max_results_
, page_token_
, q_
);
306 //======================== FilesListNextPageRequest =========================
308 FilesListNextPageRequest::FilesListNextPageRequest(
309 RequestSender
* sender
,
310 const FileListCallback
& callback
)
311 : DriveApiDataRequest
<FileList
>(sender
, callback
) {
312 DCHECK(!callback
.is_null());
315 FilesListNextPageRequest::~FilesListNextPageRequest() {
318 GURL
FilesListNextPageRequest::GetURLInternal() const {
322 //============================ FilesDeleteRequest =============================
324 FilesDeleteRequest::FilesDeleteRequest(
325 RequestSender
* sender
,
326 const DriveApiUrlGenerator
& url_generator
,
327 const EntryActionCallback
& callback
)
328 : EntryActionRequest(sender
, callback
),
329 url_generator_(url_generator
) {
330 DCHECK(!callback
.is_null());
333 FilesDeleteRequest::~FilesDeleteRequest() {}
335 net::URLFetcher::RequestType
FilesDeleteRequest::GetRequestType() const {
336 return net::URLFetcher::DELETE_REQUEST
;
339 GURL
FilesDeleteRequest::GetURL() const {
340 return url_generator_
.GetFilesDeleteUrl(file_id_
);
343 std::vector
<std::string
> FilesDeleteRequest::GetExtraRequestHeaders() const {
344 std::vector
<std::string
> headers(
345 EntryActionRequest::GetExtraRequestHeaders());
346 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
350 //============================ FilesTrashRequest =============================
352 FilesTrashRequest::FilesTrashRequest(
353 RequestSender
* sender
,
354 const DriveApiUrlGenerator
& url_generator
,
355 const FileResourceCallback
& callback
)
356 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
357 url_generator_(url_generator
) {
358 DCHECK(!callback
.is_null());
361 FilesTrashRequest::~FilesTrashRequest() {}
363 net::URLFetcher::RequestType
FilesTrashRequest::GetRequestType() const {
364 return net::URLFetcher::POST
;
367 GURL
FilesTrashRequest::GetURLInternal() const {
368 return url_generator_
.GetFilesTrashUrl(file_id_
);
371 //============================== AboutGetRequest =============================
373 AboutGetRequest::AboutGetRequest(
374 RequestSender
* sender
,
375 const DriveApiUrlGenerator
& url_generator
,
376 const AboutResourceCallback
& callback
)
377 : DriveApiDataRequest
<AboutResource
>(sender
, callback
),
378 url_generator_(url_generator
) {
379 DCHECK(!callback
.is_null());
382 AboutGetRequest::~AboutGetRequest() {}
384 GURL
AboutGetRequest::GetURLInternal() const {
385 return url_generator_
.GetAboutGetUrl();
388 //============================ ChangesListRequest ===========================
390 ChangesListRequest::ChangesListRequest(
391 RequestSender
* sender
,
392 const DriveApiUrlGenerator
& url_generator
,
393 const ChangeListCallback
& callback
)
394 : DriveApiDataRequest
<ChangeList
>(sender
, callback
),
395 url_generator_(url_generator
),
396 include_deleted_(true),
398 start_change_id_(0) {
399 DCHECK(!callback
.is_null());
402 ChangesListRequest::~ChangesListRequest() {}
404 GURL
ChangesListRequest::GetURLInternal() const {
405 return url_generator_
.GetChangesListUrl(
406 include_deleted_
, max_results_
, page_token_
, start_change_id_
);
409 //======================== ChangesListNextPageRequest =========================
411 ChangesListNextPageRequest::ChangesListNextPageRequest(
412 RequestSender
* sender
,
413 const ChangeListCallback
& callback
)
414 : DriveApiDataRequest
<ChangeList
>(sender
, callback
) {
415 DCHECK(!callback
.is_null());
418 ChangesListNextPageRequest::~ChangesListNextPageRequest() {
421 GURL
ChangesListNextPageRequest::GetURLInternal() const {
425 //============================== AppsListRequest ===========================
427 AppsListRequest::AppsListRequest(
428 RequestSender
* sender
,
429 const DriveApiUrlGenerator
& url_generator
,
430 bool use_internal_endpoint
,
431 const AppListCallback
& callback
)
432 : DriveApiDataRequest
<AppList
>(sender
, callback
),
433 url_generator_(url_generator
),
434 use_internal_endpoint_(use_internal_endpoint
) {
435 DCHECK(!callback
.is_null());
438 AppsListRequest::~AppsListRequest() {}
440 GURL
AppsListRequest::GetURLInternal() const {
441 return url_generator_
.GetAppsListUrl(use_internal_endpoint_
);
444 //============================== AppsDeleteRequest ===========================
446 AppsDeleteRequest::AppsDeleteRequest(RequestSender
* sender
,
447 const DriveApiUrlGenerator
& url_generator
,
448 const EntryActionCallback
& callback
)
449 : EntryActionRequest(sender
, callback
),
450 url_generator_(url_generator
) {
451 DCHECK(!callback
.is_null());
454 AppsDeleteRequest::~AppsDeleteRequest() {}
456 net::URLFetcher::RequestType
AppsDeleteRequest::GetRequestType() const {
457 return net::URLFetcher::DELETE_REQUEST
;
460 GURL
AppsDeleteRequest::GetURL() const {
461 return url_generator_
.GetAppsDeleteUrl(app_id_
);
464 //========================== ChildrenInsertRequest ============================
466 ChildrenInsertRequest::ChildrenInsertRequest(
467 RequestSender
* sender
,
468 const DriveApiUrlGenerator
& url_generator
,
469 const EntryActionCallback
& callback
)
470 : EntryActionRequest(sender
, callback
),
471 url_generator_(url_generator
) {
472 DCHECK(!callback
.is_null());
475 ChildrenInsertRequest::~ChildrenInsertRequest() {}
477 net::URLFetcher::RequestType
ChildrenInsertRequest::GetRequestType() const {
478 return net::URLFetcher::POST
;
481 GURL
ChildrenInsertRequest::GetURL() const {
482 return url_generator_
.GetChildrenInsertUrl(folder_id_
);
485 bool ChildrenInsertRequest::GetContentData(std::string
* upload_content_type
,
486 std::string
* upload_content
) {
487 *upload_content_type
= util::kContentTypeApplicationJson
;
489 base::DictionaryValue root
;
490 root
.SetString("id", id_
);
492 base::JSONWriter::Write(&root
, upload_content
);
493 DVLOG(1) << "InsertResource data: " << *upload_content_type
<< ", ["
494 << *upload_content
<< "]";
498 //========================== ChildrenDeleteRequest ============================
500 ChildrenDeleteRequest::ChildrenDeleteRequest(
501 RequestSender
* sender
,
502 const DriveApiUrlGenerator
& url_generator
,
503 const EntryActionCallback
& callback
)
504 : EntryActionRequest(sender
, callback
),
505 url_generator_(url_generator
) {
506 DCHECK(!callback
.is_null());
509 ChildrenDeleteRequest::~ChildrenDeleteRequest() {}
511 net::URLFetcher::RequestType
ChildrenDeleteRequest::GetRequestType() const {
512 return net::URLFetcher::DELETE_REQUEST
;
515 GURL
ChildrenDeleteRequest::GetURL() const {
516 return url_generator_
.GetChildrenDeleteUrl(child_id_
, folder_id_
);
519 //======================= InitiateUploadNewFileRequest =======================
521 InitiateUploadNewFileRequest::InitiateUploadNewFileRequest(
522 RequestSender
* sender
,
523 const DriveApiUrlGenerator
& url_generator
,
524 const std::string
& content_type
,
525 int64 content_length
,
526 const std::string
& parent_resource_id
,
527 const std::string
& title
,
528 const InitiateUploadCallback
& callback
)
529 : InitiateUploadRequestBase(sender
,
533 url_generator_(url_generator
),
534 parent_resource_id_(parent_resource_id
),
538 InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() {}
540 GURL
InitiateUploadNewFileRequest::GetURL() const {
541 return url_generator_
.GetInitiateUploadNewFileUrl(!modified_date_
.is_null());
544 net::URLFetcher::RequestType
545 InitiateUploadNewFileRequest::GetRequestType() const {
546 return net::URLFetcher::POST
;
549 bool InitiateUploadNewFileRequest::GetContentData(
550 std::string
* upload_content_type
,
551 std::string
* upload_content
) {
552 *upload_content_type
= util::kContentTypeApplicationJson
;
554 base::DictionaryValue root
;
555 root
.SetString("title", title_
);
558 scoped_ptr
<base::ListValue
> parents(new base::ListValue
);
559 parents
->Append(util::CreateParentValue(parent_resource_id_
).release());
560 root
.Set("parents", parents
.release());
562 if (!modified_date_
.is_null())
563 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
565 if (!last_viewed_by_me_date_
.is_null()) {
566 root
.SetString("lastViewedByMeDate",
567 util::FormatTimeAsString(last_viewed_by_me_date_
));
570 base::JSONWriter::Write(&root
, upload_content
);
572 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type
<< ", ["
573 << *upload_content
<< "]";
577 //===================== InitiateUploadExistingFileRequest ====================
579 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest(
580 RequestSender
* sender
,
581 const DriveApiUrlGenerator
& url_generator
,
582 const std::string
& content_type
,
583 int64 content_length
,
584 const std::string
& resource_id
,
585 const std::string
& etag
,
586 const InitiateUploadCallback
& callback
)
587 : InitiateUploadRequestBase(sender
,
591 url_generator_(url_generator
),
592 resource_id_(resource_id
),
596 InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() {}
598 GURL
InitiateUploadExistingFileRequest::GetURL() const {
599 return url_generator_
.GetInitiateUploadExistingFileUrl(
600 resource_id_
, !modified_date_
.is_null());
603 net::URLFetcher::RequestType
604 InitiateUploadExistingFileRequest::GetRequestType() const {
605 return net::URLFetcher::PUT
;
608 std::vector
<std::string
>
609 InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const {
610 std::vector
<std::string
> headers(
611 InitiateUploadRequestBase::GetExtraRequestHeaders());
612 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
616 bool InitiateUploadExistingFileRequest::GetContentData(
617 std::string
* upload_content_type
,
618 std::string
* upload_content
) {
619 base::DictionaryValue root
;
620 if (!parent_resource_id_
.empty()) {
621 scoped_ptr
<base::ListValue
> parents(new base::ListValue
);
622 parents
->Append(util::CreateParentValue(parent_resource_id_
).release());
623 root
.Set("parents", parents
.release());
627 root
.SetString("title", title_
);
629 if (!modified_date_
.is_null())
630 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
632 if (!last_viewed_by_me_date_
.is_null()) {
633 root
.SetString("lastViewedByMeDate",
634 util::FormatTimeAsString(last_viewed_by_me_date_
));
640 *upload_content_type
= util::kContentTypeApplicationJson
;
641 base::JSONWriter::Write(&root
, upload_content
);
642 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type
643 << ", [" << *upload_content
<< "]";
647 //============================ ResumeUploadRequest ===========================
649 ResumeUploadRequest::ResumeUploadRequest(
650 RequestSender
* sender
,
651 const GURL
& upload_location
,
652 int64 start_position
,
654 int64 content_length
,
655 const std::string
& content_type
,
656 const base::FilePath
& local_file_path
,
657 const UploadRangeCallback
& callback
,
658 const ProgressCallback
& progress_callback
)
659 : ResumeUploadRequestBase(sender
,
667 progress_callback_(progress_callback
) {
668 DCHECK(!callback_
.is_null());
671 ResumeUploadRequest::~ResumeUploadRequest() {}
673 void ResumeUploadRequest::OnRangeRequestComplete(
674 const UploadRangeResponse
& response
,
675 scoped_ptr
<base::Value
> value
) {
676 DCHECK(CalledOnValidThread());
677 ParseFileResourceWithUploadRangeAndRun(callback_
, response
, value
.Pass());
680 void ResumeUploadRequest::OnURLFetchUploadProgress(
681 const net::URLFetcher
* source
, int64 current
, int64 total
) {
682 if (!progress_callback_
.is_null())
683 progress_callback_
.Run(current
, total
);
686 //========================== GetUploadStatusRequest ==========================
688 GetUploadStatusRequest::GetUploadStatusRequest(
689 RequestSender
* sender
,
690 const GURL
& upload_url
,
691 int64 content_length
,
692 const UploadRangeCallback
& callback
)
693 : GetUploadStatusRequestBase(sender
,
696 callback_(callback
) {
697 DCHECK(!callback
.is_null());
700 GetUploadStatusRequest::~GetUploadStatusRequest() {}
702 void GetUploadStatusRequest::OnRangeRequestComplete(
703 const UploadRangeResponse
& response
,
704 scoped_ptr
<base::Value
> value
) {
705 DCHECK(CalledOnValidThread());
706 ParseFileResourceWithUploadRangeAndRun(callback_
, response
, value
.Pass());
709 //======================= MultipartUploadNewFileRequest =======================
711 MultipartUploadNewFileRequest::MultipartUploadNewFileRequest(
712 RequestSender
* sender
,
713 const std::string
& title
,
714 const std::string
& parent_resource_id
,
715 const std::string
& content_type
,
716 int64 content_length
,
717 const base::Time
& modified_date
,
718 const base::Time
& last_viewed_by_me_date
,
719 const base::FilePath
& local_file_path
,
720 const DriveApiUrlGenerator
& url_generator
,
721 const FileResourceCallback
& callback
,
722 const ProgressCallback
& progress_callback
)
723 : MultipartUploadRequestBase(sender
,
729 last_viewed_by_me_date
,
733 url_generator_(url_generator
) {
736 MultipartUploadNewFileRequest::~MultipartUploadNewFileRequest() {
739 GURL
MultipartUploadNewFileRequest::GetURL() const {
740 return url_generator_
.GetMultipartUploadNewFileUrl(has_modified_date());
743 net::URLFetcher::RequestType
MultipartUploadNewFileRequest::GetRequestType()
745 return net::URLFetcher::POST
;
748 //======================= MultipartUploadExistingFileRequest ===================
750 MultipartUploadExistingFileRequest::MultipartUploadExistingFileRequest(
751 RequestSender
* sender
,
752 const std::string
& title
,
753 const std::string
& resource_id
,
754 const std::string
& parent_resource_id
,
755 const std::string
& content_type
,
756 int64 content_length
,
757 const base::Time
& modified_date
,
758 const base::Time
& last_viewed_by_me_date
,
759 const base::FilePath
& local_file_path
,
760 const std::string
& etag
,
761 const DriveApiUrlGenerator
& url_generator
,
762 const FileResourceCallback
& callback
,
763 const ProgressCallback
& progress_callback
)
764 : MultipartUploadRequestBase(sender
,
770 last_viewed_by_me_date
,
774 resource_id_(resource_id
),
776 url_generator_(url_generator
) {
779 MultipartUploadExistingFileRequest::~MultipartUploadExistingFileRequest() {
782 std::vector
<std::string
>
783 MultipartUploadExistingFileRequest::GetExtraRequestHeaders() const {
784 std::vector
<std::string
> headers(
785 MultipartUploadRequestBase::GetExtraRequestHeaders());
786 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
790 GURL
MultipartUploadExistingFileRequest::GetURL() const {
791 return url_generator_
.GetMultipartUploadExistingFileUrl(
792 resource_id_
, has_modified_date());
795 net::URLFetcher::RequestType
796 MultipartUploadExistingFileRequest::GetRequestType() const {
797 return net::URLFetcher::PUT
;
800 //========================== DownloadFileRequest ==========================
802 DownloadFileRequest::DownloadFileRequest(
803 RequestSender
* sender
,
804 const DriveApiUrlGenerator
& url_generator
,
805 const std::string
& resource_id
,
806 const base::FilePath
& output_file_path
,
807 const DownloadActionCallback
& download_action_callback
,
808 const GetContentCallback
& get_content_callback
,
809 const ProgressCallback
& progress_callback
)
810 : DownloadFileRequestBase(
812 download_action_callback
,
813 get_content_callback
,
815 url_generator
.GenerateDownloadFileUrl(resource_id
),
819 DownloadFileRequest::~DownloadFileRequest() {
822 //========================== PermissionsInsertRequest ==========================
824 PermissionsInsertRequest::PermissionsInsertRequest(
825 RequestSender
* sender
,
826 const DriveApiUrlGenerator
& url_generator
,
827 const EntryActionCallback
& callback
)
828 : EntryActionRequest(sender
, callback
),
829 url_generator_(url_generator
),
830 type_(PERMISSION_TYPE_USER
),
831 role_(PERMISSION_ROLE_READER
) {
834 PermissionsInsertRequest::~PermissionsInsertRequest() {
837 GURL
PermissionsInsertRequest::GetURL() const {
838 return url_generator_
.GetPermissionsInsertUrl(id_
);
841 net::URLFetcher::RequestType
842 PermissionsInsertRequest::GetRequestType() const {
843 return net::URLFetcher::POST
;
846 bool PermissionsInsertRequest::GetContentData(std::string
* upload_content_type
,
847 std::string
* upload_content
) {
848 *upload_content_type
= util::kContentTypeApplicationJson
;
850 base::DictionaryValue root
;
852 case PERMISSION_TYPE_ANYONE
:
853 root
.SetString("type", "anyone");
855 case PERMISSION_TYPE_DOMAIN
:
856 root
.SetString("type", "domain");
858 case PERMISSION_TYPE_GROUP
:
859 root
.SetString("type", "group");
861 case PERMISSION_TYPE_USER
:
862 root
.SetString("type", "user");
866 case PERMISSION_ROLE_OWNER
:
867 root
.SetString("role", "owner");
869 case PERMISSION_ROLE_READER
:
870 root
.SetString("role", "reader");
872 case PERMISSION_ROLE_WRITER
:
873 root
.SetString("role", "writer");
875 case PERMISSION_ROLE_COMMENTER
:
876 root
.SetString("role", "reader");
878 base::ListValue
* list
= new base::ListValue
;
879 list
->AppendString("commenter");
880 root
.Set("additionalRoles", list
);
884 root
.SetString("value", value_
);
885 base::JSONWriter::Write(&root
, upload_content
);
890 } // namespace google_apis