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/location.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/task_runner_util.h"
14 #include "base/time/time.h"
15 #include "base/values.h"
16 #include "google_apis/drive/base_requests.h"
17 #include "google_apis/drive/drive_api_parser.h"
18 #include "google_apis/drive/drive_api_url_generator.h"
19 #include "google_apis/drive/drive_common_callbacks.h"
21 namespace google_apis
{
23 // Callback used for requests that the server returns FileResource data
24 // formatted into JSON value.
25 typedef base::Callback
<void(GDataErrorCode error
,
26 scoped_ptr
<FileResource
> entry
)>
29 // Callback used for requests that the server returns FileList data
30 // formatted into JSON value.
31 typedef base::Callback
<void(GDataErrorCode error
,
32 scoped_ptr
<FileList
> entry
)> FileListCallback
;
34 // Callback used for requests that the server returns ChangeList data
35 // formatted into JSON value.
36 typedef base::Callback
<void(GDataErrorCode error
,
37 scoped_ptr
<ChangeList
> entry
)> ChangeListCallback
;
41 //============================ DriveApiPartialFieldRequest ====================
43 // This is base class of the Drive API related requests. All Drive API requests
44 // support partial request (to improve the performance). The function can be
45 // shared among the Drive API requests.
46 // See also https://developers.google.com/drive/performance
47 class DriveApiPartialFieldRequest
: public UrlFetchRequestBase
{
49 explicit DriveApiPartialFieldRequest(RequestSender
* sender
);
50 virtual ~DriveApiPartialFieldRequest();
52 // Optional parameter.
53 const std::string
& fields() const { return fields_
; }
54 void set_fields(const std::string
& fields
) { fields_
= fields
; }
57 // UrlFetchRequestBase overrides.
58 virtual GURL
GetURL() const override
;
60 // Derived classes should override GetURLInternal instead of GetURL()
62 virtual GURL
GetURLInternal() const = 0;
67 DISALLOW_COPY_AND_ASSIGN(DriveApiPartialFieldRequest
);
70 //============================ DriveApiDataRequest ===========================
72 // The base class of Drive API related requests that receive a JSON response
73 // representing |DataType|.
74 template<class DataType
>
75 class DriveApiDataRequest
: public DriveApiPartialFieldRequest
{
77 typedef base::Callback
<void(GDataErrorCode error
,
78 scoped_ptr
<DataType
> data
)> Callback
;
80 // |callback| is called when the request finishes either by success or by
81 // failure. On success, a JSON Value object is passed. It must not be null.
82 DriveApiDataRequest(RequestSender
* sender
, const Callback
& callback
)
83 : DriveApiPartialFieldRequest(sender
),
85 weak_ptr_factory_(this) {
86 DCHECK(!callback_
.is_null());
88 virtual ~DriveApiDataRequest() {}
91 // UrlFetchRequestBase overrides.
92 virtual void ProcessURLFetchResults(const net::URLFetcher
* source
) override
{
93 GDataErrorCode error
= GetErrorCode();
97 base::PostTaskAndReplyWithResult(
98 blocking_task_runner(),
100 base::Bind(&DriveApiDataRequest::Parse
, response_writer()->data()),
101 base::Bind(&DriveApiDataRequest::OnDataParsed
,
102 weak_ptr_factory_
.GetWeakPtr(), error
));
105 RunCallbackOnPrematureFailure(error
);
106 OnProcessURLFetchResultsComplete();
111 virtual void RunCallbackOnPrematureFailure(GDataErrorCode error
) override
{
112 callback_
.Run(error
, scoped_ptr
<DataType
>());
116 // Parses the |json| string by using DataType::CreateFrom.
117 static scoped_ptr
<DataType
> Parse(const std::string
& json
) {
118 scoped_ptr
<base::Value
> value
= ParseJson(json
);
119 return value
? DataType::CreateFrom(*value
) : scoped_ptr
<DataType
>();
122 // Receives the parsed result and invokes the callback.
123 void OnDataParsed(GDataErrorCode error
, scoped_ptr
<DataType
> value
) {
125 error
= GDATA_PARSE_ERROR
;
126 callback_
.Run(error
, value
.Pass());
127 OnProcessURLFetchResultsComplete();
130 const Callback callback_
;
132 // Note: This should remain the last member so it'll be destroyed and
133 // invalidate its weak pointers before any other members are destroyed.
134 base::WeakPtrFactory
<DriveApiDataRequest
> weak_ptr_factory_
;
136 DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest
);
139 //=============================== FilesGetRequest =============================
141 // This class performs the request for fetching a file.
142 // This request is mapped to
143 // https://developers.google.com/drive/v2/reference/files/get
144 class FilesGetRequest
: public DriveApiDataRequest
<FileResource
> {
146 FilesGetRequest(RequestSender
* sender
,
147 const DriveApiUrlGenerator
& url_generator
,
148 const FileResourceCallback
& callback
);
149 virtual ~FilesGetRequest();
151 // Required parameter.
152 const std::string
& file_id() const { return file_id_
; }
153 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
156 // Overridden from DriveApiDataRequest.
157 virtual GURL
GetURLInternal() const override
;
160 const DriveApiUrlGenerator url_generator_
;
161 std::string file_id_
;
163 DISALLOW_COPY_AND_ASSIGN(FilesGetRequest
);
166 //============================ FilesAuthorizeRequest ===========================
168 // This class performs request for authorizing an app to access a file.
169 // This request is mapped to /drive/v2internal/file/authorize internal endpoint.
170 class FilesAuthorizeRequest
: public DriveApiDataRequest
<FileResource
> {
172 FilesAuthorizeRequest(RequestSender
* sender
,
173 const DriveApiUrlGenerator
& url_generator
,
174 const FileResourceCallback
& callback
);
175 virtual ~FilesAuthorizeRequest();
177 // Required parameter.
178 const std::string
& file_id() const { return file_id_
; }
179 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
180 const std::string
& app_id() const { return app_id_
; }
181 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
184 // Overridden from GetDataRequest.
185 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
187 // Overridden from DriveApiDataRequest.
188 virtual GURL
GetURLInternal() const override
;
191 const DriveApiUrlGenerator url_generator_
;
192 std::string file_id_
;
195 DISALLOW_COPY_AND_ASSIGN(FilesAuthorizeRequest
);
198 //============================ FilesInsertRequest =============================
200 // This class performs the request for creating a resource.
201 // This request is mapped to
202 // https://developers.google.com/drive/v2/reference/files/insert
203 // See also https://developers.google.com/drive/manage-uploads and
204 // https://developers.google.com/drive/folder
205 class FilesInsertRequest
: public DriveApiDataRequest
<FileResource
> {
207 FilesInsertRequest(RequestSender
* sender
,
208 const DriveApiUrlGenerator
& url_generator
,
209 const FileResourceCallback
& callback
);
210 virtual ~FilesInsertRequest();
212 // Optional request body.
213 const base::Time
& last_viewed_by_me_date() const {
214 return last_viewed_by_me_date_
;
216 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
217 last_viewed_by_me_date_
= last_viewed_by_me_date
;
220 const std::string
& mime_type() const { return mime_type_
; }
221 void set_mime_type(const std::string
& mime_type
) {
222 mime_type_
= mime_type
;
225 const base::Time
& modified_date() const { return modified_date_
; }
226 void set_modified_date(const base::Time
& modified_date
) {
227 modified_date_
= modified_date
;
230 const std::vector
<std::string
>& parents() const { return parents_
; }
231 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
233 const std::string
& title() const { return title_
; }
234 void set_title(const std::string
& title
) { title_
= title
; }
237 // Overridden from GetDataRequest.
238 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
239 virtual bool GetContentData(std::string
* upload_content_type
,
240 std::string
* upload_content
) override
;
242 // Overridden from DriveApiDataRequest.
243 virtual GURL
GetURLInternal() const override
;
246 const DriveApiUrlGenerator url_generator_
;
248 base::Time last_viewed_by_me_date_
;
249 std::string mime_type_
;
250 base::Time modified_date_
;
251 std::vector
<std::string
> parents_
;
254 DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest
);
257 //============================== FilesPatchRequest ============================
259 // This class performs the request for patching file metadata.
260 // This request is mapped to
261 // https://developers.google.com/drive/v2/reference/files/patch
262 class FilesPatchRequest
: public DriveApiDataRequest
<FileResource
> {
264 FilesPatchRequest(RequestSender
* sender
,
265 const DriveApiUrlGenerator
& url_generator
,
266 const FileResourceCallback
& callback
);
267 virtual ~FilesPatchRequest();
269 // Required parameter.
270 const std::string
& file_id() const { return file_id_
; }
271 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
273 // Optional parameter.
274 bool set_modified_date() const { return set_modified_date_
; }
275 void set_set_modified_date(bool set_modified_date
) {
276 set_modified_date_
= set_modified_date
;
279 bool update_viewed_date() const { return update_viewed_date_
; }
280 void set_update_viewed_date(bool update_viewed_date
) {
281 update_viewed_date_
= update_viewed_date
;
284 // Optional request body.
285 // Note: "Files: patch" accepts any "Files resource" data, but this class
286 // only supports limited members of it for now. We can extend it upon
288 const std::string
& title() const { return title_
; }
289 void set_title(const std::string
& title
) { title_
= title
; }
291 const base::Time
& modified_date() const { return modified_date_
; }
292 void set_modified_date(const base::Time
& modified_date
) {
293 modified_date_
= modified_date
;
296 const base::Time
& last_viewed_by_me_date() const {
297 return last_viewed_by_me_date_
;
299 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
300 last_viewed_by_me_date_
= last_viewed_by_me_date
;
303 const std::vector
<std::string
>& parents() const { return parents_
; }
304 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
307 // Overridden from URLFetchRequestBase.
308 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
309 virtual std::vector
<std::string
> GetExtraRequestHeaders() const override
;
310 virtual bool GetContentData(std::string
* upload_content_type
,
311 std::string
* upload_content
) override
;
313 // Overridden from DriveApiDataRequest.
314 virtual GURL
GetURLInternal() const override
;
317 const DriveApiUrlGenerator url_generator_
;
319 std::string file_id_
;
320 bool set_modified_date_
;
321 bool update_viewed_date_
;
324 base::Time modified_date_
;
325 base::Time last_viewed_by_me_date_
;
326 std::vector
<std::string
> parents_
;
328 DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest
);
331 //============================= FilesCopyRequest ==============================
333 // This class performs the request for copying a resource.
334 // This request is mapped to
335 // https://developers.google.com/drive/v2/reference/files/copy
336 class FilesCopyRequest
: public DriveApiDataRequest
<FileResource
> {
338 // Upon completion, |callback| will be called. |callback| must not be null.
339 FilesCopyRequest(RequestSender
* sender
,
340 const DriveApiUrlGenerator
& url_generator
,
341 const FileResourceCallback
& callback
);
342 virtual ~FilesCopyRequest();
344 // Required parameter.
345 const std::string
& file_id() const { return file_id_
; }
346 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
348 // Optional request body.
349 const std::vector
<std::string
>& parents() const { return parents_
; }
350 void add_parent(const std::string
& parent
) { parents_
.push_back(parent
); }
352 const base::Time
& modified_date() const { return modified_date_
; }
353 void set_modified_date(const base::Time
& modified_date
) {
354 modified_date_
= modified_date
;
357 const std::string
& title() const { return title_
; }
358 void set_title(const std::string
& title
) { title_
= title
; }
361 // Overridden from URLFetchRequestBase.
362 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
363 virtual bool GetContentData(std::string
* upload_content_type
,
364 std::string
* upload_content
) override
;
366 // Overridden from DriveApiDataRequest.
367 virtual GURL
GetURLInternal() const override
;
370 const DriveApiUrlGenerator url_generator_
;
372 std::string file_id_
;
373 base::Time modified_date_
;
374 std::vector
<std::string
> parents_
;
377 DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest
);
380 //============================= FilesListRequest =============================
382 // This class performs the request for fetching FileList.
383 // The result may contain only first part of the result. The remaining result
384 // should be able to be fetched by ContinueGetFileListRequest defined below,
385 // or by FilesListRequest with setting page token.
386 // This request is mapped to
387 // https://developers.google.com/drive/v2/reference/files/list
388 class FilesListRequest
: public DriveApiDataRequest
<FileList
> {
390 FilesListRequest(RequestSender
* sender
,
391 const DriveApiUrlGenerator
& url_generator
,
392 const FileListCallback
& callback
);
393 virtual ~FilesListRequest();
395 // Optional parameter
396 int max_results() const { return max_results_
; }
397 void set_max_results(int max_results
) { max_results_
= max_results
; }
399 const std::string
& page_token() const { return page_token_
; }
400 void set_page_token(const std::string
& page_token
) {
401 page_token_
= page_token
;
404 const std::string
& q() const { return q_
; }
405 void set_q(const std::string
& q
) { q_
= q
; }
408 // Overridden from DriveApiDataRequest.
409 virtual GURL
GetURLInternal() const override
;
412 const DriveApiUrlGenerator url_generator_
;
414 std::string page_token_
;
417 DISALLOW_COPY_AND_ASSIGN(FilesListRequest
);
420 //========================= FilesListNextPageRequest ==========================
422 // There are two ways to obtain next pages of "Files: list" result (if paged).
423 // 1) Set pageToken and all params used for the initial request.
424 // 2) Use URL in the nextLink field in the previous response.
425 // This class implements 2)'s request.
426 class FilesListNextPageRequest
: public DriveApiDataRequest
<FileList
> {
428 FilesListNextPageRequest(RequestSender
* sender
,
429 const FileListCallback
& callback
);
430 virtual ~FilesListNextPageRequest();
432 const GURL
& next_link() const { return next_link_
; }
433 void set_next_link(const GURL
& next_link
) { next_link_
= next_link
; }
436 // Overridden from DriveApiDataRequest.
437 virtual GURL
GetURLInternal() const override
;
442 DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest
);
445 //============================= FilesDeleteRequest =============================
447 // This class performs the request for deleting a resource.
448 // This request is mapped to
449 // https://developers.google.com/drive/v2/reference/files/delete
450 class FilesDeleteRequest
: public EntryActionRequest
{
452 FilesDeleteRequest(RequestSender
* sender
,
453 const DriveApiUrlGenerator
& url_generator
,
454 const EntryActionCallback
& callback
);
455 virtual ~FilesDeleteRequest();
457 // Required parameter.
458 const std::string
& file_id() const { return file_id_
; }
459 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
460 void set_etag(const std::string
& etag
) { etag_
= etag
; }
463 // Overridden from UrlFetchRequestBase.
464 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
465 virtual GURL
GetURL() const override
;
466 virtual std::vector
<std::string
> GetExtraRequestHeaders() const override
;
469 const DriveApiUrlGenerator url_generator_
;
470 std::string file_id_
;
473 DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest
);
476 //============================= FilesTrashRequest ==============================
478 // This class performs the request for trashing a resource.
479 // This request is mapped to
480 // https://developers.google.com/drive/v2/reference/files/trash
481 class FilesTrashRequest
: public DriveApiDataRequest
<FileResource
> {
483 FilesTrashRequest(RequestSender
* sender
,
484 const DriveApiUrlGenerator
& url_generator
,
485 const FileResourceCallback
& callback
);
486 virtual ~FilesTrashRequest();
488 // Required parameter.
489 const std::string
& file_id() const { return file_id_
; }
490 void set_file_id(const std::string
& file_id
) { file_id_
= file_id
; }
493 // Overridden from UrlFetchRequestBase.
494 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
496 // Overridden from DriveApiDataRequest.
497 virtual GURL
GetURLInternal() const override
;
500 const DriveApiUrlGenerator url_generator_
;
501 std::string file_id_
;
503 DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest
);
506 //============================== AboutGetRequest =============================
508 // This class performs the request for fetching About data.
509 // This request is mapped to
510 // https://developers.google.com/drive/v2/reference/about/get
511 class AboutGetRequest
: public DriveApiDataRequest
<AboutResource
> {
513 AboutGetRequest(RequestSender
* sender
,
514 const DriveApiUrlGenerator
& url_generator
,
515 const AboutResourceCallback
& callback
);
516 virtual ~AboutGetRequest();
519 // Overridden from DriveApiDataRequest.
520 virtual GURL
GetURLInternal() const override
;
523 const DriveApiUrlGenerator url_generator_
;
525 DISALLOW_COPY_AND_ASSIGN(AboutGetRequest
);
528 //============================ ChangesListRequest ============================
530 // This class performs the request for fetching ChangeList.
531 // The result may contain only first part of the result. The remaining result
532 // should be able to be fetched by ContinueGetFileListRequest defined below.
533 // or by ChangesListRequest with setting page token.
534 // This request is mapped to
535 // https://developers.google.com/drive/v2/reference/changes/list
536 class ChangesListRequest
: public DriveApiDataRequest
<ChangeList
> {
538 ChangesListRequest(RequestSender
* sender
,
539 const DriveApiUrlGenerator
& url_generator
,
540 const ChangeListCallback
& callback
);
541 virtual ~ChangesListRequest();
543 // Optional parameter
544 bool include_deleted() const { return include_deleted_
; }
545 void set_include_deleted(bool include_deleted
) {
546 include_deleted_
= include_deleted
;
549 int max_results() const { return max_results_
; }
550 void set_max_results(int max_results
) { max_results_
= max_results
; }
552 const std::string
& page_token() const { return page_token_
; }
553 void set_page_token(const std::string
& page_token
) {
554 page_token_
= page_token
;
557 int64
start_change_id() const { return start_change_id_
; }
558 void set_start_change_id(int64 start_change_id
) {
559 start_change_id_
= start_change_id
;
563 // Overridden from DriveApiDataRequest.
564 virtual GURL
GetURLInternal() const override
;
567 const DriveApiUrlGenerator url_generator_
;
568 bool include_deleted_
;
570 std::string page_token_
;
571 int64 start_change_id_
;
573 DISALLOW_COPY_AND_ASSIGN(ChangesListRequest
);
576 //======================== ChangesListNextPageRequest =========================
578 // There are two ways to obtain next pages of "Changes: list" result (if paged).
579 // 1) Set pageToken and all params used for the initial request.
580 // 2) Use URL in the nextLink field in the previous response.
581 // This class implements 2)'s request.
582 class ChangesListNextPageRequest
: public DriveApiDataRequest
<ChangeList
> {
584 ChangesListNextPageRequest(RequestSender
* sender
,
585 const ChangeListCallback
& callback
);
586 virtual ~ChangesListNextPageRequest();
588 const GURL
& next_link() const { return next_link_
; }
589 void set_next_link(const GURL
& next_link
) { next_link_
= next_link
; }
592 // Overridden from DriveApiDataRequest.
593 virtual GURL
GetURLInternal() const override
;
598 DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest
);
601 //============================= AppsListRequest ============================
603 // This class performs the request for fetching AppList.
604 // This request is mapped to
605 // https://developers.google.com/drive/v2/reference/apps/list
606 class AppsListRequest
: public DriveApiDataRequest
<AppList
> {
608 AppsListRequest(RequestSender
* sender
,
609 const DriveApiUrlGenerator
& url_generator
,
610 bool use_internal_endpoint
,
611 const AppListCallback
& callback
);
612 virtual ~AppsListRequest();
615 // Overridden from DriveApiDataRequest.
616 virtual GURL
GetURLInternal() const override
;
619 const DriveApiUrlGenerator url_generator_
;
620 bool use_internal_endpoint_
;
622 DISALLOW_COPY_AND_ASSIGN(AppsListRequest
);
625 //============================= AppsDeleteRequest ==============================
627 // This class performs the request for deleting a Drive app.
628 // This request is mapped to
629 // https://developers.google.com/drive/v2/reference/files/trash
630 class AppsDeleteRequest
: public EntryActionRequest
{
632 AppsDeleteRequest(RequestSender
* sender
,
633 const DriveApiUrlGenerator
& url_generator
,
634 const EntryActionCallback
& callback
);
635 virtual ~AppsDeleteRequest();
637 // Required parameter.
638 const std::string
& app_id() const { return app_id_
; }
639 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
642 // Overridden from UrlFetchRequestBase.
643 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
644 virtual GURL
GetURL() const override
;
647 const DriveApiUrlGenerator url_generator_
;
650 DISALLOW_COPY_AND_ASSIGN(AppsDeleteRequest
);
653 //========================== ChildrenInsertRequest ============================
655 // This class performs the request for inserting a resource to a directory.
656 // This request is mapped to
657 // https://developers.google.com/drive/v2/reference/children/insert
658 class ChildrenInsertRequest
: public EntryActionRequest
{
660 ChildrenInsertRequest(RequestSender
* sender
,
661 const DriveApiUrlGenerator
& url_generator
,
662 const EntryActionCallback
& callback
);
663 virtual ~ChildrenInsertRequest();
665 // Required parameter.
666 const std::string
& folder_id() const { return folder_id_
; }
667 void set_folder_id(const std::string
& folder_id
) {
668 folder_id_
= folder_id
;
672 const std::string
& id() const { return id_
; }
673 void set_id(const std::string
& id
) { id_
= id
; }
676 // UrlFetchRequestBase overrides.
677 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
678 virtual GURL
GetURL() const override
;
679 virtual bool GetContentData(std::string
* upload_content_type
,
680 std::string
* upload_content
) override
;
683 const DriveApiUrlGenerator url_generator_
;
684 std::string folder_id_
;
687 DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest
);
690 //========================== ChildrenDeleteRequest ============================
692 // This class performs the request for removing a resource from a directory.
693 // This request is mapped to
694 // https://developers.google.com/drive/v2/reference/children/delete
695 class ChildrenDeleteRequest
: public EntryActionRequest
{
697 // |callback| must not be null.
698 ChildrenDeleteRequest(RequestSender
* sender
,
699 const DriveApiUrlGenerator
& url_generator
,
700 const EntryActionCallback
& callback
);
701 virtual ~ChildrenDeleteRequest();
703 // Required parameter.
704 const std::string
& child_id() const { return child_id_
; }
705 void set_child_id(const std::string
& child_id
) {
706 child_id_
= child_id
;
709 const std::string
& folder_id() const { return folder_id_
; }
710 void set_folder_id(const std::string
& folder_id
) {
711 folder_id_
= folder_id
;
715 // UrlFetchRequestBase overrides.
716 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
717 virtual GURL
GetURL() const override
;
720 const DriveApiUrlGenerator url_generator_
;
721 std::string child_id_
;
722 std::string folder_id_
;
724 DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest
);
727 //======================= InitiateUploadNewFileRequest =======================
729 // This class performs the request for initiating the upload of a new file.
730 class InitiateUploadNewFileRequest
: public InitiateUploadRequestBase
{
732 // |parent_resource_id| should be the resource id of the parent directory.
733 // |title| should be set.
734 // See also the comments of InitiateUploadRequestBase for more details
735 // about the other parameters.
736 InitiateUploadNewFileRequest(RequestSender
* sender
,
737 const DriveApiUrlGenerator
& url_generator
,
738 const std::string
& content_type
,
739 int64 content_length
,
740 const std::string
& parent_resource_id
,
741 const std::string
& title
,
742 const InitiateUploadCallback
& callback
);
743 virtual ~InitiateUploadNewFileRequest();
745 // Optional parameters.
746 const base::Time
& modified_date() const { return modified_date_
; }
747 void set_modified_date(const base::Time
& modified_date
) {
748 modified_date_
= modified_date
;
750 const base::Time
& last_viewed_by_me_date() const {
751 return last_viewed_by_me_date_
;
753 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
754 last_viewed_by_me_date_
= last_viewed_by_me_date
;
758 // UrlFetchRequestBase overrides.
759 virtual GURL
GetURL() const override
;
760 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
761 virtual bool GetContentData(std::string
* upload_content_type
,
762 std::string
* upload_content
) override
;
765 const DriveApiUrlGenerator url_generator_
;
766 const std::string parent_resource_id_
;
767 const std::string title_
;
769 base::Time modified_date_
;
770 base::Time last_viewed_by_me_date_
;
772 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest
);
775 //==================== InitiateUploadExistingFileRequest =====================
777 // This class performs the request for initiating the upload of an existing
779 class InitiateUploadExistingFileRequest
: public InitiateUploadRequestBase
{
781 // |upload_url| should be the upload_url() of the file
782 // (resumable-create-media URL)
783 // |etag| should be set if it is available to detect the upload confliction.
784 // See also the comments of InitiateUploadRequestBase for more details
785 // about the other parameters.
786 InitiateUploadExistingFileRequest(RequestSender
* sender
,
787 const DriveApiUrlGenerator
& url_generator
,
788 const std::string
& content_type
,
789 int64 content_length
,
790 const std::string
& resource_id
,
791 const std::string
& etag
,
792 const InitiateUploadCallback
& callback
);
793 virtual ~InitiateUploadExistingFileRequest();
796 // Optional parameters.
797 const std::string
& parent_resource_id() const { return parent_resource_id_
; }
798 void set_parent_resource_id(const std::string
& parent_resource_id
) {
799 parent_resource_id_
= parent_resource_id
;
801 const std::string
& title() const { return title_
; }
802 void set_title(const std::string
& title
) { title_
= title
; }
803 const base::Time
& modified_date() const { return modified_date_
; }
804 void set_modified_date(const base::Time
& modified_date
) {
805 modified_date_
= modified_date
;
807 const base::Time
& last_viewed_by_me_date() const {
808 return last_viewed_by_me_date_
;
810 void set_last_viewed_by_me_date(const base::Time
& last_viewed_by_me_date
) {
811 last_viewed_by_me_date_
= last_viewed_by_me_date
;
815 // UrlFetchRequestBase overrides.
816 virtual GURL
GetURL() const override
;
817 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
818 virtual std::vector
<std::string
> GetExtraRequestHeaders() const override
;
819 virtual bool GetContentData(std::string
* upload_content_type
,
820 std::string
* upload_content
) override
;
823 const DriveApiUrlGenerator url_generator_
;
824 const std::string resource_id_
;
825 const std::string etag_
;
827 std::string parent_resource_id_
;
829 base::Time modified_date_
;
830 base::Time last_viewed_by_me_date_
;
832 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest
);
835 // Callback used for ResumeUpload() and GetUploadStatus().
836 typedef base::Callback
<void(
837 const UploadRangeResponse
& response
,
838 scoped_ptr
<FileResource
> new_resource
)> UploadRangeCallback
;
840 //============================ ResumeUploadRequest ===========================
842 // Performs the request for resuming the upload of a file.
843 class ResumeUploadRequest
: public ResumeUploadRequestBase
{
845 // See also ResumeUploadRequestBase's comment for parameters meaning.
846 // |callback| must not be null. |progress_callback| may be null.
847 ResumeUploadRequest(RequestSender
* sender
,
848 const GURL
& upload_location
,
849 int64 start_position
,
851 int64 content_length
,
852 const std::string
& content_type
,
853 const base::FilePath
& local_file_path
,
854 const UploadRangeCallback
& callback
,
855 const ProgressCallback
& progress_callback
);
856 virtual ~ResumeUploadRequest();
859 // UploadRangeRequestBase overrides.
860 virtual void OnRangeRequestComplete(
861 const UploadRangeResponse
& response
,
862 scoped_ptr
<base::Value
> value
) override
;
863 // content::UrlFetcherDelegate overrides.
864 virtual void OnURLFetchUploadProgress(const net::URLFetcher
* source
,
865 int64 current
, int64 total
) override
;
868 const UploadRangeCallback callback_
;
869 const ProgressCallback progress_callback_
;
871 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest
);
874 //========================== GetUploadStatusRequest ==========================
876 // Performs the request to fetch the current upload status of a file.
877 class GetUploadStatusRequest
: public GetUploadStatusRequestBase
{
879 // See also GetUploadStatusRequestBase's comment for parameters meaning.
880 // |callback| must not be null.
881 GetUploadStatusRequest(RequestSender
* sender
,
882 const GURL
& upload_url
,
883 int64 content_length
,
884 const UploadRangeCallback
& callback
);
885 virtual ~GetUploadStatusRequest();
888 // UploadRangeRequestBase overrides.
889 virtual void OnRangeRequestComplete(
890 const UploadRangeResponse
& response
,
891 scoped_ptr
<base::Value
> value
) override
;
894 const UploadRangeCallback callback_
;
896 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest
);
899 //========================== DownloadFileRequest ==========================
901 // This class performs the request for downloading of a specified file.
902 class DownloadFileRequest
: public DownloadFileRequestBase
{
904 // See also DownloadFileRequestBase's comment for parameters meaning.
905 DownloadFileRequest(RequestSender
* sender
,
906 const DriveApiUrlGenerator
& url_generator
,
907 const std::string
& resource_id
,
908 const base::FilePath
& output_file_path
,
909 const DownloadActionCallback
& download_action_callback
,
910 const GetContentCallback
& get_content_callback
,
911 const ProgressCallback
& progress_callback
);
912 virtual ~DownloadFileRequest();
914 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest
);
917 //========================== PermissionsInsertRequest ==========================
919 // Enumeration type for specifying type of permissions.
920 enum PermissionType
{
921 PERMISSION_TYPE_ANYONE
,
922 PERMISSION_TYPE_DOMAIN
,
923 PERMISSION_TYPE_GROUP
,
924 PERMISSION_TYPE_USER
,
927 // Enumeration type for specifying the role of permissions.
928 enum PermissionRole
{
929 PERMISSION_ROLE_OWNER
,
930 PERMISSION_ROLE_READER
,
931 PERMISSION_ROLE_WRITER
,
932 PERMISSION_ROLE_COMMENTER
,
935 // This class performs the request for adding permission on a specified file.
936 class PermissionsInsertRequest
: public EntryActionRequest
{
938 // See https://developers.google.com/drive/v2/reference/permissions/insert.
939 PermissionsInsertRequest(RequestSender
* sender
,
940 const DriveApiUrlGenerator
& url_generator
,
941 const EntryActionCallback
& callback
);
942 virtual ~PermissionsInsertRequest();
944 void set_id(const std::string
& id
) { id_
= id
; }
945 void set_type(PermissionType type
) { type_
= type
; }
946 void set_role(PermissionRole role
) { role_
= role
; }
947 void set_value(const std::string
& value
) { value_
= value
; }
949 // UrlFetchRequestBase overrides.
950 virtual GURL
GetURL() const override
;
951 virtual net::URLFetcher::RequestType
GetRequestType() const override
;
952 virtual bool GetContentData(std::string
* upload_content_type
,
953 std::string
* upload_content
) override
;
956 const DriveApiUrlGenerator url_generator_
;
958 PermissionType type_
;
959 PermissionRole role_
;
962 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest
);
966 } // namespace google_apis
968 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_