• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
7 
8 #include <string>
9 
10 #include "base/callback_forward.h"
11 #include "base/time/time.h"
12 #include "google_apis/drive/base_requests.h"
13 #include "google_apis/drive/drive_api_url_generator.h"
14 #include "google_apis/drive/drive_common_callbacks.h"
15 
16 namespace google_apis {
17 
18 class ChangeList;
19 class FileResource;
20 class FileList;
21 
22 // Callback used for requests that the server returns FileResource data
23 // formatted into JSON value.
24 typedef base::Callback<void(GDataErrorCode error,
25                             scoped_ptr<FileResource> entry)>
26     FileResourceCallback;
27 
28 // Callback used for requests that the server returns FileList data
29 // formatted into JSON value.
30 typedef base::Callback<void(GDataErrorCode error,
31                             scoped_ptr<FileList> entry)> FileListCallback;
32 
33 // Callback used for requests that the server returns ChangeList data
34 // formatted into JSON value.
35 typedef base::Callback<void(GDataErrorCode error,
36                             scoped_ptr<ChangeList> entry)> ChangeListCallback;
37 
38 namespace drive {
39 
40 //============================ DriveApiDataRequest ===========================
41 
42 // This is base class of the Drive API related requests. All Drive API requests
43 // support partial request (to improve the performance). The function can be
44 // shared among the Drive API requests.
45 // See also https://developers.google.com/drive/performance
46 class DriveApiDataRequest : public GetDataRequest {
47  public:
48   DriveApiDataRequest(RequestSender* sender, const GetDataCallback& callback);
49   virtual ~DriveApiDataRequest();
50 
51   // Optional parameter.
fields()52   const std::string& fields() const { return fields_; }
set_fields(const std::string & fields)53   void set_fields(const std::string& fields) { fields_ = fields; }
54 
55  protected:
56   // Overridden from GetDataRequest.
57   virtual GURL GetURL() const OVERRIDE;
58 
59   // Derived classes should override GetURLInternal instead of GetURL()
60   // directly.
61   virtual GURL GetURLInternal() const = 0;
62 
63  private:
64   std::string fields_;
65 
66   DISALLOW_COPY_AND_ASSIGN(DriveApiDataRequest);
67 };
68 
69 //=============================== FilesGetRequest =============================
70 
71 // This class performs the request for fetching a file.
72 // This request is mapped to
73 // https://developers.google.com/drive/v2/reference/files/get
74 class FilesGetRequest : public DriveApiDataRequest {
75  public:
76   FilesGetRequest(RequestSender* sender,
77                   const DriveApiUrlGenerator& url_generator,
78                   const FileResourceCallback& callback);
79   virtual ~FilesGetRequest();
80 
81   // Required parameter.
file_id()82   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)83   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
84 
85  protected:
86   // Overridden from DriveApiDataRequest.
87   virtual GURL GetURLInternal() const OVERRIDE;
88 
89  private:
90   const DriveApiUrlGenerator url_generator_;
91   std::string file_id_;
92 
93   DISALLOW_COPY_AND_ASSIGN(FilesGetRequest);
94 };
95 
96 //============================ FilesAuthorizeRequest ===========================
97 
98 // This class performs request for authorizing an app to access a file.
99 // This request is mapped to /drive/v2internal/file/authorize internal endpoint.
100 class FilesAuthorizeRequest : public DriveApiDataRequest {
101  public:
102   FilesAuthorizeRequest(RequestSender* sender,
103                         const DriveApiUrlGenerator& url_generator,
104                         const FileResourceCallback& callback);
105   virtual ~FilesAuthorizeRequest();
106 
107   // Required parameter.
file_id()108   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)109   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
app_id()110   const std::string& app_id() const { return app_id_; }
set_app_id(const std::string & app_id)111   void set_app_id(const std::string& app_id) { app_id_ = app_id; }
112 
113  protected:
114   // Overridden from GetDataRequest.
115   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
116 
117   // Overridden from DriveApiDataRequest.
118   virtual GURL GetURLInternal() const OVERRIDE;
119 
120  private:
121   const DriveApiUrlGenerator url_generator_;
122   std::string file_id_;
123   std::string app_id_;
124 
125   DISALLOW_COPY_AND_ASSIGN(FilesAuthorizeRequest);
126 };
127 
128 //============================ FilesInsertRequest =============================
129 
130 // This class performs the request for creating a resource.
131 // This request is mapped to
132 // https://developers.google.com/drive/v2/reference/files/insert
133 // See also https://developers.google.com/drive/manage-uploads and
134 // https://developers.google.com/drive/folder
135 class FilesInsertRequest : public DriveApiDataRequest {
136  public:
137   FilesInsertRequest(RequestSender* sender,
138                      const DriveApiUrlGenerator& url_generator,
139                      const FileResourceCallback& callback);
140   virtual ~FilesInsertRequest();
141 
142   // Optional request body.
last_viewed_by_me_date()143   const base::Time& last_viewed_by_me_date() const {
144     return last_viewed_by_me_date_;
145   }
set_last_viewed_by_me_date(const base::Time & last_viewed_by_me_date)146   void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
147     last_viewed_by_me_date_ = last_viewed_by_me_date;
148   }
149 
mime_type()150   const std::string& mime_type() const { return mime_type_; }
set_mime_type(const std::string & mime_type)151   void set_mime_type(const std::string& mime_type) {
152     mime_type_ = mime_type;
153   }
154 
modified_date()155   const base::Time& modified_date() const { return modified_date_; }
set_modified_date(const base::Time & modified_date)156   void set_modified_date(const base::Time& modified_date) {
157     modified_date_ = modified_date;
158   }
159 
parents()160   const std::vector<std::string>& parents() const { return parents_; }
add_parent(const std::string & parent)161   void add_parent(const std::string& parent) { parents_.push_back(parent); }
162 
title()163   const std::string& title() const { return title_; }
set_title(const std::string & title)164   void set_title(const std::string& title) { title_ = title; }
165 
166  protected:
167   // Overridden from GetDataRequest.
168   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
169   virtual bool GetContentData(std::string* upload_content_type,
170                               std::string* upload_content) OVERRIDE;
171 
172   // Overridden from DriveApiDataRequest.
173   virtual GURL GetURLInternal() const OVERRIDE;
174 
175  private:
176   const DriveApiUrlGenerator url_generator_;
177 
178   base::Time last_viewed_by_me_date_;
179   std::string mime_type_;
180   base::Time modified_date_;
181   std::vector<std::string> parents_;
182   std::string title_;
183 
184   DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest);
185 };
186 
187 //============================== FilesPatchRequest ============================
188 
189 // This class performs the request for patching file metadata.
190 // This request is mapped to
191 // https://developers.google.com/drive/v2/reference/files/patch
192 class FilesPatchRequest : public DriveApiDataRequest {
193  public:
194   FilesPatchRequest(RequestSender* sender,
195                     const DriveApiUrlGenerator& url_generator,
196                     const FileResourceCallback& callback);
197   virtual ~FilesPatchRequest();
198 
199   // Required parameter.
file_id()200   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)201   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
202 
203   // Optional parameter.
set_modified_date()204   bool set_modified_date() const { return set_modified_date_; }
set_set_modified_date(bool set_modified_date)205   void set_set_modified_date(bool set_modified_date) {
206     set_modified_date_ = set_modified_date;
207   }
208 
update_viewed_date()209   bool update_viewed_date() const { return update_viewed_date_; }
set_update_viewed_date(bool update_viewed_date)210   void set_update_viewed_date(bool update_viewed_date) {
211     update_viewed_date_ = update_viewed_date;
212   }
213 
214   // Optional request body.
215   // Note: "Files: patch" accepts any "Files resource" data, but this class
216   // only supports limited members of it for now. We can extend it upon
217   // requirments.
title()218   const std::string& title() const { return title_; }
set_title(const std::string & title)219   void set_title(const std::string& title) { title_ = title; }
220 
modified_date()221   const base::Time& modified_date() const { return modified_date_; }
set_modified_date(const base::Time & modified_date)222   void set_modified_date(const base::Time& modified_date) {
223     modified_date_ = modified_date;
224   }
225 
last_viewed_by_me_date()226   const base::Time& last_viewed_by_me_date() const {
227     return last_viewed_by_me_date_;
228   }
set_last_viewed_by_me_date(const base::Time & last_viewed_by_me_date)229   void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
230     last_viewed_by_me_date_ = last_viewed_by_me_date;
231   }
232 
parents()233   const std::vector<std::string>& parents() const { return parents_; }
add_parent(const std::string & parent)234   void add_parent(const std::string& parent) { parents_.push_back(parent); }
235 
236  protected:
237   // Overridden from URLFetchRequestBase.
238   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
239   virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
240   virtual bool GetContentData(std::string* upload_content_type,
241                               std::string* upload_content) OVERRIDE;
242 
243   // Overridden from DriveApiDataRequest.
244   virtual GURL GetURLInternal() const OVERRIDE;
245 
246  private:
247   const DriveApiUrlGenerator url_generator_;
248 
249   std::string file_id_;
250   bool set_modified_date_;
251   bool update_viewed_date_;
252 
253   std::string title_;
254   base::Time modified_date_;
255   base::Time last_viewed_by_me_date_;
256   std::vector<std::string> parents_;
257 
258   DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest);
259 };
260 
261 //============================= FilesCopyRequest ==============================
262 
263 // This class performs the request for copying a resource.
264 // This request is mapped to
265 // https://developers.google.com/drive/v2/reference/files/copy
266 class FilesCopyRequest : public DriveApiDataRequest {
267  public:
268   // Upon completion, |callback| will be called. |callback| must not be null.
269   FilesCopyRequest(RequestSender* sender,
270                    const DriveApiUrlGenerator& url_generator,
271                    const FileResourceCallback& callback);
272   virtual ~FilesCopyRequest();
273 
274   // Required parameter.
file_id()275   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)276   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
277 
278   // Optional request body.
parents()279   const std::vector<std::string>& parents() const { return parents_; }
add_parent(const std::string & parent)280   void add_parent(const std::string& parent) { parents_.push_back(parent); }
281 
modified_date()282   const base::Time& modified_date() const { return modified_date_; }
set_modified_date(const base::Time & modified_date)283   void set_modified_date(const base::Time& modified_date) {
284     modified_date_ = modified_date;
285   }
286 
title()287   const std::string& title() const { return title_; }
set_title(const std::string & title)288   void set_title(const std::string& title) { title_ = title; }
289 
290  protected:
291   // Overridden from URLFetchRequestBase.
292   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
293   virtual bool GetContentData(std::string* upload_content_type,
294                               std::string* upload_content) OVERRIDE;
295 
296   // Overridden from DriveApiDataRequest.
297   virtual GURL GetURLInternal() const OVERRIDE;
298 
299  private:
300   const DriveApiUrlGenerator url_generator_;
301 
302   std::string file_id_;
303   base::Time modified_date_;
304   std::vector<std::string> parents_;
305   std::string title_;
306 
307   DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest);
308 };
309 
310 //============================= FilesListRequest =============================
311 
312 // This class performs the request for fetching FileList.
313 // The result may contain only first part of the result. The remaining result
314 // should be able to be fetched by ContinueGetFileListRequest defined below,
315 // or by FilesListRequest with setting page token.
316 // This request is mapped to
317 // https://developers.google.com/drive/v2/reference/files/list
318 class FilesListRequest : public DriveApiDataRequest {
319  public:
320   FilesListRequest(RequestSender* sender,
321                    const DriveApiUrlGenerator& url_generator,
322                    const FileListCallback& callback);
323   virtual ~FilesListRequest();
324 
325   // Optional parameter
max_results()326   int max_results() const { return max_results_; }
set_max_results(int max_results)327   void set_max_results(int max_results) { max_results_ = max_results; }
328 
page_token()329   const std::string& page_token() const { return page_token_; }
set_page_token(const std::string & page_token)330   void set_page_token(const std::string& page_token) {
331     page_token_ = page_token;
332   }
333 
q()334   const std::string& q() const { return q_; }
set_q(const std::string & q)335   void set_q(const std::string& q) { q_ = q; }
336 
337  protected:
338   // Overridden from DriveApiDataRequest.
339   virtual GURL GetURLInternal() const OVERRIDE;
340 
341  private:
342   const DriveApiUrlGenerator url_generator_;
343   int max_results_;
344   std::string page_token_;
345   std::string q_;
346 
347   DISALLOW_COPY_AND_ASSIGN(FilesListRequest);
348 };
349 
350 //========================= FilesListNextPageRequest ==========================
351 
352 // There are two ways to obtain next pages of "Files: list" result (if paged).
353 // 1) Set pageToken and all params used for the initial request.
354 // 2) Use URL in the nextLink field in the previous response.
355 // This class implements 2)'s request.
356 class FilesListNextPageRequest : public DriveApiDataRequest {
357  public:
358   FilesListNextPageRequest(RequestSender* sender,
359                            const FileListCallback& callback);
360   virtual ~FilesListNextPageRequest();
361 
next_link()362   const GURL& next_link() const { return next_link_; }
set_next_link(const GURL & next_link)363   void set_next_link(const GURL& next_link) { next_link_ = next_link; }
364 
365  protected:
366   // Overridden from DriveApiDataRequest.
367   virtual GURL GetURLInternal() const OVERRIDE;
368 
369  private:
370   GURL next_link_;
371 
372   DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest);
373 };
374 
375 //============================= FilesDeleteRequest =============================
376 
377 // This class performs the request for deleting a resource.
378 // This request is mapped to
379 // https://developers.google.com/drive/v2/reference/files/delete
380 class FilesDeleteRequest : public EntryActionRequest {
381  public:
382   FilesDeleteRequest(RequestSender* sender,
383                      const DriveApiUrlGenerator& url_generator,
384                      const EntryActionCallback& callback);
385   virtual ~FilesDeleteRequest();
386 
387   // Required parameter.
file_id()388   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)389   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
set_etag(const std::string & etag)390   void set_etag(const std::string& etag) { etag_ = etag; }
391 
392  protected:
393   // Overridden from UrlFetchRequestBase.
394   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
395   virtual GURL GetURL() const OVERRIDE;
396   virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
397 
398  private:
399   const DriveApiUrlGenerator url_generator_;
400   std::string file_id_;
401   std::string etag_;
402 
403   DISALLOW_COPY_AND_ASSIGN(FilesDeleteRequest);
404 };
405 
406 //============================= FilesTrashRequest ==============================
407 
408 // This class performs the request for trashing a resource.
409 // This request is mapped to
410 // https://developers.google.com/drive/v2/reference/files/trash
411 class FilesTrashRequest : public DriveApiDataRequest {
412  public:
413   FilesTrashRequest(RequestSender* sender,
414                     const DriveApiUrlGenerator& url_generator,
415                     const FileResourceCallback& callback);
416   virtual ~FilesTrashRequest();
417 
418   // Required parameter.
file_id()419   const std::string& file_id() const { return file_id_; }
set_file_id(const std::string & file_id)420   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
421 
422  protected:
423   // Overridden from UrlFetchRequestBase.
424   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
425 
426   // Overridden from DriveApiDataRequest.
427   virtual GURL GetURLInternal() const OVERRIDE;
428 
429  private:
430   const DriveApiUrlGenerator url_generator_;
431   std::string file_id_;
432 
433   DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest);
434 };
435 
436 //============================== AboutGetRequest =============================
437 
438 // This class performs the request for fetching About data.
439 // This request is mapped to
440 // https://developers.google.com/drive/v2/reference/about/get
441 class AboutGetRequest : public DriveApiDataRequest {
442  public:
443   AboutGetRequest(RequestSender* sender,
444                   const DriveApiUrlGenerator& url_generator,
445                   const AboutResourceCallback& callback);
446   virtual ~AboutGetRequest();
447 
448  protected:
449   // Overridden from DriveApiDataRequest.
450   virtual GURL GetURLInternal() const OVERRIDE;
451 
452  private:
453   const DriveApiUrlGenerator url_generator_;
454 
455   DISALLOW_COPY_AND_ASSIGN(AboutGetRequest);
456 };
457 
458 //============================ ChangesListRequest ============================
459 
460 // This class performs the request for fetching ChangeList.
461 // The result may contain only first part of the result. The remaining result
462 // should be able to be fetched by ContinueGetFileListRequest defined below.
463 // or by ChangesListRequest with setting page token.
464 // This request is mapped to
465 // https://developers.google.com/drive/v2/reference/changes/list
466 class ChangesListRequest : public DriveApiDataRequest {
467  public:
468   ChangesListRequest(RequestSender* sender,
469                      const DriveApiUrlGenerator& url_generator,
470                      const ChangeListCallback& callback);
471   virtual ~ChangesListRequest();
472 
473   // Optional parameter
include_deleted()474   bool include_deleted() const { return include_deleted_; }
set_include_deleted(bool include_deleted)475   void set_include_deleted(bool include_deleted) {
476     include_deleted_ = include_deleted;
477   }
478 
max_results()479   int max_results() const { return max_results_; }
set_max_results(int max_results)480   void set_max_results(int max_results) { max_results_ = max_results; }
481 
page_token()482   const std::string& page_token() const { return page_token_; }
set_page_token(const std::string & page_token)483   void set_page_token(const std::string& page_token) {
484     page_token_ = page_token;
485   }
486 
start_change_id()487   int64 start_change_id() const { return start_change_id_; }
set_start_change_id(int64 start_change_id)488   void set_start_change_id(int64 start_change_id) {
489     start_change_id_ = start_change_id;
490   }
491 
492  protected:
493   // Overridden from DriveApiDataRequest.
494   virtual GURL GetURLInternal() const OVERRIDE;
495 
496  private:
497   const DriveApiUrlGenerator url_generator_;
498   bool include_deleted_;
499   int max_results_;
500   std::string page_token_;
501   int64 start_change_id_;
502 
503   DISALLOW_COPY_AND_ASSIGN(ChangesListRequest);
504 };
505 
506 //======================== ChangesListNextPageRequest =========================
507 
508 // There are two ways to obtain next pages of "Changes: list" result (if paged).
509 // 1) Set pageToken and all params used for the initial request.
510 // 2) Use URL in the nextLink field in the previous response.
511 // This class implements 2)'s request.
512 class ChangesListNextPageRequest : public DriveApiDataRequest {
513  public:
514   ChangesListNextPageRequest(RequestSender* sender,
515                              const ChangeListCallback& callback);
516   virtual ~ChangesListNextPageRequest();
517 
next_link()518   const GURL& next_link() const { return next_link_; }
set_next_link(const GURL & next_link)519   void set_next_link(const GURL& next_link) { next_link_ = next_link; }
520 
521  protected:
522   // Overridden from DriveApiDataRequest.
523   virtual GURL GetURLInternal() const OVERRIDE;
524 
525  private:
526   GURL next_link_;
527 
528   DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest);
529 };
530 
531 //============================= AppsListRequest ============================
532 
533 // This class performs the request for fetching AppList.
534 // This request is mapped to
535 // https://developers.google.com/drive/v2/reference/apps/list
536 class AppsListRequest : public DriveApiDataRequest {
537  public:
538   AppsListRequest(RequestSender* sender,
539                   const DriveApiUrlGenerator& url_generator,
540                   bool use_internal_endpoint,
541                   const AppListCallback& callback);
542   virtual ~AppsListRequest();
543 
544  protected:
545   // Overridden from DriveApiDataRequest.
546   virtual GURL GetURLInternal() const OVERRIDE;
547 
548  private:
549   const DriveApiUrlGenerator url_generator_;
550   bool use_internal_endpoint_;
551 
552   DISALLOW_COPY_AND_ASSIGN(AppsListRequest);
553 };
554 
555 //============================= AppsDeleteRequest ==============================
556 
557 // This class performs the request for deleting a Drive app.
558 // This request is mapped to
559 // https://developers.google.com/drive/v2/reference/files/trash
560 class AppsDeleteRequest : public EntryActionRequest {
561  public:
562   AppsDeleteRequest(RequestSender* sender,
563                     const DriveApiUrlGenerator& url_generator,
564                     const EntryActionCallback& callback);
565   virtual ~AppsDeleteRequest();
566 
567   // Required parameter.
app_id()568   const std::string& app_id() const { return app_id_; }
set_app_id(const std::string & app_id)569   void set_app_id(const std::string& app_id) { app_id_ = app_id; }
570 
571  protected:
572   // Overridden from UrlFetchRequestBase.
573   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
574   virtual GURL GetURL() const OVERRIDE;
575 
576  private:
577   const DriveApiUrlGenerator url_generator_;
578   std::string app_id_;
579 
580   DISALLOW_COPY_AND_ASSIGN(AppsDeleteRequest);
581 };
582 
583 //========================== ChildrenInsertRequest ============================
584 
585 // This class performs the request for inserting a resource to a directory.
586 // This request is mapped to
587 // https://developers.google.com/drive/v2/reference/children/insert
588 class ChildrenInsertRequest : public EntryActionRequest {
589  public:
590   ChildrenInsertRequest(RequestSender* sender,
591                         const DriveApiUrlGenerator& url_generator,
592                         const EntryActionCallback& callback);
593   virtual ~ChildrenInsertRequest();
594 
595   // Required parameter.
folder_id()596   const std::string& folder_id() const { return folder_id_; }
set_folder_id(const std::string & folder_id)597   void set_folder_id(const std::string& folder_id) {
598     folder_id_ = folder_id;
599   }
600 
601   // Required body.
id()602   const std::string& id() const { return id_; }
set_id(const std::string & id)603   void set_id(const std::string& id) { id_ = id; }
604 
605  protected:
606   // UrlFetchRequestBase overrides.
607   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
608   virtual GURL GetURL() const OVERRIDE;
609   virtual bool GetContentData(std::string* upload_content_type,
610                               std::string* upload_content) OVERRIDE;
611 
612  private:
613   const DriveApiUrlGenerator url_generator_;
614   std::string folder_id_;
615   std::string id_;
616 
617   DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest);
618 };
619 
620 //========================== ChildrenDeleteRequest ============================
621 
622 // This class performs the request for removing a resource from a directory.
623 // This request is mapped to
624 // https://developers.google.com/drive/v2/reference/children/delete
625 class ChildrenDeleteRequest : public EntryActionRequest {
626  public:
627   // |callback| must not be null.
628   ChildrenDeleteRequest(RequestSender* sender,
629                         const DriveApiUrlGenerator& url_generator,
630                         const EntryActionCallback& callback);
631   virtual ~ChildrenDeleteRequest();
632 
633   // Required parameter.
child_id()634   const std::string& child_id() const { return child_id_; }
set_child_id(const std::string & child_id)635   void set_child_id(const std::string& child_id) {
636     child_id_ = child_id;
637   }
638 
folder_id()639   const std::string& folder_id() const { return folder_id_; }
set_folder_id(const std::string & folder_id)640   void set_folder_id(const std::string& folder_id) {
641     folder_id_ = folder_id;
642   }
643 
644  protected:
645   // UrlFetchRequestBase overrides.
646   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
647   virtual GURL GetURL() const OVERRIDE;
648 
649  private:
650   const DriveApiUrlGenerator url_generator_;
651   std::string child_id_;
652   std::string folder_id_;
653 
654   DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest);
655 };
656 
657 //======================= InitiateUploadNewFileRequest =======================
658 
659 // This class performs the request for initiating the upload of a new file.
660 class InitiateUploadNewFileRequest : public InitiateUploadRequestBase {
661  public:
662   // |parent_resource_id| should be the resource id of the parent directory.
663   // |title| should be set.
664   // See also the comments of InitiateUploadRequestBase for more details
665   // about the other parameters.
666   InitiateUploadNewFileRequest(RequestSender* sender,
667                                const DriveApiUrlGenerator& url_generator,
668                                const std::string& content_type,
669                                int64 content_length,
670                                const std::string& parent_resource_id,
671                                const std::string& title,
672                                const InitiateUploadCallback& callback);
673   virtual ~InitiateUploadNewFileRequest();
674 
675   // Optional parameters.
modified_date()676   const base::Time& modified_date() const { return modified_date_; }
set_modified_date(const base::Time & modified_date)677   void set_modified_date(const base::Time& modified_date) {
678     modified_date_ = modified_date;
679   }
last_viewed_by_me_date()680   const base::Time& last_viewed_by_me_date() const {
681     return last_viewed_by_me_date_;
682   }
set_last_viewed_by_me_date(const base::Time & last_viewed_by_me_date)683   void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
684     last_viewed_by_me_date_ = last_viewed_by_me_date;
685   }
686 
687  protected:
688   // UrlFetchRequestBase overrides.
689   virtual GURL GetURL() const OVERRIDE;
690   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
691   virtual bool GetContentData(std::string* upload_content_type,
692                               std::string* upload_content) OVERRIDE;
693 
694  private:
695   const DriveApiUrlGenerator url_generator_;
696   const std::string parent_resource_id_;
697   const std::string title_;
698 
699   base::Time modified_date_;
700   base::Time last_viewed_by_me_date_;
701 
702   DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest);
703 };
704 
705 //==================== InitiateUploadExistingFileRequest =====================
706 
707 // This class performs the request for initiating the upload of an existing
708 // file.
709 class InitiateUploadExistingFileRequest : public InitiateUploadRequestBase {
710  public:
711   // |upload_url| should be the upload_url() of the file
712   //    (resumable-create-media URL)
713   // |etag| should be set if it is available to detect the upload confliction.
714   // See also the comments of InitiateUploadRequestBase for more details
715   // about the other parameters.
716   InitiateUploadExistingFileRequest(RequestSender* sender,
717                                     const DriveApiUrlGenerator& url_generator,
718                                     const std::string& content_type,
719                                     int64 content_length,
720                                     const std::string& resource_id,
721                                     const std::string& etag,
722                                     const InitiateUploadCallback& callback);
723   virtual ~InitiateUploadExistingFileRequest();
724 
725 
726   // Optional parameters.
parent_resource_id()727   const std::string& parent_resource_id() const { return parent_resource_id_; }
set_parent_resource_id(const std::string & parent_resource_id)728   void set_parent_resource_id(const std::string& parent_resource_id) {
729     parent_resource_id_ = parent_resource_id;
730   }
title()731   const std::string& title() const { return title_; }
set_title(const std::string & title)732   void set_title(const std::string& title) { title_ = title; }
modified_date()733   const base::Time& modified_date() const { return modified_date_; }
set_modified_date(const base::Time & modified_date)734   void set_modified_date(const base::Time& modified_date) {
735     modified_date_ = modified_date;
736   }
last_viewed_by_me_date()737   const base::Time& last_viewed_by_me_date() const {
738     return last_viewed_by_me_date_;
739   }
set_last_viewed_by_me_date(const base::Time & last_viewed_by_me_date)740   void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
741     last_viewed_by_me_date_ = last_viewed_by_me_date;
742   }
743 
744  protected:
745   // UrlFetchRequestBase overrides.
746   virtual GURL GetURL() const OVERRIDE;
747   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
748   virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
749   virtual bool GetContentData(std::string* upload_content_type,
750                               std::string* upload_content) OVERRIDE;
751 
752  private:
753   const DriveApiUrlGenerator url_generator_;
754   const std::string resource_id_;
755   const std::string etag_;
756 
757   std::string parent_resource_id_;
758   std::string title_;
759   base::Time modified_date_;
760   base::Time last_viewed_by_me_date_;
761 
762   DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest);
763 };
764 
765 // Callback used for ResumeUpload() and GetUploadStatus().
766 typedef base::Callback<void(
767     const UploadRangeResponse& response,
768     scoped_ptr<FileResource> new_resource)> UploadRangeCallback;
769 
770 //============================ ResumeUploadRequest ===========================
771 
772 // Performs the request for resuming the upload of a file.
773 class ResumeUploadRequest : public ResumeUploadRequestBase {
774  public:
775   // See also ResumeUploadRequestBase's comment for parameters meaning.
776   // |callback| must not be null. |progress_callback| may be null.
777   ResumeUploadRequest(RequestSender* sender,
778                       const GURL& upload_location,
779                       int64 start_position,
780                       int64 end_position,
781                       int64 content_length,
782                       const std::string& content_type,
783                       const base::FilePath& local_file_path,
784                       const UploadRangeCallback& callback,
785                       const ProgressCallback& progress_callback);
786   virtual ~ResumeUploadRequest();
787 
788  protected:
789   // UploadRangeRequestBase overrides.
790   virtual void OnRangeRequestComplete(
791       const UploadRangeResponse& response,
792       scoped_ptr<base::Value> value) OVERRIDE;
793   // content::UrlFetcherDelegate overrides.
794   virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
795                                         int64 current, int64 total) OVERRIDE;
796 
797  private:
798   const UploadRangeCallback callback_;
799   const ProgressCallback progress_callback_;
800 
801   DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest);
802 };
803 
804 //========================== GetUploadStatusRequest ==========================
805 
806 // Performs the request to fetch the current upload status of a file.
807 class GetUploadStatusRequest : public GetUploadStatusRequestBase {
808  public:
809   // See also GetUploadStatusRequestBase's comment for parameters meaning.
810   // |callback| must not be null.
811   GetUploadStatusRequest(RequestSender* sender,
812                          const GURL& upload_url,
813                          int64 content_length,
814                          const UploadRangeCallback& callback);
815   virtual ~GetUploadStatusRequest();
816 
817  protected:
818   // UploadRangeRequestBase overrides.
819   virtual void OnRangeRequestComplete(
820       const UploadRangeResponse& response,
821       scoped_ptr<base::Value> value) OVERRIDE;
822 
823  private:
824   const UploadRangeCallback callback_;
825 
826   DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest);
827 };
828 
829 //========================== DownloadFileRequest ==========================
830 
831 // This class performs the request for downloading of a specified file.
832 class DownloadFileRequest : public DownloadFileRequestBase {
833  public:
834   // See also DownloadFileRequestBase's comment for parameters meaning.
835   DownloadFileRequest(RequestSender* sender,
836                       const DriveApiUrlGenerator& url_generator,
837                       const std::string& resource_id,
838                       const base::FilePath& output_file_path,
839                       const DownloadActionCallback& download_action_callback,
840                       const GetContentCallback& get_content_callback,
841                       const ProgressCallback& progress_callback);
842   virtual ~DownloadFileRequest();
843 
844   DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest);
845 };
846 
847 //========================== PermissionsInsertRequest ==========================
848 
849 // Enumeration type for specifying type of permissions.
850 enum PermissionType {
851   PERMISSION_TYPE_ANYONE,
852   PERMISSION_TYPE_DOMAIN,
853   PERMISSION_TYPE_GROUP,
854   PERMISSION_TYPE_USER,
855 };
856 
857 // Enumeration type for specifying the role of permissions.
858 enum PermissionRole {
859   PERMISSION_ROLE_OWNER,
860   PERMISSION_ROLE_READER,
861   PERMISSION_ROLE_WRITER,
862   PERMISSION_ROLE_COMMENTER,
863 };
864 
865 // This class performs the request for adding permission on a specified file.
866 class PermissionsInsertRequest : public EntryActionRequest {
867  public:
868   // See https://developers.google.com/drive/v2/reference/permissions/insert.
869   PermissionsInsertRequest(RequestSender* sender,
870                            const DriveApiUrlGenerator& url_generator,
871                            const EntryActionCallback& callback);
872   virtual ~PermissionsInsertRequest();
873 
set_id(const std::string & id)874   void set_id(const std::string& id) { id_ = id; }
set_type(PermissionType type)875   void set_type(PermissionType type) { type_ = type; }
set_role(PermissionRole role)876   void set_role(PermissionRole role) { role_ = role; }
set_value(const std::string & value)877   void set_value(const std::string& value) { value_ = value; }
878 
879   // UrlFetchRequestBase overrides.
880   virtual GURL GetURL() const OVERRIDE;
881   virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
882   virtual bool GetContentData(std::string* upload_content_type,
883                               std::string* upload_content) OVERRIDE;
884 
885  private:
886   const DriveApiUrlGenerator url_generator_;
887   std::string id_;
888   PermissionType type_;
889   PermissionRole role_;
890   std::string value_;
891 
892   DISALLOW_COPY_AND_ASSIGN(PermissionsInsertRequest);
893 };
894 
895 }  // namespace drive
896 }  // namespace google_apis
897 
898 #endif  // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
899