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 const FileResourceCallback
& callback
)
74 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
75 url_generator_(url_generator
) {
76 DCHECK(!callback
.is_null());
79 FilesGetRequest::~FilesGetRequest() {}
81 GURL
FilesGetRequest::GetURLInternal() const {
82 return url_generator_
.GetFilesGetUrl(file_id_
);
85 //============================ FilesAuthorizeRequest ===========================
87 FilesAuthorizeRequest::FilesAuthorizeRequest(
88 RequestSender
* sender
,
89 const DriveApiUrlGenerator
& url_generator
,
90 const FileResourceCallback
& callback
)
91 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
92 url_generator_(url_generator
) {
93 DCHECK(!callback
.is_null());
96 FilesAuthorizeRequest::~FilesAuthorizeRequest() {}
98 net::URLFetcher::RequestType
FilesAuthorizeRequest::GetRequestType() const {
99 return net::URLFetcher::POST
;
102 GURL
FilesAuthorizeRequest::GetURLInternal() const {
103 return url_generator_
.GetFilesAuthorizeUrl(file_id_
, app_id_
);
106 //============================ FilesInsertRequest ============================
108 FilesInsertRequest::FilesInsertRequest(
109 RequestSender
* sender
,
110 const DriveApiUrlGenerator
& url_generator
,
111 const FileResourceCallback
& callback
)
112 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
113 url_generator_(url_generator
) {
114 DCHECK(!callback
.is_null());
117 FilesInsertRequest::~FilesInsertRequest() {}
119 net::URLFetcher::RequestType
FilesInsertRequest::GetRequestType() const {
120 return net::URLFetcher::POST
;
123 bool FilesInsertRequest::GetContentData(std::string
* upload_content_type
,
124 std::string
* upload_content
) {
125 *upload_content_type
= util::kContentTypeApplicationJson
;
127 base::DictionaryValue root
;
129 if (!last_viewed_by_me_date_
.is_null()) {
130 root
.SetString("lastViewedByMeDate",
131 util::FormatTimeAsString(last_viewed_by_me_date_
));
134 if (!mime_type_
.empty())
135 root
.SetString("mimeType", mime_type_
);
137 if (!modified_date_
.is_null())
138 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
140 if (!parents_
.empty()) {
141 base::ListValue
* parents_value
= new base::ListValue
;
142 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
143 base::DictionaryValue
* parent
= new base::DictionaryValue
;
144 parent
->SetString("id", parents_
[i
]);
145 parents_value
->Append(parent
);
147 root
.Set("parents", parents_value
);
151 root
.SetString("title", title_
);
153 base::JSONWriter::Write(&root
, upload_content
);
154 DVLOG(1) << "FilesInsert data: " << *upload_content_type
<< ", ["
155 << *upload_content
<< "]";
159 GURL
FilesInsertRequest::GetURLInternal() const {
160 return url_generator_
.GetFilesInsertUrl();
163 //============================== FilesPatchRequest ============================
165 FilesPatchRequest::FilesPatchRequest(
166 RequestSender
* sender
,
167 const DriveApiUrlGenerator
& url_generator
,
168 const FileResourceCallback
& callback
)
169 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
170 url_generator_(url_generator
),
171 set_modified_date_(false),
172 update_viewed_date_(true) {
173 DCHECK(!callback
.is_null());
176 FilesPatchRequest::~FilesPatchRequest() {}
178 net::URLFetcher::RequestType
FilesPatchRequest::GetRequestType() const {
179 return net::URLFetcher::PATCH
;
182 std::vector
<std::string
> FilesPatchRequest::GetExtraRequestHeaders() const {
183 std::vector
<std::string
> headers
;
184 headers
.push_back(util::kIfMatchAllHeader
);
188 GURL
FilesPatchRequest::GetURLInternal() const {
189 return url_generator_
.GetFilesPatchUrl(
190 file_id_
, set_modified_date_
, update_viewed_date_
);
193 bool FilesPatchRequest::GetContentData(std::string
* upload_content_type
,
194 std::string
* upload_content
) {
195 if (title_
.empty() &&
196 modified_date_
.is_null() &&
197 last_viewed_by_me_date_
.is_null() &&
201 *upload_content_type
= util::kContentTypeApplicationJson
;
203 base::DictionaryValue root
;
205 root
.SetString("title", title_
);
207 if (!modified_date_
.is_null())
208 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
210 if (!last_viewed_by_me_date_
.is_null()) {
211 root
.SetString("lastViewedByMeDate",
212 util::FormatTimeAsString(last_viewed_by_me_date_
));
215 if (!parents_
.empty()) {
216 base::ListValue
* parents_value
= new base::ListValue
;
217 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
218 base::DictionaryValue
* parent
= new base::DictionaryValue
;
219 parent
->SetString("id", parents_
[i
]);
220 parents_value
->Append(parent
);
222 root
.Set("parents", parents_value
);
225 base::JSONWriter::Write(&root
, upload_content
);
226 DVLOG(1) << "FilesPatch data: " << *upload_content_type
<< ", ["
227 << *upload_content
<< "]";
231 //============================= FilesCopyRequest ==============================
233 FilesCopyRequest::FilesCopyRequest(
234 RequestSender
* sender
,
235 const DriveApiUrlGenerator
& url_generator
,
236 const FileResourceCallback
& callback
)
237 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
238 url_generator_(url_generator
) {
239 DCHECK(!callback
.is_null());
242 FilesCopyRequest::~FilesCopyRequest() {
245 net::URLFetcher::RequestType
FilesCopyRequest::GetRequestType() const {
246 return net::URLFetcher::POST
;
249 GURL
FilesCopyRequest::GetURLInternal() const {
250 return url_generator_
.GetFilesCopyUrl(file_id_
);
253 bool FilesCopyRequest::GetContentData(std::string
* upload_content_type
,
254 std::string
* upload_content
) {
255 if (parents_
.empty() && title_
.empty())
258 *upload_content_type
= util::kContentTypeApplicationJson
;
260 base::DictionaryValue root
;
262 if (!modified_date_
.is_null())
263 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
265 if (!parents_
.empty()) {
266 base::ListValue
* parents_value
= new base::ListValue
;
267 for (size_t i
= 0; i
< parents_
.size(); ++i
) {
268 base::DictionaryValue
* parent
= new base::DictionaryValue
;
269 parent
->SetString("id", parents_
[i
]);
270 parents_value
->Append(parent
);
272 root
.Set("parents", parents_value
);
276 root
.SetString("title", title_
);
278 base::JSONWriter::Write(&root
, upload_content
);
279 DVLOG(1) << "FilesCopy data: " << *upload_content_type
<< ", ["
280 << *upload_content
<< "]";
284 //============================= FilesListRequest =============================
286 FilesListRequest::FilesListRequest(
287 RequestSender
* sender
,
288 const DriveApiUrlGenerator
& url_generator
,
289 const FileListCallback
& callback
)
290 : DriveApiDataRequest
<FileList
>(sender
, callback
),
291 url_generator_(url_generator
),
293 DCHECK(!callback
.is_null());
296 FilesListRequest::~FilesListRequest() {}
298 GURL
FilesListRequest::GetURLInternal() const {
299 return url_generator_
.GetFilesListUrl(max_results_
, page_token_
, q_
);
302 //======================== FilesListNextPageRequest =========================
304 FilesListNextPageRequest::FilesListNextPageRequest(
305 RequestSender
* sender
,
306 const FileListCallback
& callback
)
307 : DriveApiDataRequest
<FileList
>(sender
, callback
) {
308 DCHECK(!callback
.is_null());
311 FilesListNextPageRequest::~FilesListNextPageRequest() {
314 GURL
FilesListNextPageRequest::GetURLInternal() const {
318 //============================ FilesDeleteRequest =============================
320 FilesDeleteRequest::FilesDeleteRequest(
321 RequestSender
* sender
,
322 const DriveApiUrlGenerator
& url_generator
,
323 const EntryActionCallback
& callback
)
324 : EntryActionRequest(sender
, callback
),
325 url_generator_(url_generator
) {
326 DCHECK(!callback
.is_null());
329 FilesDeleteRequest::~FilesDeleteRequest() {}
331 net::URLFetcher::RequestType
FilesDeleteRequest::GetRequestType() const {
332 return net::URLFetcher::DELETE_REQUEST
;
335 GURL
FilesDeleteRequest::GetURL() const {
336 return url_generator_
.GetFilesDeleteUrl(file_id_
);
339 std::vector
<std::string
> FilesDeleteRequest::GetExtraRequestHeaders() const {
340 std::vector
<std::string
> headers(
341 EntryActionRequest::GetExtraRequestHeaders());
342 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
346 //============================ FilesTrashRequest =============================
348 FilesTrashRequest::FilesTrashRequest(
349 RequestSender
* sender
,
350 const DriveApiUrlGenerator
& url_generator
,
351 const FileResourceCallback
& callback
)
352 : DriveApiDataRequest
<FileResource
>(sender
, callback
),
353 url_generator_(url_generator
) {
354 DCHECK(!callback
.is_null());
357 FilesTrashRequest::~FilesTrashRequest() {}
359 net::URLFetcher::RequestType
FilesTrashRequest::GetRequestType() const {
360 return net::URLFetcher::POST
;
363 GURL
FilesTrashRequest::GetURLInternal() const {
364 return url_generator_
.GetFilesTrashUrl(file_id_
);
367 //============================== AboutGetRequest =============================
369 AboutGetRequest::AboutGetRequest(
370 RequestSender
* sender
,
371 const DriveApiUrlGenerator
& url_generator
,
372 const AboutResourceCallback
& callback
)
373 : DriveApiDataRequest
<AboutResource
>(sender
, callback
),
374 url_generator_(url_generator
) {
375 DCHECK(!callback
.is_null());
378 AboutGetRequest::~AboutGetRequest() {}
380 GURL
AboutGetRequest::GetURLInternal() const {
381 return url_generator_
.GetAboutGetUrl();
384 //============================ ChangesListRequest ===========================
386 ChangesListRequest::ChangesListRequest(
387 RequestSender
* sender
,
388 const DriveApiUrlGenerator
& url_generator
,
389 const ChangeListCallback
& callback
)
390 : DriveApiDataRequest
<ChangeList
>(sender
, callback
),
391 url_generator_(url_generator
),
392 include_deleted_(true),
394 start_change_id_(0) {
395 DCHECK(!callback
.is_null());
398 ChangesListRequest::~ChangesListRequest() {}
400 GURL
ChangesListRequest::GetURLInternal() const {
401 return url_generator_
.GetChangesListUrl(
402 include_deleted_
, max_results_
, page_token_
, start_change_id_
);
405 //======================== ChangesListNextPageRequest =========================
407 ChangesListNextPageRequest::ChangesListNextPageRequest(
408 RequestSender
* sender
,
409 const ChangeListCallback
& callback
)
410 : DriveApiDataRequest
<ChangeList
>(sender
, callback
) {
411 DCHECK(!callback
.is_null());
414 ChangesListNextPageRequest::~ChangesListNextPageRequest() {
417 GURL
ChangesListNextPageRequest::GetURLInternal() const {
421 //============================== AppsListRequest ===========================
423 AppsListRequest::AppsListRequest(
424 RequestSender
* sender
,
425 const DriveApiUrlGenerator
& url_generator
,
426 bool use_internal_endpoint
,
427 const AppListCallback
& callback
)
428 : DriveApiDataRequest
<AppList
>(sender
, callback
),
429 url_generator_(url_generator
),
430 use_internal_endpoint_(use_internal_endpoint
) {
431 DCHECK(!callback
.is_null());
434 AppsListRequest::~AppsListRequest() {}
436 GURL
AppsListRequest::GetURLInternal() const {
437 return url_generator_
.GetAppsListUrl(use_internal_endpoint_
);
440 //============================== AppsDeleteRequest ===========================
442 AppsDeleteRequest::AppsDeleteRequest(RequestSender
* sender
,
443 const DriveApiUrlGenerator
& url_generator
,
444 const EntryActionCallback
& callback
)
445 : EntryActionRequest(sender
, callback
),
446 url_generator_(url_generator
) {
447 DCHECK(!callback
.is_null());
450 AppsDeleteRequest::~AppsDeleteRequest() {}
452 net::URLFetcher::RequestType
AppsDeleteRequest::GetRequestType() const {
453 return net::URLFetcher::DELETE_REQUEST
;
456 GURL
AppsDeleteRequest::GetURL() const {
457 return url_generator_
.GetAppsDeleteUrl(app_id_
);
460 //========================== ChildrenInsertRequest ============================
462 ChildrenInsertRequest::ChildrenInsertRequest(
463 RequestSender
* sender
,
464 const DriveApiUrlGenerator
& url_generator
,
465 const EntryActionCallback
& callback
)
466 : EntryActionRequest(sender
, callback
),
467 url_generator_(url_generator
) {
468 DCHECK(!callback
.is_null());
471 ChildrenInsertRequest::~ChildrenInsertRequest() {}
473 net::URLFetcher::RequestType
ChildrenInsertRequest::GetRequestType() const {
474 return net::URLFetcher::POST
;
477 GURL
ChildrenInsertRequest::GetURL() const {
478 return url_generator_
.GetChildrenInsertUrl(folder_id_
);
481 bool ChildrenInsertRequest::GetContentData(std::string
* upload_content_type
,
482 std::string
* upload_content
) {
483 *upload_content_type
= util::kContentTypeApplicationJson
;
485 base::DictionaryValue root
;
486 root
.SetString("id", id_
);
488 base::JSONWriter::Write(&root
, upload_content
);
489 DVLOG(1) << "InsertResource data: " << *upload_content_type
<< ", ["
490 << *upload_content
<< "]";
494 //========================== ChildrenDeleteRequest ============================
496 ChildrenDeleteRequest::ChildrenDeleteRequest(
497 RequestSender
* sender
,
498 const DriveApiUrlGenerator
& url_generator
,
499 const EntryActionCallback
& callback
)
500 : EntryActionRequest(sender
, callback
),
501 url_generator_(url_generator
) {
502 DCHECK(!callback
.is_null());
505 ChildrenDeleteRequest::~ChildrenDeleteRequest() {}
507 net::URLFetcher::RequestType
ChildrenDeleteRequest::GetRequestType() const {
508 return net::URLFetcher::DELETE_REQUEST
;
511 GURL
ChildrenDeleteRequest::GetURL() const {
512 return url_generator_
.GetChildrenDeleteUrl(child_id_
, folder_id_
);
515 //======================= InitiateUploadNewFileRequest =======================
517 InitiateUploadNewFileRequest::InitiateUploadNewFileRequest(
518 RequestSender
* sender
,
519 const DriveApiUrlGenerator
& url_generator
,
520 const std::string
& content_type
,
521 int64 content_length
,
522 const std::string
& parent_resource_id
,
523 const std::string
& title
,
524 const InitiateUploadCallback
& callback
)
525 : InitiateUploadRequestBase(sender
,
529 url_generator_(url_generator
),
530 parent_resource_id_(parent_resource_id
),
534 InitiateUploadNewFileRequest::~InitiateUploadNewFileRequest() {}
536 GURL
InitiateUploadNewFileRequest::GetURL() const {
537 return url_generator_
.GetInitiateUploadNewFileUrl(!modified_date_
.is_null());
540 net::URLFetcher::RequestType
541 InitiateUploadNewFileRequest::GetRequestType() const {
542 return net::URLFetcher::POST
;
545 bool InitiateUploadNewFileRequest::GetContentData(
546 std::string
* upload_content_type
,
547 std::string
* upload_content
) {
548 *upload_content_type
= util::kContentTypeApplicationJson
;
550 base::DictionaryValue root
;
551 root
.SetString("title", title_
);
554 scoped_ptr
<base::ListValue
> parents(new base::ListValue
);
555 parents
->Append(util::CreateParentValue(parent_resource_id_
).release());
556 root
.Set("parents", parents
.release());
558 if (!modified_date_
.is_null())
559 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
561 if (!last_viewed_by_me_date_
.is_null()) {
562 root
.SetString("lastViewedByMeDate",
563 util::FormatTimeAsString(last_viewed_by_me_date_
));
566 base::JSONWriter::Write(&root
, upload_content
);
568 DVLOG(1) << "InitiateUploadNewFile data: " << *upload_content_type
<< ", ["
569 << *upload_content
<< "]";
573 //===================== InitiateUploadExistingFileRequest ====================
575 InitiateUploadExistingFileRequest::InitiateUploadExistingFileRequest(
576 RequestSender
* sender
,
577 const DriveApiUrlGenerator
& url_generator
,
578 const std::string
& content_type
,
579 int64 content_length
,
580 const std::string
& resource_id
,
581 const std::string
& etag
,
582 const InitiateUploadCallback
& callback
)
583 : InitiateUploadRequestBase(sender
,
587 url_generator_(url_generator
),
588 resource_id_(resource_id
),
592 InitiateUploadExistingFileRequest::~InitiateUploadExistingFileRequest() {}
594 GURL
InitiateUploadExistingFileRequest::GetURL() const {
595 return url_generator_
.GetInitiateUploadExistingFileUrl(
596 resource_id_
, !modified_date_
.is_null());
599 net::URLFetcher::RequestType
600 InitiateUploadExistingFileRequest::GetRequestType() const {
601 return net::URLFetcher::PUT
;
604 std::vector
<std::string
>
605 InitiateUploadExistingFileRequest::GetExtraRequestHeaders() const {
606 std::vector
<std::string
> headers(
607 InitiateUploadRequestBase::GetExtraRequestHeaders());
608 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
612 bool InitiateUploadExistingFileRequest::GetContentData(
613 std::string
* upload_content_type
,
614 std::string
* upload_content
) {
615 base::DictionaryValue root
;
616 if (!parent_resource_id_
.empty()) {
617 scoped_ptr
<base::ListValue
> parents(new base::ListValue
);
618 parents
->Append(util::CreateParentValue(parent_resource_id_
).release());
619 root
.Set("parents", parents
.release());
623 root
.SetString("title", title_
);
625 if (!modified_date_
.is_null())
626 root
.SetString("modifiedDate", util::FormatTimeAsString(modified_date_
));
628 if (!last_viewed_by_me_date_
.is_null()) {
629 root
.SetString("lastViewedByMeDate",
630 util::FormatTimeAsString(last_viewed_by_me_date_
));
636 *upload_content_type
= util::kContentTypeApplicationJson
;
637 base::JSONWriter::Write(&root
, upload_content
);
638 DVLOG(1) << "InitiateUploadExistingFile data: " << *upload_content_type
639 << ", [" << *upload_content
<< "]";
643 //============================ ResumeUploadRequest ===========================
645 ResumeUploadRequest::ResumeUploadRequest(
646 RequestSender
* sender
,
647 const GURL
& upload_location
,
648 int64 start_position
,
650 int64 content_length
,
651 const std::string
& content_type
,
652 const base::FilePath
& local_file_path
,
653 const UploadRangeCallback
& callback
,
654 const ProgressCallback
& progress_callback
)
655 : ResumeUploadRequestBase(sender
,
663 progress_callback_(progress_callback
) {
664 DCHECK(!callback_
.is_null());
667 ResumeUploadRequest::~ResumeUploadRequest() {}
669 void ResumeUploadRequest::OnRangeRequestComplete(
670 const UploadRangeResponse
& response
,
671 scoped_ptr
<base::Value
> value
) {
672 DCHECK(CalledOnValidThread());
673 ParseFileResourceWithUploadRangeAndRun(callback_
, response
, value
.Pass());
676 void ResumeUploadRequest::OnURLFetchUploadProgress(
677 const net::URLFetcher
* source
, int64 current
, int64 total
) {
678 if (!progress_callback_
.is_null())
679 progress_callback_
.Run(current
, total
);
682 //========================== GetUploadStatusRequest ==========================
684 GetUploadStatusRequest::GetUploadStatusRequest(
685 RequestSender
* sender
,
686 const GURL
& upload_url
,
687 int64 content_length
,
688 const UploadRangeCallback
& callback
)
689 : GetUploadStatusRequestBase(sender
,
692 callback_(callback
) {
693 DCHECK(!callback
.is_null());
696 GetUploadStatusRequest::~GetUploadStatusRequest() {}
698 void GetUploadStatusRequest::OnRangeRequestComplete(
699 const UploadRangeResponse
& response
,
700 scoped_ptr
<base::Value
> value
) {
701 DCHECK(CalledOnValidThread());
702 ParseFileResourceWithUploadRangeAndRun(callback_
, response
, value
.Pass());
705 //======================= MultipartUploadNewFileRequest =======================
707 MultipartUploadNewFileRequest::MultipartUploadNewFileRequest(
708 RequestSender
* sender
,
709 const std::string
& title
,
710 const std::string
& parent_resource_id
,
711 const std::string
& content_type
,
712 int64 content_length
,
713 const base::Time
& modified_date
,
714 const base::Time
& last_viewed_by_me_date
,
715 const base::FilePath
& local_file_path
,
716 const DriveApiUrlGenerator
& url_generator
,
717 const FileResourceCallback
& callback
,
718 const ProgressCallback
& progress_callback
)
719 : MultipartUploadRequestBase(sender
,
725 last_viewed_by_me_date
,
729 url_generator_(url_generator
) {
732 MultipartUploadNewFileRequest::~MultipartUploadNewFileRequest() {
735 GURL
MultipartUploadNewFileRequest::GetURL() const {
736 return url_generator_
.GetMultipartUploadNewFileUrl(has_modified_date());
739 net::URLFetcher::RequestType
MultipartUploadNewFileRequest::GetRequestType()
741 return net::URLFetcher::POST
;
744 //======================= MultipartUploadExistingFileRequest ===================
746 MultipartUploadExistingFileRequest::MultipartUploadExistingFileRequest(
747 RequestSender
* sender
,
748 const std::string
& title
,
749 const std::string
& resource_id
,
750 const std::string
& parent_resource_id
,
751 const std::string
& content_type
,
752 int64 content_length
,
753 const base::Time
& modified_date
,
754 const base::Time
& last_viewed_by_me_date
,
755 const base::FilePath
& local_file_path
,
756 const std::string
& etag
,
757 const DriveApiUrlGenerator
& url_generator
,
758 const FileResourceCallback
& callback
,
759 const ProgressCallback
& progress_callback
)
760 : MultipartUploadRequestBase(sender
,
766 last_viewed_by_me_date
,
770 resource_id_(resource_id
),
772 url_generator_(url_generator
) {
775 MultipartUploadExistingFileRequest::~MultipartUploadExistingFileRequest() {
778 std::vector
<std::string
>
779 MultipartUploadExistingFileRequest::GetExtraRequestHeaders() const {
780 std::vector
<std::string
> headers(
781 MultipartUploadRequestBase::GetExtraRequestHeaders());
782 headers
.push_back(util::GenerateIfMatchHeader(etag_
));
786 GURL
MultipartUploadExistingFileRequest::GetURL() const {
787 return url_generator_
.GetMultipartUploadExistingFileUrl(
788 resource_id_
, has_modified_date());
791 net::URLFetcher::RequestType
792 MultipartUploadExistingFileRequest::GetRequestType() const {
793 return net::URLFetcher::PUT
;
796 //========================== DownloadFileRequest ==========================
798 DownloadFileRequest::DownloadFileRequest(
799 RequestSender
* sender
,
800 const DriveApiUrlGenerator
& url_generator
,
801 const std::string
& resource_id
,
802 const base::FilePath
& output_file_path
,
803 const DownloadActionCallback
& download_action_callback
,
804 const GetContentCallback
& get_content_callback
,
805 const ProgressCallback
& progress_callback
)
806 : DownloadFileRequestBase(
808 download_action_callback
,
809 get_content_callback
,
811 url_generator
.GenerateDownloadFileUrl(resource_id
),
815 DownloadFileRequest::~DownloadFileRequest() {
818 //========================== PermissionsInsertRequest ==========================
820 PermissionsInsertRequest::PermissionsInsertRequest(
821 RequestSender
* sender
,
822 const DriveApiUrlGenerator
& url_generator
,
823 const EntryActionCallback
& callback
)
824 : EntryActionRequest(sender
, callback
),
825 url_generator_(url_generator
),
826 type_(PERMISSION_TYPE_USER
),
827 role_(PERMISSION_ROLE_READER
) {
830 PermissionsInsertRequest::~PermissionsInsertRequest() {
833 GURL
PermissionsInsertRequest::GetURL() const {
834 return url_generator_
.GetPermissionsInsertUrl(id_
);
837 net::URLFetcher::RequestType
838 PermissionsInsertRequest::GetRequestType() const {
839 return net::URLFetcher::POST
;
842 bool PermissionsInsertRequest::GetContentData(std::string
* upload_content_type
,
843 std::string
* upload_content
) {
844 *upload_content_type
= util::kContentTypeApplicationJson
;
846 base::DictionaryValue root
;
848 case PERMISSION_TYPE_ANYONE
:
849 root
.SetString("type", "anyone");
851 case PERMISSION_TYPE_DOMAIN
:
852 root
.SetString("type", "domain");
854 case PERMISSION_TYPE_GROUP
:
855 root
.SetString("type", "group");
857 case PERMISSION_TYPE_USER
:
858 root
.SetString("type", "user");
862 case PERMISSION_ROLE_OWNER
:
863 root
.SetString("role", "owner");
865 case PERMISSION_ROLE_READER
:
866 root
.SetString("role", "reader");
868 case PERMISSION_ROLE_WRITER
:
869 root
.SetString("role", "writer");
871 case PERMISSION_ROLE_COMMENTER
:
872 root
.SetString("role", "reader");
874 base::ListValue
* list
= new base::ListValue
;
875 list
->AppendString("commenter");
876 root
.Set("additionalRoles", list
);
880 root
.SetString("value", value_
);
881 base::JSONWriter::Write(&root
, upload_content
);
886 } // namespace google_apis