Upstream SIGNOUT_ALLOWED pref for AccountManagementFragment.
[chromium-blink-merge.git] / google_apis / drive / drive_api_requests.h
blob92afc873a0744b0373b9090200dfab42cfe477c6
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_
8 #include <string>
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 FileList data
24 // formatted into JSON value.
25 typedef base::Callback<void(GDataErrorCode error,
26 scoped_ptr<FileList> entry)> FileListCallback;
28 // Callback used for requests that the server returns ChangeList data
29 // formatted into JSON value.
30 typedef base::Callback<void(GDataErrorCode error,
31 scoped_ptr<ChangeList> entry)> ChangeListCallback;
33 namespace drive {
35 //============================ DriveApiPartialFieldRequest ====================
37 // This is base class of the Drive API related requests. All Drive API requests
38 // support partial request (to improve the performance). The function can be
39 // shared among the Drive API requests.
40 // See also https://developers.google.com/drive/performance
41 class DriveApiPartialFieldRequest : public UrlFetchRequestBase {
42 public:
43 explicit DriveApiPartialFieldRequest(RequestSender* sender);
44 ~DriveApiPartialFieldRequest() override;
46 // Optional parameter.
47 const std::string& fields() const { return fields_; }
48 void set_fields(const std::string& fields) { fields_ = fields; }
50 protected:
51 // UrlFetchRequestBase overrides.
52 GURL GetURL() const override;
54 // Derived classes should override GetURLInternal instead of GetURL()
55 // directly.
56 virtual GURL GetURLInternal() const = 0;
58 private:
59 std::string fields_;
61 DISALLOW_COPY_AND_ASSIGN(DriveApiPartialFieldRequest);
64 //============================ DriveApiDataRequest ===========================
66 // The base class of Drive API related requests that receive a JSON response
67 // representing |DataType|.
68 template<class DataType>
69 class DriveApiDataRequest : public DriveApiPartialFieldRequest {
70 public:
71 typedef base::Callback<void(GDataErrorCode error,
72 scoped_ptr<DataType> data)> Callback;
74 // |callback| is called when the request finishes either by success or by
75 // failure. On success, a JSON Value object is passed. It must not be null.
76 DriveApiDataRequest(RequestSender* sender, const Callback& callback)
77 : DriveApiPartialFieldRequest(sender),
78 callback_(callback),
79 weak_ptr_factory_(this) {
80 DCHECK(!callback_.is_null());
82 virtual ~DriveApiDataRequest() {}
84 protected:
85 // UrlFetchRequestBase overrides.
86 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override {
87 GDataErrorCode error = GetErrorCode();
88 switch (error) {
89 case HTTP_SUCCESS:
90 case HTTP_CREATED:
91 base::PostTaskAndReplyWithResult(
92 blocking_task_runner(),
93 FROM_HERE,
94 base::Bind(&DriveApiDataRequest::Parse, response_writer()->data()),
95 base::Bind(&DriveApiDataRequest::OnDataParsed,
96 weak_ptr_factory_.GetWeakPtr(), error));
97 break;
98 default:
99 RunCallbackOnPrematureFailure(error);
100 OnProcessURLFetchResultsComplete();
101 break;
105 virtual void RunCallbackOnPrematureFailure(GDataErrorCode error) override {
106 callback_.Run(error, scoped_ptr<DataType>());
109 private:
110 // Parses the |json| string by using DataType::CreateFrom.
111 static scoped_ptr<DataType> Parse(const std::string& json) {
112 scoped_ptr<base::Value> value = ParseJson(json);
113 return value ? DataType::CreateFrom(*value) : scoped_ptr<DataType>();
116 // Receives the parsed result and invokes the callback.
117 void OnDataParsed(GDataErrorCode error, scoped_ptr<DataType> value) {
118 if (!value)
119 error = GDATA_PARSE_ERROR;
120 callback_.Run(error, value.Pass());
121 OnProcessURLFetchResultsComplete();
124 const Callback callback_;
126 // Note: This should remain the last member so it'll be destroyed and
127 // invalidate its weak pointers before any other members are destroyed.
128 base::WeakPtrFactory<DriveApiDataRequest> weak_ptr_factory_;
130 DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest);
133 //=============================== FilesGetRequest =============================
135 // This class performs the request for fetching a file.
136 // This request is mapped to
137 // https://developers.google.com/drive/v2/reference/files/get
138 class FilesGetRequest : public DriveApiDataRequest<FileResource> {
139 public:
140 FilesGetRequest(RequestSender* sender,
141 const DriveApiUrlGenerator& url_generator,
142 bool use_internal_endpoint,
143 const FileResourceCallback& callback);
144 ~FilesGetRequest() override;
146 // Required parameter.
147 const std::string& file_id() const { return file_id_; }
148 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
150 // Optional parameter.
151 const GURL& embed_origin() const { return embed_origin_; }
152 void set_embed_origin(const GURL& embed_origin) {
153 embed_origin_ = embed_origin;
156 protected:
157 // Overridden from DriveApiDataRequest.
158 GURL GetURLInternal() const override;
160 private:
161 const DriveApiUrlGenerator url_generator_;
162 const bool use_internal_endpoint_;
163 std::string file_id_;
164 GURL embed_origin_;
166 DISALLOW_COPY_AND_ASSIGN(FilesGetRequest);
169 //============================ FilesAuthorizeRequest ===========================
171 // This class performs request for authorizing an app to access a file.
172 // This request is mapped to /drive/v2internal/file/authorize internal endpoint.
173 class FilesAuthorizeRequest : public DriveApiDataRequest<FileResource> {
174 public:
175 FilesAuthorizeRequest(RequestSender* sender,
176 const DriveApiUrlGenerator& url_generator,
177 const FileResourceCallback& callback);
178 ~FilesAuthorizeRequest() override;
180 // Required parameter.
181 const std::string& file_id() const { return file_id_; }
182 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
183 const std::string& app_id() const { return app_id_; }
184 void set_app_id(const std::string& app_id) { app_id_ = app_id; }
186 protected:
187 // Overridden from GetDataRequest.
188 net::URLFetcher::RequestType GetRequestType() const override;
190 // Overridden from DriveApiDataRequest.
191 GURL GetURLInternal() const override;
193 private:
194 const DriveApiUrlGenerator url_generator_;
195 std::string file_id_;
196 std::string app_id_;
198 DISALLOW_COPY_AND_ASSIGN(FilesAuthorizeRequest);
201 //============================ FilesInsertRequest =============================
203 // This class performs the request for creating a resource.
204 // This request is mapped to
205 // https://developers.google.com/drive/v2/reference/files/insert
206 // See also https://developers.google.com/drive/manage-uploads and
207 // https://developers.google.com/drive/folder
208 class FilesInsertRequest : public DriveApiDataRequest<FileResource> {
209 public:
210 FilesInsertRequest(RequestSender* sender,
211 const DriveApiUrlGenerator& url_generator,
212 const FileResourceCallback& callback);
213 ~FilesInsertRequest() override;
215 // Optional request body.
216 const base::Time& last_viewed_by_me_date() const {
217 return last_viewed_by_me_date_;
219 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
220 last_viewed_by_me_date_ = last_viewed_by_me_date;
223 const std::string& mime_type() const { return mime_type_; }
224 void set_mime_type(const std::string& mime_type) {
225 mime_type_ = mime_type;
228 const base::Time& modified_date() const { return modified_date_; }
229 void set_modified_date(const base::Time& modified_date) {
230 modified_date_ = modified_date;
233 const std::vector<std::string>& parents() const { return parents_; }
234 void add_parent(const std::string& parent) { parents_.push_back(parent); }
236 const std::string& title() const { return title_; }
237 void set_title(const std::string& title) { title_ = title; }
239 protected:
240 // Overridden from GetDataRequest.
241 net::URLFetcher::RequestType GetRequestType() const override;
242 bool GetContentData(std::string* upload_content_type,
243 std::string* upload_content) override;
245 // Overridden from DriveApiDataRequest.
246 GURL GetURLInternal() const override;
248 private:
249 const DriveApiUrlGenerator url_generator_;
251 base::Time last_viewed_by_me_date_;
252 std::string mime_type_;
253 base::Time modified_date_;
254 std::vector<std::string> parents_;
255 std::string title_;
257 DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest);
260 //============================== FilesPatchRequest ============================
262 // This class performs the request for patching file metadata.
263 // This request is mapped to
264 // https://developers.google.com/drive/v2/reference/files/patch
265 class FilesPatchRequest : public DriveApiDataRequest<FileResource> {
266 public:
267 FilesPatchRequest(RequestSender* sender,
268 const DriveApiUrlGenerator& url_generator,
269 const FileResourceCallback& callback);
270 ~FilesPatchRequest() override;
272 // Required parameter.
273 const std::string& file_id() const { return file_id_; }
274 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
276 // Optional parameter.
277 bool set_modified_date() const { return set_modified_date_; }
278 void set_set_modified_date(bool set_modified_date) {
279 set_modified_date_ = set_modified_date;
282 bool update_viewed_date() const { return update_viewed_date_; }
283 void set_update_viewed_date(bool update_viewed_date) {
284 update_viewed_date_ = update_viewed_date;
287 // Optional request body.
288 // Note: "Files: patch" accepts any "Files resource" data, but this class
289 // only supports limited members of it for now. We can extend it upon
290 // requirments.
291 const std::string& title() const { return title_; }
292 void set_title(const std::string& title) { title_ = title; }
294 const base::Time& modified_date() const { return modified_date_; }
295 void set_modified_date(const base::Time& modified_date) {
296 modified_date_ = modified_date;
299 const base::Time& last_viewed_by_me_date() const {
300 return last_viewed_by_me_date_;
302 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
303 last_viewed_by_me_date_ = last_viewed_by_me_date;
306 const std::vector<std::string>& parents() const { return parents_; }
307 void add_parent(const std::string& parent) { parents_.push_back(parent); }
309 protected:
310 // Overridden from URLFetchRequestBase.
311 net::URLFetcher::RequestType GetRequestType() const override;
312 std::vector<std::string> GetExtraRequestHeaders() const override;
313 bool GetContentData(std::string* upload_content_type,
314 std::string* upload_content) override;
316 // Overridden from DriveApiDataRequest.
317 GURL GetURLInternal() const override;
319 private:
320 const DriveApiUrlGenerator url_generator_;
322 std::string file_id_;
323 bool set_modified_date_;
324 bool update_viewed_date_;
326 std::string title_;
327 base::Time modified_date_;
328 base::Time last_viewed_by_me_date_;
329 std::vector<std::string> parents_;
331 DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest);
334 //============================= FilesCopyRequest ==============================
336 // This class performs the request for copying a resource.
337 // This request is mapped to
338 // https://developers.google.com/drive/v2/reference/files/copy
339 class FilesCopyRequest : public DriveApiDataRequest<FileResource> {
340 public:
341 // Upon completion, |callback| will be called. |callback| must not be null.
342 FilesCopyRequest(RequestSender* sender,
343 const DriveApiUrlGenerator& url_generator,
344 const FileResourceCallback& callback);
345 ~FilesCopyRequest() override;
347 // Required parameter.
348 const std::string& file_id() const { return file_id_; }
349 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
351 // Optional request body.
352 const std::vector<std::string>& parents() const { return parents_; }
353 void add_parent(const std::string& parent) { parents_.push_back(parent); }
355 const base::Time& modified_date() const { return modified_date_; }
356 void set_modified_date(const base::Time& modified_date) {
357 modified_date_ = modified_date;
360 const std::string& title() const { return title_; }
361 void set_title(const std::string& title) { title_ = title; }
363 protected:
364 // Overridden from URLFetchRequestBase.
365 net::URLFetcher::RequestType GetRequestType() const override;
366 bool GetContentData(std::string* upload_content_type,
367 std::string* upload_content) override;
369 // Overridden from DriveApiDataRequest.
370 GURL GetURLInternal() const override;
372 private:
373 const DriveApiUrlGenerator url_generator_;
375 std::string file_id_;
376 base::Time modified_date_;
377 std::vector<std::string> parents_;
378 std::string title_;
380 DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest);
383 //============================= FilesListRequest =============================
385 // This class performs the request for fetching FileList.
386 // The result may contain only first part of the result. The remaining result
387 // should be able to be fetched by ContinueGetFileListRequest defined below,
388 // or by FilesListRequest with setting page token.
389 // This request is mapped to
390 // https://developers.google.com/drive/v2/reference/files/list
391 class FilesListRequest : public DriveApiDataRequest<FileList> {
392 public:
393 FilesListRequest(RequestSender* sender,
394 const DriveApiUrlGenerator& url_generator,
395 const FileListCallback& callback);
396 ~FilesListRequest() override;
398 // Optional parameter
399 int max_results() const { return max_results_; }
400 void set_max_results(int max_results) { max_results_ = max_results; }
402 const std::string& page_token() const { return page_token_; }
403 void set_page_token(const std::string& page_token) {
404 page_token_ = page_token;
407 const std::string& q() const { return q_; }
408 void set_q(const std::string& q) { q_ = q; }
410 protected:
411 // Overridden from DriveApiDataRequest.
412 GURL GetURLInternal() const override;
414 private:
415 const DriveApiUrlGenerator url_generator_;
416 int max_results_;
417 std::string page_token_;
418 std::string q_;
420 DISALLOW_COPY_AND_ASSIGN(FilesListRequest);
423 //========================= FilesListNextPageRequest ==========================
425 // There are two ways to obtain next pages of "Files: list" result (if paged).
426 // 1) Set pageToken and all params used for the initial request.
427 // 2) Use URL in the nextLink field in the previous response.
428 // This class implements 2)'s request.
429 class FilesListNextPageRequest : public DriveApiDataRequest<FileList> {
430 public:
431 FilesListNextPageRequest(RequestSender* sender,
432 const FileListCallback& callback);
433 ~FilesListNextPageRequest() override;
435 const GURL& next_link() const { return next_link_; }
436 void set_next_link(const GURL& next_link) { next_link_ = next_link; }
438 protected:
439 // Overridden from DriveApiDataRequest.
440 GURL GetURLInternal() const override;
442 private:
443 GURL next_link_;
445 DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest);
448 //============================= FilesDeleteRequest =============================
450 // This class performs the request for deleting a resource.
451 // This request is mapped to
452 // https://developers.google.com/drive/v2/reference/files/delete
453 class FilesDeleteRequest : public EntryActionRequest {
454 public:
455 FilesDeleteRequest(RequestSender* sender,
456 const DriveApiUrlGenerator& url_generator,
457 const EntryActionCallback& callback);
458 ~FilesDeleteRequest() override;
460 // Required parameter.
461 const std::string& file_id() const { return file_id_; }
462 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
463 void set_etag(const std::string& etag) { etag_ = etag; }
465 protected:
466 // Overridden from UrlFetchRequestBase.
467 net::URLFetcher::RequestType GetRequestType() const override;
468 GURL GetURL() const override;
469 std::vector<std::string> GetExtraRequestHeaders() const override;
471 private:
472 const DriveApiUrlGenerator url_generator_;
473 std::string file_id_;
474 std::string etag_;
476 DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest);
479 //============================= FilesTrashRequest ==============================
481 // This class performs the request for trashing a resource.
482 // This request is mapped to
483 // https://developers.google.com/drive/v2/reference/files/trash
484 class FilesTrashRequest : public DriveApiDataRequest<FileResource> {
485 public:
486 FilesTrashRequest(RequestSender* sender,
487 const DriveApiUrlGenerator& url_generator,
488 const FileResourceCallback& callback);
489 ~FilesTrashRequest() override;
491 // Required parameter.
492 const std::string& file_id() const { return file_id_; }
493 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
495 protected:
496 // Overridden from UrlFetchRequestBase.
497 net::URLFetcher::RequestType GetRequestType() const override;
499 // Overridden from DriveApiDataRequest.
500 GURL GetURLInternal() const override;
502 private:
503 const DriveApiUrlGenerator url_generator_;
504 std::string file_id_;
506 DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest);
509 //============================== AboutGetRequest =============================
511 // This class performs the request for fetching About data.
512 // This request is mapped to
513 // https://developers.google.com/drive/v2/reference/about/get
514 class AboutGetRequest : public DriveApiDataRequest<AboutResource> {
515 public:
516 AboutGetRequest(RequestSender* sender,
517 const DriveApiUrlGenerator& url_generator,
518 const AboutResourceCallback& callback);
519 ~AboutGetRequest() override;
521 protected:
522 // Overridden from DriveApiDataRequest.
523 GURL GetURLInternal() const override;
525 private:
526 const DriveApiUrlGenerator url_generator_;
528 DISALLOW_COPY_AND_ASSIGN(AboutGetRequest);
531 //============================ ChangesListRequest ============================
533 // This class performs the request for fetching ChangeList.
534 // The result may contain only first part of the result. The remaining result
535 // should be able to be fetched by ContinueGetFileListRequest defined below.
536 // or by ChangesListRequest with setting page token.
537 // This request is mapped to
538 // https://developers.google.com/drive/v2/reference/changes/list
539 class ChangesListRequest : public DriveApiDataRequest<ChangeList> {
540 public:
541 ChangesListRequest(RequestSender* sender,
542 const DriveApiUrlGenerator& url_generator,
543 const ChangeListCallback& callback);
544 ~ChangesListRequest() override;
546 // Optional parameter
547 bool include_deleted() const { return include_deleted_; }
548 void set_include_deleted(bool include_deleted) {
549 include_deleted_ = include_deleted;
552 int max_results() const { return max_results_; }
553 void set_max_results(int max_results) { max_results_ = max_results; }
555 const std::string& page_token() const { return page_token_; }
556 void set_page_token(const std::string& page_token) {
557 page_token_ = page_token;
560 int64 start_change_id() const { return start_change_id_; }
561 void set_start_change_id(int64 start_change_id) {
562 start_change_id_ = start_change_id;
565 protected:
566 // Overridden from DriveApiDataRequest.
567 GURL GetURLInternal() const override;
569 private:
570 const DriveApiUrlGenerator url_generator_;
571 bool include_deleted_;
572 int max_results_;
573 std::string page_token_;
574 int64 start_change_id_;
576 DISALLOW_COPY_AND_ASSIGN(ChangesListRequest);
579 //======================== ChangesListNextPageRequest =========================
581 // There are two ways to obtain next pages of "Changes: list" result (if paged).
582 // 1) Set pageToken and all params used for the initial request.
583 // 2) Use URL in the nextLink field in the previous response.
584 // This class implements 2)'s request.
585 class ChangesListNextPageRequest : public DriveApiDataRequest<ChangeList> {
586 public:
587 ChangesListNextPageRequest(RequestSender* sender,
588 const ChangeListCallback& callback);
589 ~ChangesListNextPageRequest() override;
591 const GURL& next_link() const { return next_link_; }
592 void set_next_link(const GURL& next_link) { next_link_ = next_link; }
594 protected:
595 // Overridden from DriveApiDataRequest.
596 GURL GetURLInternal() const override;
598 private:
599 GURL next_link_;
601 DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest);
604 //============================= AppsListRequest ============================
606 // This class performs the request for fetching AppList.
607 // This request is mapped to
608 // https://developers.google.com/drive/v2/reference/apps/list
609 class AppsListRequest : public DriveApiDataRequest<AppList> {
610 public:
611 AppsListRequest(RequestSender* sender,
612 const DriveApiUrlGenerator& url_generator,
613 bool use_internal_endpoint,
614 const AppListCallback& callback);
615 ~AppsListRequest() override;
617 protected:
618 // Overridden from DriveApiDataRequest.
619 GURL GetURLInternal() const override;
621 private:
622 const DriveApiUrlGenerator url_generator_;
623 const bool use_internal_endpoint_;
625 DISALLOW_COPY_AND_ASSIGN(AppsListRequest);
628 //============================= AppsDeleteRequest ==============================
630 // This class performs the request for deleting a Drive app.
631 // This request is mapped to
632 // https://developers.google.com/drive/v2/reference/files/trash
633 class AppsDeleteRequest : public EntryActionRequest {
634 public:
635 AppsDeleteRequest(RequestSender* sender,
636 const DriveApiUrlGenerator& url_generator,
637 const EntryActionCallback& callback);
638 ~AppsDeleteRequest() override;
640 // Required parameter.
641 const std::string& app_id() const { return app_id_; }
642 void set_app_id(const std::string& app_id) { app_id_ = app_id; }
644 protected:
645 // Overridden from UrlFetchRequestBase.
646 net::URLFetcher::RequestType GetRequestType() const override;
647 GURL GetURL() const override;
649 private:
650 const DriveApiUrlGenerator url_generator_;
651 std::string app_id_;
653 DISALLOW_COPY_AND_ASSIGN(AppsDeleteRequest);
656 //========================== ChildrenInsertRequest ============================
658 // This class performs the request for inserting a resource to a directory.
659 // This request is mapped to
660 // https://developers.google.com/drive/v2/reference/children/insert
661 class ChildrenInsertRequest : public EntryActionRequest {
662 public:
663 ChildrenInsertRequest(RequestSender* sender,
664 const DriveApiUrlGenerator& url_generator,
665 const EntryActionCallback& callback);
666 ~ChildrenInsertRequest() override;
668 // Required parameter.
669 const std::string& folder_id() const { return folder_id_; }
670 void set_folder_id(const std::string& folder_id) {
671 folder_id_ = folder_id;
674 // Required body.
675 const std::string& id() const { return id_; }
676 void set_id(const std::string& id) { id_ = id; }
678 protected:
679 // UrlFetchRequestBase overrides.
680 net::URLFetcher::RequestType GetRequestType() const override;
681 GURL GetURL() const override;
682 bool GetContentData(std::string* upload_content_type,
683 std::string* upload_content) override;
685 private:
686 const DriveApiUrlGenerator url_generator_;
687 std::string folder_id_;
688 std::string id_;
690 DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest);
693 //========================== ChildrenDeleteRequest ============================
695 // This class performs the request for removing a resource from a directory.
696 // This request is mapped to
697 // https://developers.google.com/drive/v2/reference/children/delete
698 class ChildrenDeleteRequest : public EntryActionRequest {
699 public:
700 // |callback| must not be null.
701 ChildrenDeleteRequest(RequestSender* sender,
702 const DriveApiUrlGenerator& url_generator,
703 const EntryActionCallback& callback);
704 ~ChildrenDeleteRequest() override;
706 // Required parameter.
707 const std::string& child_id() const { return child_id_; }
708 void set_child_id(const std::string& child_id) {
709 child_id_ = child_id;
712 const std::string& folder_id() const { return folder_id_; }
713 void set_folder_id(const std::string& folder_id) {
714 folder_id_ = folder_id;
717 protected:
718 // UrlFetchRequestBase overrides.
719 net::URLFetcher::RequestType GetRequestType() const override;
720 GURL GetURL() const override;
722 private:
723 const DriveApiUrlGenerator url_generator_;
724 std::string child_id_;
725 std::string folder_id_;
727 DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest);
730 //======================= InitiateUploadNewFileRequest =======================
732 // This class performs the request for initiating the upload of a new file.
733 class InitiateUploadNewFileRequest : public InitiateUploadRequestBase {
734 public:
735 // |parent_resource_id| should be the resource id of the parent directory.
736 // |title| should be set.
737 // See also the comments of InitiateUploadRequestBase for more details
738 // about the other parameters.
739 InitiateUploadNewFileRequest(RequestSender* sender,
740 const DriveApiUrlGenerator& url_generator,
741 const std::string& content_type,
742 int64 content_length,
743 const std::string& parent_resource_id,
744 const std::string& title,
745 const InitiateUploadCallback& callback);
746 ~InitiateUploadNewFileRequest() override;
748 // Optional parameters.
749 const base::Time& modified_date() const { return modified_date_; }
750 void set_modified_date(const base::Time& modified_date) {
751 modified_date_ = modified_date;
753 const base::Time& last_viewed_by_me_date() const {
754 return last_viewed_by_me_date_;
756 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
757 last_viewed_by_me_date_ = last_viewed_by_me_date;
760 protected:
761 // UrlFetchRequestBase overrides.
762 GURL GetURL() const override;
763 net::URLFetcher::RequestType GetRequestType() const override;
764 bool GetContentData(std::string* upload_content_type,
765 std::string* upload_content) override;
767 private:
768 const DriveApiUrlGenerator url_generator_;
769 const std::string parent_resource_id_;
770 const std::string title_;
772 base::Time modified_date_;
773 base::Time last_viewed_by_me_date_;
775 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest);
778 //==================== InitiateUploadExistingFileRequest =====================
780 // This class performs the request for initiating the upload of an existing
781 // file.
782 class InitiateUploadExistingFileRequest : public InitiateUploadRequestBase {
783 public:
784 // |upload_url| should be the upload_url() of the file
785 // (resumable-create-media URL)
786 // |etag| should be set if it is available to detect the upload confliction.
787 // See also the comments of InitiateUploadRequestBase for more details
788 // about the other parameters.
789 InitiateUploadExistingFileRequest(RequestSender* sender,
790 const DriveApiUrlGenerator& url_generator,
791 const std::string& content_type,
792 int64 content_length,
793 const std::string& resource_id,
794 const std::string& etag,
795 const InitiateUploadCallback& callback);
796 ~InitiateUploadExistingFileRequest() override;
798 // Optional parameters.
799 const std::string& parent_resource_id() const { return parent_resource_id_; }
800 void set_parent_resource_id(const std::string& parent_resource_id) {
801 parent_resource_id_ = parent_resource_id;
803 const std::string& title() const { return title_; }
804 void set_title(const std::string& title) { title_ = title; }
805 const base::Time& modified_date() const { return modified_date_; }
806 void set_modified_date(const base::Time& modified_date) {
807 modified_date_ = modified_date;
809 const base::Time& last_viewed_by_me_date() const {
810 return last_viewed_by_me_date_;
812 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
813 last_viewed_by_me_date_ = last_viewed_by_me_date;
816 protected:
817 // UrlFetchRequestBase overrides.
818 GURL GetURL() const override;
819 net::URLFetcher::RequestType GetRequestType() const override;
820 std::vector<std::string> GetExtraRequestHeaders() const override;
821 bool GetContentData(std::string* upload_content_type,
822 std::string* upload_content) override;
824 private:
825 const DriveApiUrlGenerator url_generator_;
826 const std::string resource_id_;
827 const std::string etag_;
829 std::string parent_resource_id_;
830 std::string title_;
831 base::Time modified_date_;
832 base::Time last_viewed_by_me_date_;
834 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest);
837 // Callback used for ResumeUpload() and GetUploadStatus().
838 typedef base::Callback<void(
839 const UploadRangeResponse& response,
840 scoped_ptr<FileResource> new_resource)> UploadRangeCallback;
842 //============================ ResumeUploadRequest ===========================
844 // Performs the request for resuming the upload of a file.
845 class ResumeUploadRequest : public ResumeUploadRequestBase {
846 public:
847 // See also ResumeUploadRequestBase's comment for parameters meaning.
848 // |callback| must not be null. |progress_callback| may be null.
849 ResumeUploadRequest(RequestSender* sender,
850 const GURL& upload_location,
851 int64 start_position,
852 int64 end_position,
853 int64 content_length,
854 const std::string& content_type,
855 const base::FilePath& local_file_path,
856 const UploadRangeCallback& callback,
857 const ProgressCallback& progress_callback);
858 ~ResumeUploadRequest() override;
860 protected:
861 // UploadRangeRequestBase overrides.
862 void OnRangeRequestComplete(const UploadRangeResponse& response,
863 scoped_ptr<base::Value> value) override;
864 // content::UrlFetcherDelegate overrides.
865 void OnURLFetchUploadProgress(const net::URLFetcher* source,
866 int64 current,
867 int64 total) override;
869 private:
870 const UploadRangeCallback callback_;
871 const ProgressCallback progress_callback_;
873 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest);
876 //========================== GetUploadStatusRequest ==========================
878 // Performs the request to fetch the current upload status of a file.
879 class GetUploadStatusRequest : public GetUploadStatusRequestBase {
880 public:
881 // See also GetUploadStatusRequestBase's comment for parameters meaning.
882 // |callback| must not be null.
883 GetUploadStatusRequest(RequestSender* sender,
884 const GURL& upload_url,
885 int64 content_length,
886 const UploadRangeCallback& callback);
887 ~GetUploadStatusRequest() override;
889 protected:
890 // UploadRangeRequestBase overrides.
891 void OnRangeRequestComplete(const UploadRangeResponse& response,
892 scoped_ptr<base::Value> value) override;
894 private:
895 const UploadRangeCallback callback_;
897 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest);
900 //======================= MultipartUploadNewFileRequest =======================
902 // This class performs the request for initiating the upload of a new file.
903 class MultipartUploadNewFileRequest : public MultipartUploadRequestBase {
904 public:
905 // |parent_resource_id| should be the resource id of the parent directory.
906 // |title| should be set.
907 // See also the comments of MultipartUploadRequestBase for more details
908 // about the other parameters.
909 MultipartUploadNewFileRequest(RequestSender* sender,
910 const std::string& title,
911 const std::string& parent_resource_id,
912 const std::string& content_type,
913 int64 content_length,
914 const base::Time& modified_date,
915 const base::Time& last_viewed_by_me_date,
916 const base::FilePath& local_file_path,
917 const DriveApiUrlGenerator& url_generator,
918 const FileResourceCallback& callback,
919 const ProgressCallback& progress_callback);
920 ~MultipartUploadNewFileRequest() override;
922 protected:
923 // UrlFetchRequestBase overrides.
924 GURL GetURL() const override;
925 net::URLFetcher::RequestType GetRequestType() const override;
927 private:
928 const DriveApiUrlGenerator url_generator_;
930 DISALLOW_COPY_AND_ASSIGN(MultipartUploadNewFileRequest);
933 //======================= MultipartUploadExistingFileRequest ===================
935 // This class performs the request for initiating the upload of a new file.
936 class MultipartUploadExistingFileRequest : public MultipartUploadRequestBase {
937 public:
938 // |parent_resource_id| should be the resource id of the parent directory.
939 // |title| should be set.
940 // See also the comments of MultipartUploadRequestBase for more details
941 // about the other parameters.
942 MultipartUploadExistingFileRequest(RequestSender* sender,
943 const std::string& title,
944 const std::string& resource_id,
945 const std::string& parent_resource_id,
946 const std::string& content_type,
947 int64 content_length,
948 const base::Time& modified_date,
949 const base::Time& last_viewed_by_me_date,
950 const base::FilePath& local_file_path,
951 const std::string& etag,
952 const DriveApiUrlGenerator& url_generator,
953 const FileResourceCallback& callback,
954 const ProgressCallback& progress_callback);
955 ~MultipartUploadExistingFileRequest() override;
957 protected:
958 // UrlFetchRequestBase overrides.
959 std::vector<std::string> GetExtraRequestHeaders() const override;
960 GURL GetURL() const override;
961 net::URLFetcher::RequestType GetRequestType() const override;
963 private:
964 const std::string resource_id_;
965 const std::string etag_;
966 const DriveApiUrlGenerator url_generator_;
968 DISALLOW_COPY_AND_ASSIGN(MultipartUploadExistingFileRequest);
971 //========================== DownloadFileRequest ==========================
973 // This class performs the request for downloading of a specified file.
974 class DownloadFileRequest : public DownloadFileRequestBase {
975 public:
976 // See also DownloadFileRequestBase's comment for parameters meaning.
977 DownloadFileRequest(RequestSender* sender,
978 const DriveApiUrlGenerator& url_generator,
979 const std::string& resource_id,
980 const base::FilePath& output_file_path,
981 const DownloadActionCallback& download_action_callback,
982 const GetContentCallback& get_content_callback,
983 const ProgressCallback& progress_callback);
984 ~DownloadFileRequest() override;
986 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest);
989 //========================== PermissionsInsertRequest ==========================
991 // Enumeration type for specifying type of permissions.
992 enum PermissionType {
993 PERMISSION_TYPE_ANYONE,
994 PERMISSION_TYPE_DOMAIN,
995 PERMISSION_TYPE_GROUP,
996 PERMISSION_TYPE_USER,
999 // Enumeration type for specifying the role of permissions.
1000 enum PermissionRole {
1001 PERMISSION_ROLE_OWNER,
1002 PERMISSION_ROLE_READER,
1003 PERMISSION_ROLE_WRITER,
1004 PERMISSION_ROLE_COMMENTER,
1007 // This class performs the request for adding permission on a specified file.
1008 class PermissionsInsertRequest : public EntryActionRequest {
1009 public:
1010 // See https://developers.google.com/drive/v2/reference/permissions/insert.
1011 PermissionsInsertRequest(RequestSender* sender,
1012 const DriveApiUrlGenerator& url_generator,
1013 const EntryActionCallback& callback);
1014 ~PermissionsInsertRequest() override;
1016 void set_id(const std::string& id) { id_ = id; }
1017 void set_type(PermissionType type) { type_ = type; }
1018 void set_role(PermissionRole role) { role_ = role; }
1019 void set_value(const std::string& value) { value_ = value; }
1021 // UrlFetchRequestBase overrides.
1022 GURL GetURL() const override;
1023 net::URLFetcher::RequestType GetRequestType() const override;
1024 bool GetContentData(std::string* upload_content_type,
1025 std::string* upload_content) override;
1027 private:
1028 const DriveApiUrlGenerator url_generator_;
1029 std::string id_;
1030 PermissionType type_;
1031 PermissionRole role_;
1032 std::string value_;
1034 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest);
1037 } // namespace drive
1038 } // namespace google_apis
1040 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_