[NaCl SDK] nacl_io: Fix bad test added in def60c00.
[chromium-blink-merge.git] / google_apis / drive / drive_api_requests.h
blob00f310a16f2ae2cadc1ff4e178bb35bff8c04472
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>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/location.h"
13 #include "base/sequenced_task_runner.h"
14 #include "base/task_runner_util.h"
15 #include "base/time/time.h"
16 #include "base/values.h"
17 #include "google_apis/drive/base_requests.h"
18 #include "google_apis/drive/drive_api_parser.h"
19 #include "google_apis/drive/drive_api_url_generator.h"
20 #include "google_apis/drive/drive_common_callbacks.h"
22 namespace google_apis {
24 // Callback used for requests that the server returns FileList data
25 // formatted into JSON value.
26 typedef base::Callback<void(DriveApiErrorCode error,
27 scoped_ptr<FileList> entry)> FileListCallback;
29 // Callback used for requests that the server returns ChangeList data
30 // formatted into JSON value.
31 typedef base::Callback<void(DriveApiErrorCode error,
32 scoped_ptr<ChangeList> entry)> ChangeListCallback;
34 namespace drive {
36 // Represents a property for a file or a directory.
37 // https://developers.google.com/drive/v2/reference/properties
38 class Property {
39 public:
40 Property();
41 ~Property();
43 // Visibility of the property. Either limited to the same client, or to any.
44 enum Visibility { VISIBILITY_PRIVATE, VISIBILITY_PUBLIC };
46 // Whether the property is public or private.
47 Visibility visibility() const { return visibility_; }
49 // Name of the property.
50 const std::string& key() const { return key_; }
52 // Value of the property.
53 const std::string& value() const { return value_; }
55 void set_visibility(Visibility visibility) { visibility_ = visibility; }
56 void set_key(const std::string& key) { key_ = key; }
57 void set_value(const std::string& value) { value_ = value; }
59 private:
60 Visibility visibility_;
61 std::string key_;
62 std::string value_;
65 // List of properties for a single file or a directory.
66 typedef std::vector<Property> Properties;
68 //============================ DriveApiPartialFieldRequest ====================
70 // This is base class of the Drive API related requests. All Drive API requests
71 // support partial request (to improve the performance). The function can be
72 // shared among the Drive API requests.
73 // See also https://developers.google.com/drive/performance
74 class DriveApiPartialFieldRequest : public UrlFetchRequestBase {
75 public:
76 explicit DriveApiPartialFieldRequest(RequestSender* sender);
77 ~DriveApiPartialFieldRequest() override;
79 // Optional parameter.
80 const std::string& fields() const { return fields_; }
81 void set_fields(const std::string& fields) { fields_ = fields; }
83 protected:
84 // UrlFetchRequestBase overrides.
85 GURL GetURL() const override;
87 // Derived classes should override GetURLInternal instead of GetURL()
88 // directly.
89 virtual GURL GetURLInternal() const = 0;
91 private:
92 std::string fields_;
94 DISALLOW_COPY_AND_ASSIGN(DriveApiPartialFieldRequest);
97 //============================ DriveApiDataRequest ===========================
99 // The base class of Drive API related requests that receive a JSON response
100 // representing |DataType|.
101 template<class DataType>
102 class DriveApiDataRequest : public DriveApiPartialFieldRequest {
103 public:
104 typedef base::Callback<void(DriveApiErrorCode error,
105 scoped_ptr<DataType> data)> Callback;
107 // |callback| is called when the request finishes either by success or by
108 // failure. On success, a JSON Value object is passed. It must not be null.
109 DriveApiDataRequest(RequestSender* sender, const Callback& callback)
110 : DriveApiPartialFieldRequest(sender),
111 callback_(callback),
112 weak_ptr_factory_(this) {
113 DCHECK(!callback_.is_null());
115 virtual ~DriveApiDataRequest() {}
117 protected:
118 // UrlFetchRequestBase overrides.
119 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override {
120 DriveApiErrorCode error = GetErrorCode();
121 switch (error) {
122 case HTTP_SUCCESS:
123 case HTTP_CREATED:
124 base::PostTaskAndReplyWithResult(
125 blocking_task_runner(),
126 FROM_HERE,
127 base::Bind(&DriveApiDataRequest::Parse, response_writer()->data()),
128 base::Bind(&DriveApiDataRequest::OnDataParsed,
129 weak_ptr_factory_.GetWeakPtr(), error));
130 break;
131 default:
132 RunCallbackOnPrematureFailure(error);
133 OnProcessURLFetchResultsComplete();
134 break;
138 virtual void RunCallbackOnPrematureFailure(DriveApiErrorCode error) override {
139 callback_.Run(error, scoped_ptr<DataType>());
142 private:
143 // Parses the |json| string by using DataType::CreateFrom.
144 static scoped_ptr<DataType> Parse(const std::string& json) {
145 scoped_ptr<base::Value> value = ParseJson(json);
146 return value ? DataType::CreateFrom(*value) : scoped_ptr<DataType>();
149 // Receives the parsed result and invokes the callback.
150 void OnDataParsed(DriveApiErrorCode error, scoped_ptr<DataType> value) {
151 if (!value)
152 error = DRIVE_PARSE_ERROR;
153 callback_.Run(error, value.Pass());
154 OnProcessURLFetchResultsComplete();
157 const Callback callback_;
159 // Note: This should remain the last member so it'll be destroyed and
160 // invalidate its weak pointers before any other members are destroyed.
161 base::WeakPtrFactory<DriveApiDataRequest> weak_ptr_factory_;
163 DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest);
166 //=============================== FilesGetRequest =============================
168 // This class performs the request for fetching a file.
169 // This request is mapped to
170 // https://developers.google.com/drive/v2/reference/files/get
171 class FilesGetRequest : public DriveApiDataRequest<FileResource> {
172 public:
173 FilesGetRequest(RequestSender* sender,
174 const DriveApiUrlGenerator& url_generator,
175 bool use_internal_endpoint,
176 const FileResourceCallback& callback);
177 ~FilesGetRequest() override;
179 // Required parameter.
180 const std::string& file_id() const { return file_id_; }
181 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
183 // Optional parameter.
184 const GURL& embed_origin() const { return embed_origin_; }
185 void set_embed_origin(const GURL& embed_origin) {
186 embed_origin_ = embed_origin;
189 protected:
190 // Overridden from DriveApiDataRequest.
191 GURL GetURLInternal() const override;
193 private:
194 const DriveApiUrlGenerator url_generator_;
195 const bool use_internal_endpoint_;
196 std::string file_id_;
197 GURL embed_origin_;
199 DISALLOW_COPY_AND_ASSIGN(FilesGetRequest);
202 //============================ FilesAuthorizeRequest ===========================
204 // This class performs request for authorizing an app to access a file.
205 // This request is mapped to /drive/v2internal/file/authorize internal endpoint.
206 class FilesAuthorizeRequest : public DriveApiDataRequest<FileResource> {
207 public:
208 FilesAuthorizeRequest(RequestSender* sender,
209 const DriveApiUrlGenerator& url_generator,
210 const FileResourceCallback& callback);
211 ~FilesAuthorizeRequest() override;
213 // Required parameter.
214 const std::string& file_id() const { return file_id_; }
215 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
216 const std::string& app_id() const { return app_id_; }
217 void set_app_id(const std::string& app_id) { app_id_ = app_id; }
219 protected:
220 // Overridden from GetDataRequest.
221 net::URLFetcher::RequestType GetRequestType() const override;
223 // Overridden from DriveApiDataRequest.
224 GURL GetURLInternal() const override;
226 private:
227 const DriveApiUrlGenerator url_generator_;
228 std::string file_id_;
229 std::string app_id_;
231 DISALLOW_COPY_AND_ASSIGN(FilesAuthorizeRequest);
234 //============================ FilesInsertRequest =============================
236 // This class performs the request for creating a resource.
237 // This request is mapped to
238 // https://developers.google.com/drive/v2/reference/files/insert
239 // See also https://developers.google.com/drive/manage-uploads and
240 // https://developers.google.com/drive/folder
241 class FilesInsertRequest : public DriveApiDataRequest<FileResource> {
242 public:
243 FilesInsertRequest(RequestSender* sender,
244 const DriveApiUrlGenerator& url_generator,
245 const FileResourceCallback& callback);
246 ~FilesInsertRequest() override;
248 // Optional request body.
249 const base::Time& last_viewed_by_me_date() const {
250 return last_viewed_by_me_date_;
252 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
253 last_viewed_by_me_date_ = last_viewed_by_me_date;
256 const std::string& mime_type() const { return mime_type_; }
257 void set_mime_type(const std::string& mime_type) {
258 mime_type_ = mime_type;
261 const base::Time& modified_date() const { return modified_date_; }
262 void set_modified_date(const base::Time& modified_date) {
263 modified_date_ = modified_date;
266 const std::vector<std::string>& parents() const { return parents_; }
267 void add_parent(const std::string& parent) { parents_.push_back(parent); }
269 const std::string& title() const { return title_; }
270 void set_title(const std::string& title) { title_ = title; }
272 const Properties& properties() const { return properties_; }
273 void set_properties(const Properties& properties) {
274 properties_ = properties;
277 protected:
278 // Overridden from GetDataRequest.
279 net::URLFetcher::RequestType GetRequestType() const override;
280 bool GetContentData(std::string* upload_content_type,
281 std::string* upload_content) override;
283 // Overridden from DriveApiDataRequest.
284 GURL GetURLInternal() const override;
286 private:
287 const DriveApiUrlGenerator url_generator_;
289 base::Time last_viewed_by_me_date_;
290 std::string mime_type_;
291 base::Time modified_date_;
292 std::vector<std::string> parents_;
293 std::string title_;
294 Properties properties_;
296 DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest);
299 //============================== FilesPatchRequest ============================
301 // This class performs the request for patching file metadata.
302 // This request is mapped to
303 // https://developers.google.com/drive/v2/reference/files/patch
304 class FilesPatchRequest : public DriveApiDataRequest<FileResource> {
305 public:
306 FilesPatchRequest(RequestSender* sender,
307 const DriveApiUrlGenerator& url_generator,
308 const FileResourceCallback& callback);
309 ~FilesPatchRequest() override;
311 // Required parameter.
312 const std::string& file_id() const { return file_id_; }
313 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
315 // Optional parameter.
316 bool set_modified_date() const { return set_modified_date_; }
317 void set_set_modified_date(bool set_modified_date) {
318 set_modified_date_ = set_modified_date;
321 bool update_viewed_date() const { return update_viewed_date_; }
322 void set_update_viewed_date(bool update_viewed_date) {
323 update_viewed_date_ = update_viewed_date;
326 // Optional request body.
327 // Note: "Files: patch" accepts any "Files resource" data, but this class
328 // only supports limited members of it for now. We can extend it upon
329 // requirments.
330 const std::string& title() const { return title_; }
331 void set_title(const std::string& title) { title_ = title; }
333 const base::Time& modified_date() const { return modified_date_; }
334 void set_modified_date(const base::Time& modified_date) {
335 modified_date_ = modified_date;
338 const base::Time& last_viewed_by_me_date() const {
339 return last_viewed_by_me_date_;
341 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
342 last_viewed_by_me_date_ = last_viewed_by_me_date;
345 const std::vector<std::string>& parents() const { return parents_; }
346 void add_parent(const std::string& parent) { parents_.push_back(parent); }
348 const Properties& properties() const { return properties_; }
349 void set_properties(const Properties& properties) {
350 properties_ = properties;
353 protected:
354 // Overridden from URLFetchRequestBase.
355 net::URLFetcher::RequestType GetRequestType() const override;
356 std::vector<std::string> GetExtraRequestHeaders() const override;
357 bool GetContentData(std::string* upload_content_type,
358 std::string* upload_content) override;
360 // Overridden from DriveApiDataRequest.
361 GURL GetURLInternal() const override;
363 private:
364 const DriveApiUrlGenerator url_generator_;
366 std::string file_id_;
367 bool set_modified_date_;
368 bool update_viewed_date_;
370 std::string title_;
371 base::Time modified_date_;
372 base::Time last_viewed_by_me_date_;
373 std::vector<std::string> parents_;
374 Properties properties_;
376 DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest);
379 //============================= FilesCopyRequest ==============================
381 // This class performs the request for copying a resource.
382 // This request is mapped to
383 // https://developers.google.com/drive/v2/reference/files/copy
384 class FilesCopyRequest : public DriveApiDataRequest<FileResource> {
385 public:
386 // Upon completion, |callback| will be called. |callback| must not be null.
387 FilesCopyRequest(RequestSender* sender,
388 const DriveApiUrlGenerator& url_generator,
389 const FileResourceCallback& callback);
390 ~FilesCopyRequest() override;
392 // Required parameter.
393 const std::string& file_id() const { return file_id_; }
394 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
396 // Optional request body.
397 const std::vector<std::string>& parents() const { return parents_; }
398 void add_parent(const std::string& parent) { parents_.push_back(parent); }
400 const base::Time& modified_date() const { return modified_date_; }
401 void set_modified_date(const base::Time& modified_date) {
402 modified_date_ = modified_date;
405 const std::string& title() const { return title_; }
406 void set_title(const std::string& title) { title_ = title; }
408 protected:
409 // Overridden from URLFetchRequestBase.
410 net::URLFetcher::RequestType GetRequestType() const override;
411 bool GetContentData(std::string* upload_content_type,
412 std::string* upload_content) override;
414 // Overridden from DriveApiDataRequest.
415 GURL GetURLInternal() const override;
417 private:
418 const DriveApiUrlGenerator url_generator_;
420 std::string file_id_;
421 base::Time modified_date_;
422 std::vector<std::string> parents_;
423 std::string title_;
425 DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest);
428 //============================= FilesListRequest =============================
430 // This class performs the request for fetching FileList.
431 // The result may contain only first part of the result. The remaining result
432 // should be able to be fetched by ContinueGetFileListRequest defined below,
433 // or by FilesListRequest with setting page token.
434 // This request is mapped to
435 // https://developers.google.com/drive/v2/reference/files/list
436 class FilesListRequest : public DriveApiDataRequest<FileList> {
437 public:
438 FilesListRequest(RequestSender* sender,
439 const DriveApiUrlGenerator& url_generator,
440 const FileListCallback& callback);
441 ~FilesListRequest() override;
443 // Optional parameter
444 int max_results() const { return max_results_; }
445 void set_max_results(int max_results) { max_results_ = max_results; }
447 const std::string& page_token() const { return page_token_; }
448 void set_page_token(const std::string& page_token) {
449 page_token_ = page_token;
452 const std::string& q() const { return q_; }
453 void set_q(const std::string& q) { q_ = q; }
455 protected:
456 // Overridden from DriveApiDataRequest.
457 GURL GetURLInternal() const override;
459 private:
460 const DriveApiUrlGenerator url_generator_;
461 int max_results_;
462 std::string page_token_;
463 std::string q_;
465 DISALLOW_COPY_AND_ASSIGN(FilesListRequest);
468 //========================= FilesListNextPageRequest ==========================
470 // There are two ways to obtain next pages of "Files: list" result (if paged).
471 // 1) Set pageToken and all params used for the initial request.
472 // 2) Use URL in the nextLink field in the previous response.
473 // This class implements 2)'s request.
474 class FilesListNextPageRequest : public DriveApiDataRequest<FileList> {
475 public:
476 FilesListNextPageRequest(RequestSender* sender,
477 const FileListCallback& callback);
478 ~FilesListNextPageRequest() override;
480 const GURL& next_link() const { return next_link_; }
481 void set_next_link(const GURL& next_link) { next_link_ = next_link; }
483 protected:
484 // Overridden from DriveApiDataRequest.
485 GURL GetURLInternal() const override;
487 private:
488 GURL next_link_;
490 DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest);
493 //============================= FilesDeleteRequest =============================
495 // This class performs the request for deleting a resource.
496 // This request is mapped to
497 // https://developers.google.com/drive/v2/reference/files/delete
498 class FilesDeleteRequest : public EntryActionRequest {
499 public:
500 FilesDeleteRequest(RequestSender* sender,
501 const DriveApiUrlGenerator& url_generator,
502 const EntryActionCallback& callback);
503 ~FilesDeleteRequest() override;
505 // Required parameter.
506 const std::string& file_id() const { return file_id_; }
507 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
508 void set_etag(const std::string& etag) { etag_ = etag; }
510 protected:
511 // Overridden from UrlFetchRequestBase.
512 net::URLFetcher::RequestType GetRequestType() const override;
513 GURL GetURL() const override;
514 std::vector<std::string> GetExtraRequestHeaders() const override;
516 private:
517 const DriveApiUrlGenerator url_generator_;
518 std::string file_id_;
519 std::string etag_;
521 DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest);
524 //============================= FilesTrashRequest ==============================
526 // This class performs the request for trashing a resource.
527 // This request is mapped to
528 // https://developers.google.com/drive/v2/reference/files/trash
529 class FilesTrashRequest : public DriveApiDataRequest<FileResource> {
530 public:
531 FilesTrashRequest(RequestSender* sender,
532 const DriveApiUrlGenerator& url_generator,
533 const FileResourceCallback& callback);
534 ~FilesTrashRequest() override;
536 // Required parameter.
537 const std::string& file_id() const { return file_id_; }
538 void set_file_id(const std::string& file_id) { file_id_ = file_id; }
540 protected:
541 // Overridden from UrlFetchRequestBase.
542 net::URLFetcher::RequestType GetRequestType() const override;
544 // Overridden from DriveApiDataRequest.
545 GURL GetURLInternal() const override;
547 private:
548 const DriveApiUrlGenerator url_generator_;
549 std::string file_id_;
551 DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest);
554 //============================== AboutGetRequest =============================
556 // This class performs the request for fetching About data.
557 // This request is mapped to
558 // https://developers.google.com/drive/v2/reference/about/get
559 class AboutGetRequest : public DriveApiDataRequest<AboutResource> {
560 public:
561 AboutGetRequest(RequestSender* sender,
562 const DriveApiUrlGenerator& url_generator,
563 const AboutResourceCallback& callback);
564 ~AboutGetRequest() override;
566 protected:
567 // Overridden from DriveApiDataRequest.
568 GURL GetURLInternal() const override;
570 private:
571 const DriveApiUrlGenerator url_generator_;
573 DISALLOW_COPY_AND_ASSIGN(AboutGetRequest);
576 //============================ ChangesListRequest ============================
578 // This class performs the request for fetching ChangeList.
579 // The result may contain only first part of the result. The remaining result
580 // should be able to be fetched by ContinueGetFileListRequest defined below.
581 // or by ChangesListRequest with setting page token.
582 // This request is mapped to
583 // https://developers.google.com/drive/v2/reference/changes/list
584 class ChangesListRequest : public DriveApiDataRequest<ChangeList> {
585 public:
586 ChangesListRequest(RequestSender* sender,
587 const DriveApiUrlGenerator& url_generator,
588 const ChangeListCallback& callback);
589 ~ChangesListRequest() override;
591 // Optional parameter
592 bool include_deleted() const { return include_deleted_; }
593 void set_include_deleted(bool include_deleted) {
594 include_deleted_ = include_deleted;
597 int max_results() const { return max_results_; }
598 void set_max_results(int max_results) { max_results_ = max_results; }
600 const std::string& page_token() const { return page_token_; }
601 void set_page_token(const std::string& page_token) {
602 page_token_ = page_token;
605 int64 start_change_id() const { return start_change_id_; }
606 void set_start_change_id(int64 start_change_id) {
607 start_change_id_ = start_change_id;
610 protected:
611 // Overridden from DriveApiDataRequest.
612 GURL GetURLInternal() const override;
614 private:
615 const DriveApiUrlGenerator url_generator_;
616 bool include_deleted_;
617 int max_results_;
618 std::string page_token_;
619 int64 start_change_id_;
621 DISALLOW_COPY_AND_ASSIGN(ChangesListRequest);
624 //======================== ChangesListNextPageRequest =========================
626 // There are two ways to obtain next pages of "Changes: list" result (if paged).
627 // 1) Set pageToken and all params used for the initial request.
628 // 2) Use URL in the nextLink field in the previous response.
629 // This class implements 2)'s request.
630 class ChangesListNextPageRequest : public DriveApiDataRequest<ChangeList> {
631 public:
632 ChangesListNextPageRequest(RequestSender* sender,
633 const ChangeListCallback& callback);
634 ~ChangesListNextPageRequest() override;
636 const GURL& next_link() const { return next_link_; }
637 void set_next_link(const GURL& next_link) { next_link_ = next_link; }
639 protected:
640 // Overridden from DriveApiDataRequest.
641 GURL GetURLInternal() const override;
643 private:
644 GURL next_link_;
646 DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest);
649 //============================= AppsListRequest ============================
651 // This class performs the request for fetching AppList.
652 // This request is mapped to
653 // https://developers.google.com/drive/v2/reference/apps/list
654 class AppsListRequest : public DriveApiDataRequest<AppList> {
655 public:
656 AppsListRequest(RequestSender* sender,
657 const DriveApiUrlGenerator& url_generator,
658 bool use_internal_endpoint,
659 const AppListCallback& callback);
660 ~AppsListRequest() override;
662 protected:
663 // Overridden from DriveApiDataRequest.
664 GURL GetURLInternal() const override;
666 private:
667 const DriveApiUrlGenerator url_generator_;
668 const bool use_internal_endpoint_;
670 DISALLOW_COPY_AND_ASSIGN(AppsListRequest);
673 //============================= AppsDeleteRequest ==============================
675 // This class performs the request for deleting a Drive app.
676 // This request is mapped to
677 // https://developers.google.com/drive/v2/reference/files/trash
678 class AppsDeleteRequest : public EntryActionRequest {
679 public:
680 AppsDeleteRequest(RequestSender* sender,
681 const DriveApiUrlGenerator& url_generator,
682 const EntryActionCallback& callback);
683 ~AppsDeleteRequest() override;
685 // Required parameter.
686 const std::string& app_id() const { return app_id_; }
687 void set_app_id(const std::string& app_id) { app_id_ = app_id; }
689 protected:
690 // Overridden from UrlFetchRequestBase.
691 net::URLFetcher::RequestType GetRequestType() const override;
692 GURL GetURL() const override;
694 private:
695 const DriveApiUrlGenerator url_generator_;
696 std::string app_id_;
698 DISALLOW_COPY_AND_ASSIGN(AppsDeleteRequest);
701 //========================== ChildrenInsertRequest ============================
703 // This class performs the request for inserting a resource to a directory.
704 // This request is mapped to
705 // https://developers.google.com/drive/v2/reference/children/insert
706 class ChildrenInsertRequest : public EntryActionRequest {
707 public:
708 ChildrenInsertRequest(RequestSender* sender,
709 const DriveApiUrlGenerator& url_generator,
710 const EntryActionCallback& callback);
711 ~ChildrenInsertRequest() override;
713 // Required parameter.
714 const std::string& folder_id() const { return folder_id_; }
715 void set_folder_id(const std::string& folder_id) {
716 folder_id_ = folder_id;
719 // Required body.
720 const std::string& id() const { return id_; }
721 void set_id(const std::string& id) { id_ = id; }
723 protected:
724 // UrlFetchRequestBase overrides.
725 net::URLFetcher::RequestType GetRequestType() const override;
726 GURL GetURL() const override;
727 bool GetContentData(std::string* upload_content_type,
728 std::string* upload_content) override;
730 private:
731 const DriveApiUrlGenerator url_generator_;
732 std::string folder_id_;
733 std::string id_;
735 DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest);
738 //========================== ChildrenDeleteRequest ============================
740 // This class performs the request for removing a resource from a directory.
741 // This request is mapped to
742 // https://developers.google.com/drive/v2/reference/children/delete
743 class ChildrenDeleteRequest : public EntryActionRequest {
744 public:
745 // |callback| must not be null.
746 ChildrenDeleteRequest(RequestSender* sender,
747 const DriveApiUrlGenerator& url_generator,
748 const EntryActionCallback& callback);
749 ~ChildrenDeleteRequest() override;
751 // Required parameter.
752 const std::string& child_id() const { return child_id_; }
753 void set_child_id(const std::string& child_id) {
754 child_id_ = child_id;
757 const std::string& folder_id() const { return folder_id_; }
758 void set_folder_id(const std::string& folder_id) {
759 folder_id_ = folder_id;
762 protected:
763 // UrlFetchRequestBase overrides.
764 net::URLFetcher::RequestType GetRequestType() const override;
765 GURL GetURL() const override;
767 private:
768 const DriveApiUrlGenerator url_generator_;
769 std::string child_id_;
770 std::string folder_id_;
772 DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest);
775 //======================= InitiateUploadNewFileRequest =======================
777 // This class performs the request for initiating the upload of a new file.
778 class InitiateUploadNewFileRequest : public InitiateUploadRequestBase {
779 public:
780 // |parent_resource_id| should be the resource id of the parent directory.
781 // |title| should be set.
782 // See also the comments of InitiateUploadRequestBase for more details
783 // about the other parameters.
784 InitiateUploadNewFileRequest(RequestSender* sender,
785 const DriveApiUrlGenerator& url_generator,
786 const std::string& content_type,
787 int64 content_length,
788 const std::string& parent_resource_id,
789 const std::string& title,
790 const InitiateUploadCallback& callback);
791 ~InitiateUploadNewFileRequest() override;
793 // Optional parameters.
794 const base::Time& modified_date() const { return modified_date_; }
795 void set_modified_date(const base::Time& modified_date) {
796 modified_date_ = modified_date;
798 const base::Time& last_viewed_by_me_date() const {
799 return last_viewed_by_me_date_;
801 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
802 last_viewed_by_me_date_ = last_viewed_by_me_date;
804 const Properties& properties() const { return properties_; }
805 void set_properties(const Properties& properties) {
806 properties_ = properties;
809 protected:
810 // UrlFetchRequestBase overrides.
811 GURL GetURL() const override;
812 net::URLFetcher::RequestType GetRequestType() const override;
813 bool GetContentData(std::string* upload_content_type,
814 std::string* upload_content) override;
816 private:
817 const DriveApiUrlGenerator url_generator_;
818 const std::string parent_resource_id_;
819 const std::string title_;
821 base::Time modified_date_;
822 base::Time last_viewed_by_me_date_;
823 Properties properties_;
825 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest);
828 //==================== InitiateUploadExistingFileRequest =====================
830 // This class performs the request for initiating the upload of an existing
831 // file.
832 class InitiateUploadExistingFileRequest : public InitiateUploadRequestBase {
833 public:
834 // |upload_url| should be the upload_url() of the file
835 // (resumable-create-media URL)
836 // |etag| should be set if it is available to detect the upload confliction.
837 // See also the comments of InitiateUploadRequestBase for more details
838 // about the other parameters.
839 InitiateUploadExistingFileRequest(RequestSender* sender,
840 const DriveApiUrlGenerator& url_generator,
841 const std::string& content_type,
842 int64 content_length,
843 const std::string& resource_id,
844 const std::string& etag,
845 const InitiateUploadCallback& callback);
846 ~InitiateUploadExistingFileRequest() override;
848 // Optional parameters.
849 const std::string& parent_resource_id() const { return parent_resource_id_; }
850 void set_parent_resource_id(const std::string& parent_resource_id) {
851 parent_resource_id_ = parent_resource_id;
853 const std::string& title() const { return title_; }
854 void set_title(const std::string& title) { title_ = title; }
855 const base::Time& modified_date() const { return modified_date_; }
856 void set_modified_date(const base::Time& modified_date) {
857 modified_date_ = modified_date;
859 const base::Time& last_viewed_by_me_date() const {
860 return last_viewed_by_me_date_;
862 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
863 last_viewed_by_me_date_ = last_viewed_by_me_date;
865 const Properties& properties() const { return properties_; }
866 void set_properties(const Properties& properties) {
867 properties_ = properties;
870 protected:
871 // UrlFetchRequestBase overrides.
872 GURL GetURL() const override;
873 net::URLFetcher::RequestType GetRequestType() const override;
874 std::vector<std::string> GetExtraRequestHeaders() const override;
875 bool GetContentData(std::string* upload_content_type,
876 std::string* upload_content) override;
878 private:
879 const DriveApiUrlGenerator url_generator_;
880 const std::string resource_id_;
881 const std::string etag_;
883 std::string parent_resource_id_;
884 std::string title_;
885 base::Time modified_date_;
886 base::Time last_viewed_by_me_date_;
887 Properties properties_;
889 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest);
892 // Callback used for ResumeUpload() and GetUploadStatus().
893 typedef base::Callback<void(
894 const UploadRangeResponse& response,
895 scoped_ptr<FileResource> new_resource)> UploadRangeCallback;
897 //============================ ResumeUploadRequest ===========================
899 // Performs the request for resuming the upload of a file.
900 class ResumeUploadRequest : public ResumeUploadRequestBase {
901 public:
902 // See also ResumeUploadRequestBase's comment for parameters meaning.
903 // |callback| must not be null. |progress_callback| may be null.
904 ResumeUploadRequest(RequestSender* sender,
905 const GURL& upload_location,
906 int64 start_position,
907 int64 end_position,
908 int64 content_length,
909 const std::string& content_type,
910 const base::FilePath& local_file_path,
911 const UploadRangeCallback& callback,
912 const ProgressCallback& progress_callback);
913 ~ResumeUploadRequest() override;
915 protected:
916 // UploadRangeRequestBase overrides.
917 void OnRangeRequestComplete(const UploadRangeResponse& response,
918 scoped_ptr<base::Value> value) override;
919 // content::UrlFetcherDelegate overrides.
920 void OnURLFetchUploadProgress(const net::URLFetcher* source,
921 int64 current,
922 int64 total) override;
924 private:
925 const UploadRangeCallback callback_;
926 const ProgressCallback progress_callback_;
928 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest);
931 //========================== GetUploadStatusRequest ==========================
933 // Performs the request to fetch the current upload status of a file.
934 class GetUploadStatusRequest : public GetUploadStatusRequestBase {
935 public:
936 // See also GetUploadStatusRequestBase's comment for parameters meaning.
937 // |callback| must not be null.
938 GetUploadStatusRequest(RequestSender* sender,
939 const GURL& upload_url,
940 int64 content_length,
941 const UploadRangeCallback& callback);
942 ~GetUploadStatusRequest() override;
944 protected:
945 // UploadRangeRequestBase overrides.
946 void OnRangeRequestComplete(const UploadRangeResponse& response,
947 scoped_ptr<base::Value> value) override;
949 private:
950 const UploadRangeCallback callback_;
952 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest);
955 //======================= MultipartUploadNewFileRequest =======================
957 // This class performs the request for initiating the upload of a new file.
958 class MultipartUploadNewFileRequest : public MultipartUploadRequestBase {
959 public:
960 // |parent_resource_id| should be the resource id of the parent directory.
961 // |title| should be set.
962 // See also the comments of MultipartUploadRequestBase for more details
963 // about the other parameters.
964 MultipartUploadNewFileRequest(RequestSender* sender,
965 const std::string& title,
966 const std::string& parent_resource_id,
967 const std::string& content_type,
968 int64 content_length,
969 const base::Time& modified_date,
970 const base::Time& last_viewed_by_me_date,
971 const base::FilePath& local_file_path,
972 const Properties& properties,
973 const DriveApiUrlGenerator& url_generator,
974 const FileResourceCallback& callback,
975 const ProgressCallback& progress_callback);
976 ~MultipartUploadNewFileRequest() override;
978 protected:
979 // UrlFetchRequestBase overrides.
980 GURL GetURL() const override;
981 net::URLFetcher::RequestType GetRequestType() const override;
983 private:
984 const bool has_modified_date_;
985 const DriveApiUrlGenerator url_generator_;
987 DISALLOW_COPY_AND_ASSIGN(MultipartUploadNewFileRequest);
990 //======================= MultipartUploadExistingFileRequest ===================
992 // This class performs the request for initiating the upload of a new file.
993 class MultipartUploadExistingFileRequest : public MultipartUploadRequestBase {
994 public:
995 // |parent_resource_id| should be the resource id of the parent directory.
996 // |title| should be set.
997 // See also the comments of MultipartUploadRequestBase for more details
998 // about the other parameters.
999 MultipartUploadExistingFileRequest(RequestSender* sender,
1000 const std::string& title,
1001 const std::string& resource_id,
1002 const std::string& parent_resource_id,
1003 const std::string& content_type,
1004 int64 content_length,
1005 const base::Time& modified_date,
1006 const base::Time& last_viewed_by_me_date,
1007 const base::FilePath& local_file_path,
1008 const std::string& etag,
1009 const Properties& properties,
1010 const DriveApiUrlGenerator& url_generator,
1011 const FileResourceCallback& callback,
1012 const ProgressCallback& progress_callback);
1013 ~MultipartUploadExistingFileRequest() override;
1015 protected:
1016 // UrlFetchRequestBase overrides.
1017 std::vector<std::string> GetExtraRequestHeaders() const override;
1018 GURL GetURL() const override;
1019 net::URLFetcher::RequestType GetRequestType() const override;
1021 private:
1022 const std::string resource_id_;
1023 const std::string etag_;
1024 const bool has_modified_date_;
1025 const DriveApiUrlGenerator url_generator_;
1027 DISALLOW_COPY_AND_ASSIGN(MultipartUploadExistingFileRequest);
1030 //========================== DownloadFileRequest ==========================
1032 // This class performs the request for downloading of a specified file.
1033 class DownloadFileRequest : public DownloadFileRequestBase {
1034 public:
1035 // See also DownloadFileRequestBase's comment for parameters meaning.
1036 DownloadFileRequest(RequestSender* sender,
1037 const DriveApiUrlGenerator& url_generator,
1038 const std::string& resource_id,
1039 const base::FilePath& output_file_path,
1040 const DownloadActionCallback& download_action_callback,
1041 const GetContentCallback& get_content_callback,
1042 const ProgressCallback& progress_callback);
1043 ~DownloadFileRequest() override;
1045 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest);
1048 //========================== PermissionsInsertRequest ==========================
1050 // Enumeration type for specifying type of permissions.
1051 enum PermissionType {
1052 PERMISSION_TYPE_ANYONE,
1053 PERMISSION_TYPE_DOMAIN,
1054 PERMISSION_TYPE_GROUP,
1055 PERMISSION_TYPE_USER,
1058 // Enumeration type for specifying the role of permissions.
1059 enum PermissionRole {
1060 PERMISSION_ROLE_OWNER,
1061 PERMISSION_ROLE_READER,
1062 PERMISSION_ROLE_WRITER,
1063 PERMISSION_ROLE_COMMENTER,
1066 // This class performs the request for adding permission on a specified file.
1067 class PermissionsInsertRequest : public EntryActionRequest {
1068 public:
1069 // See https://developers.google.com/drive/v2/reference/permissions/insert.
1070 PermissionsInsertRequest(RequestSender* sender,
1071 const DriveApiUrlGenerator& url_generator,
1072 const EntryActionCallback& callback);
1073 ~PermissionsInsertRequest() override;
1075 void set_id(const std::string& id) { id_ = id; }
1076 void set_type(PermissionType type) { type_ = type; }
1077 void set_role(PermissionRole role) { role_ = role; }
1078 void set_value(const std::string& value) { value_ = value; }
1080 // UrlFetchRequestBase overrides.
1081 GURL GetURL() const override;
1082 net::URLFetcher::RequestType GetRequestType() const override;
1083 bool GetContentData(std::string* upload_content_type,
1084 std::string* upload_content) override;
1086 private:
1087 const DriveApiUrlGenerator url_generator_;
1088 std::string id_;
1089 PermissionType type_;
1090 PermissionRole role_;
1091 std::string value_;
1093 DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest);
1096 } // namespace drive
1097 } // namespace google_apis
1099 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_