OLD | NEW |
| (Empty) |
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 CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_REQUESTS_H_ | |
6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_REQUESTS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/time/time.h" | |
12 #include "chrome/browser/google_apis/base_requests.h" | |
13 #include "chrome/browser/google_apis/drive_api_url_generator.h" | |
14 #include "chrome/browser/google_apis/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. | |
52 const std::string& fields() const { return 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. | |
82 const std::string& file_id() const { return 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 //============================ FilesInsertRequest ============================= | |
97 | |
98 // This class performs the request for creating a resource. | |
99 // This request is mapped to | |
100 // https://developers.google.com/drive/v2/reference/files/insert | |
101 // See also https://developers.google.com/drive/manage-uploads and | |
102 // https://developers.google.com/drive/folder | |
103 class FilesInsertRequest : public DriveApiDataRequest { | |
104 public: | |
105 FilesInsertRequest(RequestSender* sender, | |
106 const DriveApiUrlGenerator& url_generator, | |
107 const FileResourceCallback& callback); | |
108 virtual ~FilesInsertRequest(); | |
109 | |
110 // Optional request body. | |
111 const std::string& mime_type() const { return mime_type_; } | |
112 void set_mime_type(const std::string& mime_type) { | |
113 mime_type_ = mime_type; | |
114 } | |
115 | |
116 const std::vector<std::string>& parents() const { return parents_; } | |
117 void add_parent(const std::string& parent) { parents_.push_back(parent); } | |
118 | |
119 const std::string& title() const { return title_; } | |
120 void set_title(const std::string& title) { title_ = title; } | |
121 | |
122 protected: | |
123 // Overridden from GetDataRequest. | |
124 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
125 virtual bool GetContentData(std::string* upload_content_type, | |
126 std::string* upload_content) OVERRIDE; | |
127 | |
128 // Overridden from DriveApiDataRequest. | |
129 virtual GURL GetURLInternal() const OVERRIDE; | |
130 | |
131 private: | |
132 const DriveApiUrlGenerator url_generator_; | |
133 | |
134 std::string mime_type_; | |
135 std::vector<std::string> parents_; | |
136 std::string title_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(FilesInsertRequest); | |
139 }; | |
140 | |
141 //============================== FilesPatchRequest ============================ | |
142 | |
143 // This class performs the request for patching file metadata. | |
144 // This request is mapped to | |
145 // https://developers.google.com/drive/v2/reference/files/patch | |
146 class FilesPatchRequest : public DriveApiDataRequest { | |
147 public: | |
148 FilesPatchRequest(RequestSender* sender, | |
149 const DriveApiUrlGenerator& url_generator, | |
150 const FileResourceCallback& callback); | |
151 virtual ~FilesPatchRequest(); | |
152 | |
153 // Required parameter. | |
154 const std::string& file_id() const { return file_id_; } | |
155 void set_file_id(const std::string& file_id) { file_id_ = file_id; } | |
156 | |
157 // Optional parameter. | |
158 bool set_modified_date() const { return set_modified_date_; } | |
159 void set_set_modified_date(bool set_modified_date) { | |
160 set_modified_date_ = set_modified_date; | |
161 } | |
162 | |
163 bool update_viewed_date() const { return update_viewed_date_; } | |
164 void set_update_viewed_date(bool update_viewed_date) { | |
165 update_viewed_date_ = update_viewed_date; | |
166 } | |
167 | |
168 // Optional request body. | |
169 // Note: "Files: patch" accepts any "Files resource" data, but this class | |
170 // only supports limited members of it for now. We can extend it upon | |
171 // requirments. | |
172 const std::string& title() const { return title_; } | |
173 void set_title(const std::string& title) { title_ = title; } | |
174 | |
175 const base::Time& modified_date() const { return modified_date_; } | |
176 void set_modified_date(const base::Time& modified_date) { | |
177 modified_date_ = modified_date; | |
178 } | |
179 | |
180 const base::Time& last_viewed_by_me_date() const { | |
181 return last_viewed_by_me_date_; | |
182 } | |
183 void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) { | |
184 last_viewed_by_me_date_ = last_viewed_by_me_date; | |
185 } | |
186 | |
187 const std::vector<std::string>& parents() const { return parents_; } | |
188 void add_parent(const std::string& parent) { parents_.push_back(parent); } | |
189 | |
190 protected: | |
191 // Overridden from URLFetchRequestBase. | |
192 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
193 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
194 virtual bool GetContentData(std::string* upload_content_type, | |
195 std::string* upload_content) OVERRIDE; | |
196 | |
197 // Overridden from DriveApiDataRequest. | |
198 virtual GURL GetURLInternal() const OVERRIDE; | |
199 | |
200 private: | |
201 const DriveApiUrlGenerator url_generator_; | |
202 | |
203 std::string file_id_; | |
204 bool set_modified_date_; | |
205 bool update_viewed_date_; | |
206 | |
207 std::string title_; | |
208 base::Time modified_date_; | |
209 base::Time last_viewed_by_me_date_; | |
210 std::vector<std::string> parents_; | |
211 | |
212 DISALLOW_COPY_AND_ASSIGN(FilesPatchRequest); | |
213 }; | |
214 | |
215 //============================= FilesCopyRequest ============================== | |
216 | |
217 // This class performs the request for copying a resource. | |
218 // This request is mapped to | |
219 // https://developers.google.com/drive/v2/reference/files/copy | |
220 class FilesCopyRequest : public DriveApiDataRequest { | |
221 public: | |
222 // Upon completion, |callback| will be called. |callback| must not be null. | |
223 FilesCopyRequest(RequestSender* sender, | |
224 const DriveApiUrlGenerator& url_generator, | |
225 const FileResourceCallback& callback); | |
226 virtual ~FilesCopyRequest(); | |
227 | |
228 // Required parameter. | |
229 const std::string& file_id() const { return file_id_; } | |
230 void set_file_id(const std::string& file_id) { file_id_ = file_id; } | |
231 | |
232 // Optional request body. | |
233 const std::vector<std::string>& parents() const { return parents_; } | |
234 void add_parent(const std::string& parent) { parents_.push_back(parent); } | |
235 | |
236 const base::Time& modified_date() const { return modified_date_; } | |
237 void set_modified_date(const base::Time& modified_date) { | |
238 modified_date_ = modified_date; | |
239 } | |
240 | |
241 const std::string& title() const { return title_; } | |
242 void set_title(const std::string& title) { title_ = title; } | |
243 | |
244 protected: | |
245 // Overridden from URLFetchRequestBase. | |
246 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
247 virtual bool GetContentData(std::string* upload_content_type, | |
248 std::string* upload_content) OVERRIDE; | |
249 | |
250 // Overridden from DriveApiDataRequest. | |
251 virtual GURL GetURLInternal() const OVERRIDE; | |
252 | |
253 private: | |
254 const DriveApiUrlGenerator url_generator_; | |
255 | |
256 std::string file_id_; | |
257 base::Time modified_date_; | |
258 std::vector<std::string> parents_; | |
259 std::string title_; | |
260 | |
261 DISALLOW_COPY_AND_ASSIGN(FilesCopyRequest); | |
262 }; | |
263 | |
264 //============================= FilesListRequest ============================= | |
265 | |
266 // This class performs the request for fetching FileList. | |
267 // The result may contain only first part of the result. The remaining result | |
268 // should be able to be fetched by ContinueGetFileListRequest defined below, | |
269 // or by FilesListRequest with setting page token. | |
270 // This request is mapped to | |
271 // https://developers.google.com/drive/v2/reference/files/list | |
272 class FilesListRequest : public DriveApiDataRequest { | |
273 public: | |
274 FilesListRequest(RequestSender* sender, | |
275 const DriveApiUrlGenerator& url_generator, | |
276 const FileListCallback& callback); | |
277 virtual ~FilesListRequest(); | |
278 | |
279 // Optional parameter | |
280 int max_results() const { return max_results_; } | |
281 void set_max_results(int max_results) { max_results_ = max_results; } | |
282 | |
283 const std::string& page_token() const { return page_token_; } | |
284 void set_page_token(const std::string& page_token) { | |
285 page_token_ = page_token; | |
286 } | |
287 | |
288 const std::string& q() const { return q_; } | |
289 void set_q(const std::string& q) { q_ = q; } | |
290 | |
291 protected: | |
292 // Overridden from DriveApiDataRequest. | |
293 virtual GURL GetURLInternal() const OVERRIDE; | |
294 | |
295 private: | |
296 const DriveApiUrlGenerator url_generator_; | |
297 int max_results_; | |
298 std::string page_token_; | |
299 std::string q_; | |
300 | |
301 DISALLOW_COPY_AND_ASSIGN(FilesListRequest); | |
302 }; | |
303 | |
304 //========================= FilesListNextPageRequest ========================== | |
305 | |
306 // There are two ways to obtain next pages of "Files: list" result (if paged). | |
307 // 1) Set pageToken and all params used for the initial request. | |
308 // 2) Use URL in the nextLink field in the previous response. | |
309 // This class implements 2)'s request. | |
310 class FilesListNextPageRequest : public DriveApiDataRequest { | |
311 public: | |
312 FilesListNextPageRequest(RequestSender* sender, | |
313 const FileListCallback& callback); | |
314 virtual ~FilesListNextPageRequest(); | |
315 | |
316 const GURL& next_link() const { return next_link_; } | |
317 void set_next_link(const GURL& next_link) { next_link_ = next_link; } | |
318 | |
319 protected: | |
320 // Overridden from DriveApiDataRequest. | |
321 virtual GURL GetURLInternal() const OVERRIDE; | |
322 | |
323 private: | |
324 GURL next_link_; | |
325 | |
326 DISALLOW_COPY_AND_ASSIGN(FilesListNextPageRequest); | |
327 }; | |
328 | |
329 //============================= FilesTrashRequest ============================= | |
330 | |
331 // This class performs the request for trashing a resource. | |
332 // This request is mapped to | |
333 // https://developers.google.com/drive/v2/reference/files/trash | |
334 class FilesTrashRequest : public DriveApiDataRequest { | |
335 public: | |
336 FilesTrashRequest(RequestSender* sender, | |
337 const DriveApiUrlGenerator& url_generator, | |
338 const FileResourceCallback& callback); | |
339 virtual ~FilesTrashRequest(); | |
340 | |
341 // Required parameter. | |
342 const std::string& file_id() const { return file_id_; } | |
343 void set_file_id(const std::string& file_id) { file_id_ = file_id; } | |
344 | |
345 protected: | |
346 // Overridden from UrlFetchRequestBase. | |
347 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
348 | |
349 // Overridden from DriveApiDataRequest. | |
350 virtual GURL GetURLInternal() const OVERRIDE; | |
351 | |
352 private: | |
353 const DriveApiUrlGenerator url_generator_; | |
354 std::string file_id_; | |
355 | |
356 DISALLOW_COPY_AND_ASSIGN(FilesTrashRequest); | |
357 }; | |
358 | |
359 //============================== AboutGetRequest ============================= | |
360 | |
361 // This class performs the request for fetching About data. | |
362 // This request is mapped to | |
363 // https://developers.google.com/drive/v2/reference/about/get | |
364 class AboutGetRequest : public DriveApiDataRequest { | |
365 public: | |
366 AboutGetRequest(RequestSender* sender, | |
367 const DriveApiUrlGenerator& url_generator, | |
368 const AboutResourceCallback& callback); | |
369 virtual ~AboutGetRequest(); | |
370 | |
371 protected: | |
372 // Overridden from DriveApiDataRequest. | |
373 virtual GURL GetURLInternal() const OVERRIDE; | |
374 | |
375 private: | |
376 const DriveApiUrlGenerator url_generator_; | |
377 | |
378 DISALLOW_COPY_AND_ASSIGN(AboutGetRequest); | |
379 }; | |
380 | |
381 //============================ ChangesListRequest ============================ | |
382 | |
383 // This class performs the request for fetching ChangeList. | |
384 // The result may contain only first part of the result. The remaining result | |
385 // should be able to be fetched by ContinueGetFileListRequest defined below. | |
386 // or by ChangesListRequest with setting page token. | |
387 // This request is mapped to | |
388 // https://developers.google.com/drive/v2/reference/changes/list | |
389 class ChangesListRequest : public DriveApiDataRequest { | |
390 public: | |
391 ChangesListRequest(RequestSender* sender, | |
392 const DriveApiUrlGenerator& url_generator, | |
393 const ChangeListCallback& callback); | |
394 virtual ~ChangesListRequest(); | |
395 | |
396 // Optional parameter | |
397 bool include_deleted() const { return include_deleted_; } | |
398 void set_include_deleted(bool include_deleted) { | |
399 include_deleted_ = include_deleted; | |
400 } | |
401 | |
402 int max_results() const { return max_results_; } | |
403 void set_max_results(int max_results) { max_results_ = max_results; } | |
404 | |
405 const std::string& page_token() const { return page_token_; } | |
406 void set_page_token(const std::string& page_token) { | |
407 page_token_ = page_token; | |
408 } | |
409 | |
410 int64 start_change_id() const { return start_change_id_; } | |
411 void set_start_change_id(int64 start_change_id) { | |
412 start_change_id_ = start_change_id; | |
413 } | |
414 | |
415 protected: | |
416 // Overridden from DriveApiDataRequest. | |
417 virtual GURL GetURLInternal() const OVERRIDE; | |
418 | |
419 private: | |
420 const DriveApiUrlGenerator url_generator_; | |
421 bool include_deleted_; | |
422 int max_results_; | |
423 std::string page_token_; | |
424 int64 start_change_id_; | |
425 | |
426 DISALLOW_COPY_AND_ASSIGN(ChangesListRequest); | |
427 }; | |
428 | |
429 //======================== ChangesListNextPageRequest ========================= | |
430 | |
431 // There are two ways to obtain next pages of "Changes: list" result (if paged). | |
432 // 1) Set pageToken and all params used for the initial request. | |
433 // 2) Use URL in the nextLink field in the previous response. | |
434 // This class implements 2)'s request. | |
435 class ChangesListNextPageRequest : public DriveApiDataRequest { | |
436 public: | |
437 ChangesListNextPageRequest(RequestSender* sender, | |
438 const ChangeListCallback& callback); | |
439 virtual ~ChangesListNextPageRequest(); | |
440 | |
441 const GURL& next_link() const { return next_link_; } | |
442 void set_next_link(const GURL& next_link) { next_link_ = next_link; } | |
443 | |
444 protected: | |
445 // Overridden from DriveApiDataRequest. | |
446 virtual GURL GetURLInternal() const OVERRIDE; | |
447 | |
448 private: | |
449 GURL next_link_; | |
450 | |
451 DISALLOW_COPY_AND_ASSIGN(ChangesListNextPageRequest); | |
452 }; | |
453 | |
454 //============================= AppsListRequest ============================ | |
455 | |
456 // This class performs the request for fetching AppList. | |
457 // This request is mapped to | |
458 // https://developers.google.com/drive/v2/reference/apps/list | |
459 class AppsListRequest : public DriveApiDataRequest { | |
460 public: | |
461 AppsListRequest(RequestSender* sender, | |
462 const DriveApiUrlGenerator& url_generator, | |
463 const AppListCallback& callback); | |
464 virtual ~AppsListRequest(); | |
465 | |
466 protected: | |
467 // Overridden from DriveApiDataRequest. | |
468 virtual GURL GetURLInternal() const OVERRIDE; | |
469 | |
470 private: | |
471 const DriveApiUrlGenerator url_generator_; | |
472 | |
473 DISALLOW_COPY_AND_ASSIGN(AppsListRequest); | |
474 }; | |
475 | |
476 //========================== ChildrenInsertRequest ============================ | |
477 | |
478 // This class performs the request for inserting a resource to a directory. | |
479 // This request is mapped to | |
480 // https://developers.google.com/drive/v2/reference/children/insert | |
481 class ChildrenInsertRequest : public EntryActionRequest { | |
482 public: | |
483 ChildrenInsertRequest(RequestSender* sender, | |
484 const DriveApiUrlGenerator& url_generator, | |
485 const EntryActionCallback& callback); | |
486 virtual ~ChildrenInsertRequest(); | |
487 | |
488 // Required parameter. | |
489 const std::string& folder_id() const { return folder_id_; } | |
490 void set_folder_id(const std::string& folder_id) { | |
491 folder_id_ = folder_id; | |
492 } | |
493 | |
494 // Required body. | |
495 const std::string& id() const { return id_; } | |
496 void set_id(const std::string& id) { id_ = id; } | |
497 | |
498 protected: | |
499 // UrlFetchRequestBase overrides. | |
500 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
501 virtual GURL GetURL() const OVERRIDE; | |
502 virtual bool GetContentData(std::string* upload_content_type, | |
503 std::string* upload_content) OVERRIDE; | |
504 | |
505 private: | |
506 const DriveApiUrlGenerator url_generator_; | |
507 std::string folder_id_; | |
508 std::string id_; | |
509 | |
510 DISALLOW_COPY_AND_ASSIGN(ChildrenInsertRequest); | |
511 }; | |
512 | |
513 //========================== ChildrenDeleteRequest ============================ | |
514 | |
515 // This class performs the request for removing a resource from a directory. | |
516 // This request is mapped to | |
517 // https://developers.google.com/drive/v2/reference/children/delete | |
518 class ChildrenDeleteRequest : public EntryActionRequest { | |
519 public: | |
520 // |callback| must not be null. | |
521 ChildrenDeleteRequest(RequestSender* sender, | |
522 const DriveApiUrlGenerator& url_generator, | |
523 const EntryActionCallback& callback); | |
524 virtual ~ChildrenDeleteRequest(); | |
525 | |
526 // Required parameter. | |
527 const std::string& child_id() const { return child_id_; } | |
528 void set_child_id(const std::string& child_id) { | |
529 child_id_ = child_id; | |
530 } | |
531 | |
532 const std::string& folder_id() const { return folder_id_; } | |
533 void set_folder_id(const std::string& folder_id) { | |
534 folder_id_ = folder_id; | |
535 } | |
536 | |
537 protected: | |
538 // UrlFetchRequestBase overrides. | |
539 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
540 virtual GURL GetURL() const OVERRIDE; | |
541 | |
542 private: | |
543 const DriveApiUrlGenerator url_generator_; | |
544 std::string child_id_; | |
545 std::string folder_id_; | |
546 | |
547 DISALLOW_COPY_AND_ASSIGN(ChildrenDeleteRequest); | |
548 }; | |
549 | |
550 //======================= InitiateUploadNewFileRequest ======================= | |
551 | |
552 // This class performs the request for initiating the upload of a new file. | |
553 class InitiateUploadNewFileRequest : public InitiateUploadRequestBase { | |
554 public: | |
555 // |parent_resource_id| should be the resource id of the parent directory. | |
556 // |title| should be set. | |
557 // See also the comments of InitiateUploadRequestBase for more details | |
558 // about the other parameters. | |
559 InitiateUploadNewFileRequest(RequestSender* sender, | |
560 const DriveApiUrlGenerator& url_generator, | |
561 const std::string& content_type, | |
562 int64 content_length, | |
563 const std::string& parent_resource_id, | |
564 const std::string& title, | |
565 const InitiateUploadCallback& callback); | |
566 virtual ~InitiateUploadNewFileRequest(); | |
567 | |
568 protected: | |
569 // UrlFetchRequestBase overrides. | |
570 virtual GURL GetURL() const OVERRIDE; | |
571 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
572 virtual bool GetContentData(std::string* upload_content_type, | |
573 std::string* upload_content) OVERRIDE; | |
574 | |
575 private: | |
576 const DriveApiUrlGenerator url_generator_; | |
577 const std::string parent_resource_id_; | |
578 const std::string title_; | |
579 | |
580 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest); | |
581 }; | |
582 | |
583 //==================== InitiateUploadExistingFileRequest ===================== | |
584 | |
585 // This class performs the request for initiating the upload of an existing | |
586 // file. | |
587 class InitiateUploadExistingFileRequest : public InitiateUploadRequestBase { | |
588 public: | |
589 // |upload_url| should be the upload_url() of the file | |
590 // (resumable-create-media URL) | |
591 // |etag| should be set if it is available to detect the upload confliction. | |
592 // See also the comments of InitiateUploadRequestBase for more details | |
593 // about the other parameters. | |
594 InitiateUploadExistingFileRequest(RequestSender* sender, | |
595 const DriveApiUrlGenerator& url_generator, | |
596 const std::string& content_type, | |
597 int64 content_length, | |
598 const std::string& resource_id, | |
599 const std::string& etag, | |
600 const InitiateUploadCallback& callback); | |
601 virtual ~InitiateUploadExistingFileRequest(); | |
602 | |
603 protected: | |
604 // UrlFetchRequestBase overrides. | |
605 virtual GURL GetURL() const OVERRIDE; | |
606 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
607 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
608 | |
609 private: | |
610 const DriveApiUrlGenerator url_generator_; | |
611 const std::string resource_id_; | |
612 const std::string etag_; | |
613 | |
614 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest); | |
615 }; | |
616 | |
617 // Callback used for ResumeUpload() and GetUploadStatus(). | |
618 typedef base::Callback<void( | |
619 const UploadRangeResponse& response, | |
620 scoped_ptr<FileResource> new_resource)> UploadRangeCallback; | |
621 | |
622 //============================ ResumeUploadRequest =========================== | |
623 | |
624 // Performs the request for resuming the upload of a file. | |
625 class ResumeUploadRequest : public ResumeUploadRequestBase { | |
626 public: | |
627 // See also ResumeUploadRequestBase's comment for parameters meaning. | |
628 // |callback| must not be null. |progress_callback| may be null. | |
629 ResumeUploadRequest(RequestSender* sender, | |
630 const GURL& upload_location, | |
631 int64 start_position, | |
632 int64 end_position, | |
633 int64 content_length, | |
634 const std::string& content_type, | |
635 const base::FilePath& local_file_path, | |
636 const UploadRangeCallback& callback, | |
637 const ProgressCallback& progress_callback); | |
638 virtual ~ResumeUploadRequest(); | |
639 | |
640 protected: | |
641 // UploadRangeRequestBase overrides. | |
642 virtual void OnRangeRequestComplete( | |
643 const UploadRangeResponse& response, | |
644 scoped_ptr<base::Value> value) OVERRIDE; | |
645 // content::UrlFetcherDelegate overrides. | |
646 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | |
647 int64 current, int64 total) OVERRIDE; | |
648 | |
649 private: | |
650 const UploadRangeCallback callback_; | |
651 const ProgressCallback progress_callback_; | |
652 | |
653 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest); | |
654 }; | |
655 | |
656 //========================== GetUploadStatusRequest ========================== | |
657 | |
658 // Performs the request to fetch the current upload status of a file. | |
659 class GetUploadStatusRequest : public GetUploadStatusRequestBase { | |
660 public: | |
661 // See also GetUploadStatusRequestBase's comment for parameters meaning. | |
662 // |callback| must not be null. | |
663 GetUploadStatusRequest(RequestSender* sender, | |
664 const GURL& upload_url, | |
665 int64 content_length, | |
666 const UploadRangeCallback& callback); | |
667 virtual ~GetUploadStatusRequest(); | |
668 | |
669 protected: | |
670 // UploadRangeRequestBase overrides. | |
671 virtual void OnRangeRequestComplete( | |
672 const UploadRangeResponse& response, | |
673 scoped_ptr<base::Value> value) OVERRIDE; | |
674 | |
675 private: | |
676 const UploadRangeCallback callback_; | |
677 | |
678 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest); | |
679 }; | |
680 | |
681 //========================== DownloadFileRequest ========================== | |
682 | |
683 // This class performs the request for downloading of a specified file. | |
684 class DownloadFileRequest : public DownloadFileRequestBase { | |
685 public: | |
686 // See also DownloadFileRequestBase's comment for parameters meaning. | |
687 DownloadFileRequest(RequestSender* sender, | |
688 const DriveApiUrlGenerator& url_generator, | |
689 const std::string& resource_id, | |
690 const base::FilePath& output_file_path, | |
691 const DownloadActionCallback& download_action_callback, | |
692 const GetContentCallback& get_content_callback, | |
693 const ProgressCallback& progress_callback); | |
694 virtual ~DownloadFileRequest(); | |
695 | |
696 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest); | |
697 }; | |
698 | |
699 } // namespace drive | |
700 } // namespace google_apis | |
701 | |
702 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_REQUESTS_H_ | |
OLD | NEW |