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 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
10 #include "base/callback_forward.h"
11 #include "base/time/time.h"
12 #include "google_apis/drive/base_requests.h"
13 #include "google_apis/drive/drive_api_url_generator.h"
14 #include "google_apis/drive/drive_common_callbacks.h"
16 namespace google_apis
{
22 // Callback used for requests that the server returns FileResource data
23 // formatted into JSON value.
24 typedef base::Callback
<void(GDataErrorCode error
,
25 scoped_ptr
<FileResource
> entry
)>
28 // Callback used for requests that the server returns FileList data
29 // formatted into JSON value.
30 typedef base::Callback
<void(GDataErrorCode error
,
31 scoped_ptr
<FileList
> entry
)> FileListCallback
;
33 // Callback used for requests that the server returns ChangeList data
34 // formatted into JSON value.
35 typedef base::Callback
<void(GDataErrorCode error
,
36 scoped_ptr
<ChangeList
> entry
)> ChangeListCallback
;
40 //============================ DriveApiDataRequest ===========================
42 // This is base class of the Drive API related requests. All Drive API requests
43 // support partial request (to improve the performance). The function can be
44 // shared among the Drive API requests.
45 // See also https://developers.google.com/drive/performance
46 class DriveApiDataRequest
: public GetDataRequest
{
48 DriveApiDataRequest(RequestSender
* sender
, const GetDataCallback
& callback
);
49 virtual ~DriveApiDataRequest();
51 // Optional parameter.
52 const std::string
& fields() const { return fields_
; }
53 void set_fields(const std::string
& fields
) { fields_
= fields
; }
56 // Overridden from GetDataRequest.
57 virtual GURL
GetURL() const OVERRIDE
;
59 // Derived classes should override GetURLInternal instead of GetURL()
61 virtual GURL
GetURLInternal() const = 0;
66 DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest
);
69 //=============================== FilesGetRequest =============================
71 // This class performs the request for fetching a file.
72 // This request is mapped to
73 // https://developers.google.com/drive/v2/reference/files/get
74 class FilesGetRequest
: public DriveApiDataRequest
{
76 FilesGetRequest(RequestSender
* sender
,
77 const DriveApiUrlGenerator
& url_generator
,
78 const FileResourceCallback
& callback
);
79 virtual ~FilesGetRequest();
81 // Required parameter.
82 const std::string
& file_id() const { return file_id_
; }
83 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
86 // Overridden from DriveApiDataRequest.
87 virtual GURL
GetURLInternal() const OVERRIDE
;
90 const DriveApiUrlGenerator url_generator_
;
93 DISALLOW_COPY_AND_ASSIGN(FilesGetRequest
);
96 //============================ FilesAuthorizeRequest ===========================
98 // This class performs request for authorizing an app to access a file.
99 // This request is mapped to /drive/v2internal/file/authorize internal endpoint.
100 class FilesAuthorizeRequest
: public DriveApiDataRequest
{
102 FilesAuthorizeRequest(RequestSender
* sender
,
103 const DriveApiUrlGenerator
& url_generator
,
104 const FileResourceCallback
& callback
);
105 virtual ~FilesAuthorizeRequest();
107 // Required parameter.
108 const std::string
& file_id() const { return file_id_
; }
109 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
110 const std::string
& app_id() const { return app_id_
; }
111 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
114 // Overridden from GetDataRequest.
115 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
117 // Overridden from DriveApiDataRequest.
118 virtual GURL
GetURLInternal() const OVERRIDE
;
121 const DriveApiUrlGenerator url_generator_
;
122 std::string file_id_
;
125 DISALLOW_COPY_AND_ASSIGN(FilesAuthorizeRequest
);
128 //============================ FilesInsertRequest =============================
130 // This class performs the request for creating a resource.
131 // This request is mapped to
132 // https://developers.google.com/drive/v2/reference/files/insert
133 // See also https://developers.google.com/drive/manage-uploads and
134 // https://developers.google.com/drive/folder
135 class FilesInsertRequest
: public DriveApiDataRequest
{
137 FilesInsertRequest(RequestSender
* sender
,
138 const DriveApiUrlGenerator
& url_generator
,
139 const FileResourceCallback
& callback
);
140 virtual ~FilesInsertRequest();
142 // Optional request body.
143 const base::Time
& last_viewed_by_me_date() const {
144 return last_viewed_by_me_date_
;
146 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
147 last_viewed_by_me_date_
= last_viewed_by_me_date
;
150 const std::string
& mime_type() const { return mime_type_
; }
151 void set_mime_type(const std::string
& mime_type
) {
152 mime_type_
= mime_type
;
155 const base::Time
& modified_date() const { return modified_date_
; }
156 void set_modified_date(const base::Time
& modified_date
) {
157 modified_date_
= modified_date
;
160 const std::vector
<std::string
>& parents() const { return parents_
; }
161 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
163 const std::string
& title() const { return title_
; }
164 void set_title(const std::string
& title
) { title_
= title
; }
167 // Overridden from GetDataRequest.
168 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
169 virtual bool GetContentData(std::string
* upload_content_type
,
170 std::string
* upload_content
) OVERRIDE
;
172 // Overridden from DriveApiDataRequest.
173 virtual GURL
GetURLInternal() const OVERRIDE
;
176 const DriveApiUrlGenerator url_generator_
;
178 base::Time last_viewed_by_me_date_
;
179 std::string mime_type_
;
180 base::Time modified_date_
;
181 std::vector
<std::string
> parents_
;
184 DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest
);
187 //============================== FilesPatchRequest ============================
189 // This class performs the request for patching file metadata.
190 // This request is mapped to
191 // https://developers.google.com/drive/v2/reference/files/patch
192 class FilesPatchRequest
: public DriveApiDataRequest
{
194 FilesPatchRequest(RequestSender
* sender
,
195 const DriveApiUrlGenerator
& url_generator
,
196 const FileResourceCallback
& callback
);
197 virtual ~FilesPatchRequest();
199 // Required parameter.
200 const std::string
& file_id() const { return file_id_
; }
201 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
203 // Optional parameter.
204 bool set_modified_date() const { return set_modified_date_
; }
205 void set_set_modified_date(bool set_modified_date
) {
206 set_modified_date_
= set_modified_date
;
209 bool update_viewed_date() const { return update_viewed_date_
; }
210 void set_update_viewed_date(bool update_viewed_date
) {
211 update_viewed_date_
= update_viewed_date
;
214 // Optional request body.
215 // Note: "Files: patch" accepts any "Files resource" data, but this class
216 // only supports limited members of it for now. We can extend it upon
218 const std::string
& title() const { return title_
; }
219 void set_title(const std::string
& title
) { title_
= title
; }
221 const base::Time
& modified_date() const { return modified_date_
; }
222 void set_modified_date(const base::Time
& modified_date
) {
223 modified_date_
= modified_date
;
226 const base::Time
& last_viewed_by_me_date() const {
227 return last_viewed_by_me_date_
;
229 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
230 last_viewed_by_me_date_
= last_viewed_by_me_date
;
233 const std::vector
<std::string
>& parents() const { return parents_
; }
234 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
237 // Overridden from URLFetchRequestBase.
238 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
239 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
240 virtual bool GetContentData(std::string
* upload_content_type
,
241 std::string
* upload_content
) OVERRIDE
;
243 // Overridden from DriveApiDataRequest.
244 virtual GURL
GetURLInternal() const OVERRIDE
;
247 const DriveApiUrlGenerator url_generator_
;
249 std::string file_id_
;
250 bool set_modified_date_
;
251 bool update_viewed_date_
;
254 base::Time modified_date_
;
255 base::Time last_viewed_by_me_date_
;
256 std::vector
<std::string
> parents_
;
258 DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest
);
261 //============================= FilesCopyRequest ==============================
263 // This class performs the request for copying a resource.
264 // This request is mapped to
265 // https://developers.google.com/drive/v2/reference/files/copy
266 class FilesCopyRequest
: public DriveApiDataRequest
{
268 // Upon completion, |callback| will be called. |callback| must not be null.
269 FilesCopyRequest(RequestSender
* sender
,
270 const DriveApiUrlGenerator
& url_generator
,
271 const FileResourceCallback
& callback
);
272 virtual ~FilesCopyRequest();
274 // Required parameter.
275 const std::string
& file_id() const { return file_id_
; }
276 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
278 // Optional request body.
279 const std::vector
<std::string
>& parents() const { return parents_
; }
280 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
282 const base::Time
& modified_date() const { return modified_date_
; }
283 void set_modified_date(const base::Time
& modified_date
) {
284 modified_date_
= modified_date
;
287 const std::string
& title() const { return title_
; }
288 void set_title(const std::string
& title
) { title_
= title
; }
291 // Overridden from URLFetchRequestBase.
292 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
293 virtual bool GetContentData(std::string
* upload_content_type
,
294 std::string
* upload_content
) OVERRIDE
;
296 // Overridden from DriveApiDataRequest.
297 virtual GURL
GetURLInternal() const OVERRIDE
;
300 const DriveApiUrlGenerator url_generator_
;
302 std::string file_id_
;
303 base::Time modified_date_
;
304 std::vector
<std::string
> parents_
;
307 DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest
);
310 //============================= FilesListRequest =============================
312 // This class performs the request for fetching FileList.
313 // The result may contain only first part of the result. The remaining result
314 // should be able to be fetched by ContinueGetFileListRequest defined below,
315 // or by FilesListRequest with setting page token.
316 // This request is mapped to
317 // https://developers.google.com/drive/v2/reference/files/list
318 class FilesListRequest
: public DriveApiDataRequest
{
320 FilesListRequest(RequestSender
* sender
,
321 const DriveApiUrlGenerator
& url_generator
,
322 const FileListCallback
& callback
);
323 virtual ~FilesListRequest();
325 // Optional parameter
326 int max_results() const { return max_results_
; }
327 void set_max_results(int max_results
) { max_results_
= max_results
; }
329 const std::string
& page_token() const { return page_token_
; }
330 void set_page_token(const std::string
& page_token
) {
331 page_token_
= page_token
;
334 const std::string
& q() const { return q_
; }
335 void set_q(const std::string
& q
) { q_
= q
; }
338 // Overridden from DriveApiDataRequest.
339 virtual GURL
GetURLInternal() const OVERRIDE
;
342 const DriveApiUrlGenerator url_generator_
;
344 std::string page_token_
;
347 DISALLOW_COPY_AND_ASSIGN(FilesListRequest
);
350 //========================= FilesListNextPageRequest ==========================
352 // There are two ways to obtain next pages of "Files: list" result (if paged).
353 // 1) Set pageToken and all params used for the initial request.
354 // 2) Use URL in the nextLink field in the previous response.
355 // This class implements 2)'s request.
356 class FilesListNextPageRequest
: public DriveApiDataRequest
{
358 FilesListNextPageRequest(RequestSender
* sender
,
359 const FileListCallback
& callback
);
360 virtual ~FilesListNextPageRequest();
362 const GURL
& next_link() const { return next_link_
; }
363 void set_next_link(const GURL
& next_link
) { next_link_
= next_link
; }
366 // Overridden from DriveApiDataRequest.
367 virtual GURL
GetURLInternal() const OVERRIDE
;
372 DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest
);
375 //============================= FilesDeleteRequest =============================
377 // This class performs the request for deleting a resource.
378 // This request is mapped to
379 // https://developers.google.com/drive/v2/reference/files/delete
380 class FilesDeleteRequest
: public EntryActionRequest
{
382 FilesDeleteRequest(RequestSender
* sender
,
383 const DriveApiUrlGenerator
& url_generator
,
384 const EntryActionCallback
& callback
);
385 virtual ~FilesDeleteRequest();
387 // Required parameter.
388 const std::string
& file_id() const { return file_id_
; }
389 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
390 void set_etag(const std::string
& etag
) { etag_
= etag
; }
393 // Overridden from UrlFetchRequestBase.
394 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
395 virtual GURL
GetURL() const OVERRIDE
;
396 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
399 const DriveApiUrlGenerator url_generator_
;
400 std::string file_id_
;
403 DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest
);
406 //============================= FilesTrashRequest ==============================
408 // This class performs the request for trashing a resource.
409 // This request is mapped to
410 // https://developers.google.com/drive/v2/reference/files/trash
411 class FilesTrashRequest
: public DriveApiDataRequest
{
413 FilesTrashRequest(RequestSender
* sender
,
414 const DriveApiUrlGenerator
& url_generator
,
415 const FileResourceCallback
& callback
);
416 virtual ~FilesTrashRequest();
418 // Required parameter.
419 const std::string
& file_id() const { return file_id_
; }
420 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
423 // Overridden from UrlFetchRequestBase.
424 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
426 // Overridden from DriveApiDataRequest.
427 virtual GURL
GetURLInternal() const OVERRIDE
;
430 const DriveApiUrlGenerator url_generator_
;
431 std::string file_id_
;
433 DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest
);
436 //============================== AboutGetRequest =============================
438 // This class performs the request for fetching About data.
439 // This request is mapped to
440 // https://developers.google.com/drive/v2/reference/about/get
441 class AboutGetRequest
: public DriveApiDataRequest
{
443 AboutGetRequest(RequestSender
* sender
,
444 const DriveApiUrlGenerator
& url_generator
,
445 const AboutResourceCallback
& callback
);
446 virtual ~AboutGetRequest();
449 // Overridden from DriveApiDataRequest.
450 virtual GURL
GetURLInternal() const OVERRIDE
;
453 const DriveApiUrlGenerator url_generator_
;
455 DISALLOW_COPY_AND_ASSIGN(AboutGetRequest
);
458 //============================ ChangesListRequest ============================
460 // This class performs the request for fetching ChangeList.
461 // The result may contain only first part of the result. The remaining result
462 // should be able to be fetched by ContinueGetFileListRequest defined below.
463 // or by ChangesListRequest with setting page token.
464 // This request is mapped to
465 // https://developers.google.com/drive/v2/reference/changes/list
466 class ChangesListRequest
: public DriveApiDataRequest
{
468 ChangesListRequest(RequestSender
* sender
,
469 const DriveApiUrlGenerator
& url_generator
,
470 const ChangeListCallback
& callback
);
471 virtual ~ChangesListRequest();
473 // Optional parameter
474 bool include_deleted() const { return include_deleted_
; }
475 void set_include_deleted(bool include_deleted
) {
476 include_deleted_
= include_deleted
;
479 int max_results() const { return max_results_
; }
480 void set_max_results(int max_results
) { max_results_
= max_results
; }
482 const std::string
& page_token() const { return page_token_
; }
483 void set_page_token(const std::string
& page_token
) {
484 page_token_
= page_token
;
487 int64
start_change_id() const { return start_change_id_
; }
488 void set_start_change_id(int64 start_change_id
) {
489 start_change_id_
= start_change_id
;
493 // Overridden from DriveApiDataRequest.
494 virtual GURL
GetURLInternal() const OVERRIDE
;
497 const DriveApiUrlGenerator url_generator_
;
498 bool include_deleted_
;
500 std::string page_token_
;
501 int64 start_change_id_
;
503 DISALLOW_COPY_AND_ASSIGN(ChangesListRequest
);
506 //======================== ChangesListNextPageRequest =========================
508 // There are two ways to obtain next pages of "Changes: list" result (if paged).
509 // 1) Set pageToken and all params used for the initial request.
510 // 2) Use URL in the nextLink field in the previous response.
511 // This class implements 2)'s request.
512 class ChangesListNextPageRequest
: public DriveApiDataRequest
{
514 ChangesListNextPageRequest(RequestSender
* sender
,
515 const ChangeListCallback
& callback
);
516 virtual ~ChangesListNextPageRequest();
518 const GURL
& next_link() const { return next_link_
; }
519 void set_next_link(const GURL
& next_link
) { next_link_
= next_link
; }
522 // Overridden from DriveApiDataRequest.
523 virtual GURL
GetURLInternal() const OVERRIDE
;
528 DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest
);
531 //============================= AppsListRequest ============================
533 // This class performs the request for fetching AppList.
534 // This request is mapped to
535 // https://developers.google.com/drive/v2/reference/apps/list
536 class AppsListRequest
: public DriveApiDataRequest
{
538 AppsListRequest(RequestSender
* sender
,
539 const DriveApiUrlGenerator
& url_generator
,
540 bool use_internal_endpoint
,
541 const AppListCallback
& callback
);
542 virtual ~AppsListRequest();
545 // Overridden from DriveApiDataRequest.
546 virtual GURL
GetURLInternal() const OVERRIDE
;
549 const DriveApiUrlGenerator url_generator_
;
550 bool use_internal_endpoint_
;
552 DISALLOW_COPY_AND_ASSIGN(AppsListRequest
);
555 //============================= AppsDeleteRequest ==============================
557 // This class performs the request for deleting a Drive app.
558 // This request is mapped to
559 // https://developers.google.com/drive/v2/reference/files/trash
560 class AppsDeleteRequest
: public EntryActionRequest
{
562 AppsDeleteRequest(RequestSender
* sender
,
563 const DriveApiUrlGenerator
& url_generator
,
564 const EntryActionCallback
& callback
);
565 virtual ~AppsDeleteRequest();
567 // Required parameter.
568 const std::string
& app_id() const { return app_id_
; }
569 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
572 // Overridden from UrlFetchRequestBase.
573 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
574 virtual GURL
GetURL() const OVERRIDE
;
577 const DriveApiUrlGenerator url_generator_
;
580 DISALLOW_COPY_AND_ASSIGN(AppsDeleteRequest
);
583 //========================== ChildrenInsertRequest ============================
585 // This class performs the request for inserting a resource to a directory.
586 // This request is mapped to
587 // https://developers.google.com/drive/v2/reference/children/insert
588 class ChildrenInsertRequest
: public EntryActionRequest
{
590 ChildrenInsertRequest(RequestSender
* sender
,
591 const DriveApiUrlGenerator
& url_generator
,
592 const EntryActionCallback
& callback
);
593 virtual ~ChildrenInsertRequest();
595 // Required parameter.
596 const std::string
& folder_id() const { return folder_id_
; }
597 void set_folder_id(const std::string
& folder_id
) {
598 folder_id_
= folder_id
;
602 const std::string
& id() const { return id_
; }
603 void set_id(const std::string
& id
) { id_
= id
; }
606 // UrlFetchRequestBase overrides.
607 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
608 virtual GURL
GetURL() const OVERRIDE
;
609 virtual bool GetContentData(std::string
* upload_content_type
,
610 std::string
* upload_content
) OVERRIDE
;
613 const DriveApiUrlGenerator url_generator_
;
614 std::string folder_id_
;
617 DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest
);
620 //========================== ChildrenDeleteRequest ============================
622 // This class performs the request for removing a resource from a directory.
623 // This request is mapped to
624 // https://developers.google.com/drive/v2/reference/children/delete
625 class ChildrenDeleteRequest
: public EntryActionRequest
{
627 // |callback| must not be null.
628 ChildrenDeleteRequest(RequestSender
* sender
,
629 const DriveApiUrlGenerator
& url_generator
,
630 const EntryActionCallback
& callback
);
631 virtual ~ChildrenDeleteRequest();
633 // Required parameter.
634 const std::string
& child_id() const { return child_id_
; }
635 void set_child_id(const std::string
& child_id
) {
636 child_id_
= child_id
;
639 const std::string
& folder_id() const { return folder_id_
; }
640 void set_folder_id(const std::string
& folder_id
) {
641 folder_id_
= folder_id
;
645 // UrlFetchRequestBase overrides.
646 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
647 virtual GURL
GetURL() const OVERRIDE
;
650 const DriveApiUrlGenerator url_generator_
;
651 std::string child_id_
;
652 std::string folder_id_
;
654 DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest
);
657 //======================= InitiateUploadNewFileRequest =======================
659 // This class performs the request for initiating the upload of a new file.
660 class InitiateUploadNewFileRequest
: public InitiateUploadRequestBase
{
662 // |parent_resource_id| should be the resource id of the parent directory.
663 // |title| should be set.
664 // See also the comments of InitiateUploadRequestBase for more details
665 // about the other parameters.
666 InitiateUploadNewFileRequest(RequestSender
* sender
,
667 const DriveApiUrlGenerator
& url_generator
,
668 const std::string
& content_type
,
669 int64 content_length
,
670 const std::string
& parent_resource_id
,
671 const std::string
& title
,
672 const InitiateUploadCallback
& callback
);
673 virtual ~InitiateUploadNewFileRequest();
675 // Optional parameters.
676 const base::Time
& modified_date() const { return modified_date_
; }
677 void set_modified_date(const base::Time
& modified_date
) {
678 modified_date_
= modified_date
;
680 const base::Time
& last_viewed_by_me_date() const {
681 return last_viewed_by_me_date_
;
683 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
684 last_viewed_by_me_date_
= last_viewed_by_me_date
;
688 // UrlFetchRequestBase overrides.
689 virtual GURL
GetURL() const OVERRIDE
;
690 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
691 virtual bool GetContentData(std::string
* upload_content_type
,
692 std::string
* upload_content
) OVERRIDE
;
695 const DriveApiUrlGenerator url_generator_
;
696 const std::string parent_resource_id_
;
697 const std::string title_
;
699 base::Time modified_date_
;
700 base::Time last_viewed_by_me_date_
;
702 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest
);
705 //==================== InitiateUploadExistingFileRequest =====================
707 // This class performs the request for initiating the upload of an existing
709 class InitiateUploadExistingFileRequest
: public InitiateUploadRequestBase
{
711 // |upload_url| should be the upload_url() of the file
712 // (resumable-create-media URL)
713 // |etag| should be set if it is available to detect the upload confliction.
714 // See also the comments of InitiateUploadRequestBase for more details
715 // about the other parameters.
716 InitiateUploadExistingFileRequest(RequestSender
* sender
,
717 const DriveApiUrlGenerator
& url_generator
,
718 const std::string
& content_type
,
719 int64 content_length
,
720 const std::string
& resource_id
,
721 const std::string
& etag
,
722 const InitiateUploadCallback
& callback
);
723 virtual ~InitiateUploadExistingFileRequest();
726 // Optional parameters.
727 const std::string
& parent_resource_id() const { return parent_resource_id_
; }
728 void set_parent_resource_id(const std::string
& parent_resource_id
) {
729 parent_resource_id_
= parent_resource_id
;
731 const std::string
& title() const { return title_
; }
732 void set_title(const std::string
& title
) { title_
= title
; }
733 const base::Time
& modified_date() const { return modified_date_
; }
734 void set_modified_date(const base::Time
& modified_date
) {
735 modified_date_
= modified_date
;
737 const base::Time
& last_viewed_by_me_date() const {
738 return last_viewed_by_me_date_
;
740 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
741 last_viewed_by_me_date_
= last_viewed_by_me_date
;
745 // UrlFetchRequestBase overrides.
746 virtual GURL
GetURL() const OVERRIDE
;
747 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
748 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
749 virtual bool GetContentData(std::string
* upload_content_type
,
750 std::string
* upload_content
) OVERRIDE
;
753 const DriveApiUrlGenerator url_generator_
;
754 const std::string resource_id_
;
755 const std::string etag_
;
757 std::string parent_resource_id_
;
759 base::Time modified_date_
;
760 base::Time last_viewed_by_me_date_
;
762 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest
);
765 // Callback used for ResumeUpload() and GetUploadStatus().
766 typedef base::Callback
<void(
767 const UploadRangeResponse
& response
,
768 scoped_ptr
<FileResource
> new_resource
)> UploadRangeCallback
;
770 //============================ ResumeUploadRequest ===========================
772 // Performs the request for resuming the upload of a file.
773 class ResumeUploadRequest
: public ResumeUploadRequestBase
{
775 // See also ResumeUploadRequestBase's comment for parameters meaning.
776 // |callback| must not be null. |progress_callback| may be null.
777 ResumeUploadRequest(RequestSender
* sender
,
778 const GURL
& upload_location
,
779 int64 start_position
,
781 int64 content_length
,
782 const std::string
& content_type
,
783 const base::FilePath
& local_file_path
,
784 const UploadRangeCallback
& callback
,
785 const ProgressCallback
& progress_callback
);
786 virtual ~ResumeUploadRequest();
789 // UploadRangeRequestBase overrides.
790 virtual void OnRangeRequestComplete(
791 const UploadRangeResponse
& response
,
792 scoped_ptr
<base::Value
> value
) OVERRIDE
;
793 // content::UrlFetcherDelegate overrides.
794 virtual void OnURLFetchUploadProgress(const net::URLFetcher
* source
,
795 int64 current
, int64 total
) OVERRIDE
;
798 const UploadRangeCallback callback_
;
799 const ProgressCallback progress_callback_
;
801 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest
);
804 //========================== GetUploadStatusRequest ==========================
806 // Performs the request to fetch the current upload status of a file.
807 class GetUploadStatusRequest
: public GetUploadStatusRequestBase
{
809 // See also GetUploadStatusRequestBase's comment for parameters meaning.
810 // |callback| must not be null.
811 GetUploadStatusRequest(RequestSender
* sender
,
812 const GURL
& upload_url
,
813 int64 content_length
,
814 const UploadRangeCallback
& callback
);
815 virtual ~GetUploadStatusRequest();
818 // UploadRangeRequestBase overrides.
819 virtual void OnRangeRequestComplete(
820 const UploadRangeResponse
& response
,
821 scoped_ptr
<base::Value
> value
) OVERRIDE
;
824 const UploadRangeCallback callback_
;
826 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest
);
829 //========================== DownloadFileRequest ==========================
831 // This class performs the request for downloading of a specified file.
832 class DownloadFileRequest
: public DownloadFileRequestBase
{
834 // See also DownloadFileRequestBase's comment for parameters meaning.
835 DownloadFileRequest(RequestSender
* sender
,
836 const DriveApiUrlGenerator
& url_generator
,
837 const std::string
& resource_id
,
838 const base::FilePath
& output_file_path
,
839 const DownloadActionCallback
& download_action_callback
,
840 const GetContentCallback
& get_content_callback
,
841 const ProgressCallback
& progress_callback
);
842 virtual ~DownloadFileRequest();
844 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest
);
847 //========================== PermissionsInsertRequest ==========================
849 // Enumeration type for specifying type of permissions.
850 enum PermissionType
{
851 PERMISSION_TYPE_ANYONE
,
852 PERMISSION_TYPE_DOMAIN
,
853 PERMISSION_TYPE_GROUP
,
854 PERMISSION_TYPE_USER
,
857 // Enumeration type for specifying the role of permissions.
858 enum PermissionRole
{
859 PERMISSION_ROLE_OWNER
,
860 PERMISSION_ROLE_READER
,
861 PERMISSION_ROLE_WRITER
,
862 PERMISSION_ROLE_COMMENTER
,
865 // This class performs the request for adding permission on a specified file.
866 class PermissionsInsertRequest
: public EntryActionRequest
{
868 // See https://developers.google.com/drive/v2/reference/permissions/insert.
869 PermissionsInsertRequest(RequestSender
* sender
,
870 const DriveApiUrlGenerator
& url_generator
,
871 const EntryActionCallback
& callback
);
872 virtual ~PermissionsInsertRequest();
874 void set_id(const std::string
& id
) { id_
= id
; }
875 void set_type(PermissionType type
) { type_
= type
; }
876 void set_role(PermissionRole role
) { role_
= role
; }
877 void set_value(const std::string
& value
) { value_
= value
; }
879 // UrlFetchRequestBase overrides.
880 virtual GURL
GetURL() const OVERRIDE
;
881 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
882 virtual bool GetContentData(std::string
* upload_content_type
,
883 std::string
* upload_content
) OVERRIDE
;
886 const DriveApiUrlGenerator url_generator_
;
888 PermissionType type_
;
889 PermissionRole role_
;
892 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest
);
896 } // namespace google_apis
898 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_