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_GDATA_WAPI_REQUESTS_H_ | |
6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_REQUESTS_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "chrome/browser/google_apis/base_requests.h" | |
12 #include "chrome/browser/google_apis/drive_common_callbacks.h" | |
13 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | |
14 | |
15 namespace google_apis { | |
16 | |
17 class AccountMetadata; | |
18 class GDataWapiUrlGenerator; | |
19 class ResourceEntry; | |
20 | |
21 //============================ GetResourceListRequest ======================== | |
22 | |
23 // This class performs the request for fetching a resource list. | |
24 class GetResourceListRequest : public GetDataRequest { | |
25 public: | |
26 // override_url: | |
27 // If empty, a hard-coded base URL of the WAPI server is used to fetch | |
28 // the first page of the feed. This parameter is used for fetching 2nd | |
29 // page and onward. | |
30 // | |
31 // start_changestamp: | |
32 // This parameter specifies the starting point of a delta feed or 0 if a | |
33 // full feed is necessary. | |
34 // | |
35 // search_string: | |
36 // If non-empty, fetches a list of resources that match the search | |
37 // string. | |
38 // | |
39 // directory_resource_id: | |
40 // If non-empty, fetches a list of resources in a particular directory. | |
41 // | |
42 // callback: | |
43 // Called once the feed is fetched. Must not be null. | |
44 GetResourceListRequest(RequestSender* sender, | |
45 const GDataWapiUrlGenerator& url_generator, | |
46 const GURL& override_url, | |
47 int64 start_changestamp, | |
48 const std::string& search_string, | |
49 const std::string& directory_resource_id, | |
50 const GetResourceListCallback& callback); | |
51 virtual ~GetResourceListRequest(); | |
52 | |
53 protected: | |
54 // UrlFetchRequestBase overrides. | |
55 virtual GURL GetURL() const OVERRIDE; | |
56 | |
57 private: | |
58 const GDataWapiUrlGenerator url_generator_; | |
59 const GURL override_url_; | |
60 const int64 start_changestamp_; | |
61 const std::string search_string_; | |
62 const std::string directory_resource_id_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(GetResourceListRequest); | |
65 }; | |
66 | |
67 //============================ SearchByTitleRequest ========================== | |
68 | |
69 // This class performs the request for searching resources by title. | |
70 class SearchByTitleRequest : public GetDataRequest { | |
71 public: | |
72 // title: the search query. | |
73 // | |
74 // directory_resource_id: If given (non-empty), the search target is | |
75 // directly under the directory with the |directory_resource_id|. | |
76 // If empty, the search target is all the existing resources. | |
77 // | |
78 // callback: | |
79 // Called once the feed is fetched. Must not be null. | |
80 SearchByTitleRequest(RequestSender* sender, | |
81 const GDataWapiUrlGenerator& url_generator, | |
82 const std::string& title, | |
83 const std::string& directory_resource_id, | |
84 const GetResourceListCallback& callback); | |
85 virtual ~SearchByTitleRequest(); | |
86 | |
87 protected: | |
88 // UrlFetchRequestBase overrides. | |
89 virtual GURL GetURL() const OVERRIDE; | |
90 | |
91 private: | |
92 const GDataWapiUrlGenerator url_generator_; | |
93 const std::string title_; | |
94 const std::string directory_resource_id_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(SearchByTitleRequest); | |
97 }; | |
98 | |
99 //========================= GetResourceEntryRequest ========================== | |
100 | |
101 // This class performs the request for fetching a single resource entry. | |
102 class GetResourceEntryRequest : public GetDataRequest { | |
103 public: | |
104 // |callback| must not be null. | |
105 GetResourceEntryRequest(RequestSender* sender, | |
106 const GDataWapiUrlGenerator& url_generator, | |
107 const std::string& resource_id, | |
108 const GURL& embed_origin, | |
109 const GetDataCallback& callback); | |
110 virtual ~GetResourceEntryRequest(); | |
111 | |
112 protected: | |
113 // UrlFetchRequestBase overrides. | |
114 virtual GURL GetURL() const OVERRIDE; | |
115 | |
116 private: | |
117 const GDataWapiUrlGenerator url_generator_; | |
118 // Resource id of the requested entry. | |
119 const std::string resource_id_; | |
120 // Embed origin for an url to the sharing dialog. Can be empty. | |
121 const GURL& embed_origin_; | |
122 | |
123 DISALLOW_COPY_AND_ASSIGN(GetResourceEntryRequest); | |
124 }; | |
125 | |
126 //========================= GetAccountMetadataRequest ======================== | |
127 | |
128 // Callback used for GetAccountMetadata(). | |
129 typedef base::Callback<void(GDataErrorCode error, | |
130 scoped_ptr<AccountMetadata> account_metadata)> | |
131 GetAccountMetadataCallback; | |
132 | |
133 // This class performs the request for fetching account metadata. | |
134 class GetAccountMetadataRequest : public GetDataRequest { | |
135 public: | |
136 // If |include_installed_apps| is set to true, the result should include | |
137 // the list of installed third party applications. | |
138 // |callback| must not be null. | |
139 GetAccountMetadataRequest(RequestSender* sender, | |
140 const GDataWapiUrlGenerator& url_generator, | |
141 const GetAccountMetadataCallback& callback, | |
142 bool include_installed_apps); | |
143 virtual ~GetAccountMetadataRequest(); | |
144 | |
145 protected: | |
146 // UrlFetchRequestBase overrides. | |
147 virtual GURL GetURL() const OVERRIDE; | |
148 | |
149 private: | |
150 const GDataWapiUrlGenerator url_generator_; | |
151 const bool include_installed_apps_; | |
152 | |
153 DISALLOW_COPY_AND_ASSIGN(GetAccountMetadataRequest); | |
154 }; | |
155 | |
156 //=========================== DeleteResourceRequest ========================== | |
157 | |
158 // This class performs the request for deleting a resource. | |
159 // | |
160 // In WAPI, "gd:deleted" means that the resource was put in the trash, and | |
161 // "docs:removed" means its permanently gone. Since what the class does is to | |
162 // put the resource into trash, we have chosen "Delete" in the name, even though | |
163 // we are preferring the term "Remove" in drive/google_api code. | |
164 class DeleteResourceRequest : public EntryActionRequest { | |
165 public: | |
166 // |callback| must not be null. | |
167 DeleteResourceRequest(RequestSender* sender, | |
168 const GDataWapiUrlGenerator& url_generator, | |
169 const EntryActionCallback& callback, | |
170 const std::string& resource_id, | |
171 const std::string& etag); | |
172 virtual ~DeleteResourceRequest(); | |
173 | |
174 protected: | |
175 // UrlFetchRequestBase overrides. | |
176 virtual GURL GetURL() const OVERRIDE; | |
177 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
178 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
179 | |
180 private: | |
181 const GDataWapiUrlGenerator url_generator_; | |
182 const std::string resource_id_; | |
183 const std::string etag_; | |
184 | |
185 DISALLOW_COPY_AND_ASSIGN(DeleteResourceRequest); | |
186 }; | |
187 | |
188 //========================== CreateDirectoryRequest ========================== | |
189 | |
190 // This class performs the request for creating a directory. | |
191 class CreateDirectoryRequest : public GetDataRequest { | |
192 public: | |
193 // A new directory will be created under a directory specified by | |
194 // |parent_resource_id|. If this parameter is empty, a new directory will | |
195 // be created in the root directory. | |
196 // |callback| must not be null. | |
197 CreateDirectoryRequest(RequestSender* sender, | |
198 const GDataWapiUrlGenerator& url_generator, | |
199 const GetDataCallback& callback, | |
200 const std::string& parent_resource_id, | |
201 const std::string& directory_title); | |
202 virtual ~CreateDirectoryRequest(); | |
203 | |
204 protected: | |
205 // UrlFetchRequestBase overrides. | |
206 virtual GURL GetURL() const OVERRIDE; | |
207 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
208 virtual bool GetContentData(std::string* upload_content_type, | |
209 std::string* upload_content) OVERRIDE; | |
210 | |
211 private: | |
212 const GDataWapiUrlGenerator url_generator_; | |
213 const std::string parent_resource_id_; | |
214 const std::string directory_title_; | |
215 | |
216 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryRequest); | |
217 }; | |
218 | |
219 //============================ CopyHostedDocumentRequest ===================== | |
220 | |
221 // This class performs the request for making a copy of a hosted document. | |
222 // Note that this function cannot be used to copy regular files, as it's not | |
223 // supported by WAPI. | |
224 class CopyHostedDocumentRequest : public GetDataRequest { | |
225 public: | |
226 // |callback| must not be null. | |
227 CopyHostedDocumentRequest(RequestSender* sender, | |
228 const GDataWapiUrlGenerator& url_generator, | |
229 const GetDataCallback& callback, | |
230 const std::string& resource_id, | |
231 const std::string& new_title); | |
232 virtual ~CopyHostedDocumentRequest(); | |
233 | |
234 protected: | |
235 // UrlFetchRequestBase overrides. | |
236 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
237 virtual GURL GetURL() const OVERRIDE; | |
238 virtual bool GetContentData(std::string* upload_content_type, | |
239 std::string* upload_content) OVERRIDE; | |
240 | |
241 private: | |
242 const GDataWapiUrlGenerator url_generator_; | |
243 const std::string resource_id_; | |
244 const std::string new_title_; | |
245 | |
246 DISALLOW_COPY_AND_ASSIGN(CopyHostedDocumentRequest); | |
247 }; | |
248 | |
249 //=========================== RenameResourceRequest ========================== | |
250 | |
251 // This class performs the request for renaming a document/file/directory. | |
252 class RenameResourceRequest : public EntryActionRequest { | |
253 public: | |
254 // |callback| must not be null. | |
255 RenameResourceRequest(RequestSender* sender, | |
256 const GDataWapiUrlGenerator& url_generator, | |
257 const EntryActionCallback& callback, | |
258 const std::string& resource_id, | |
259 const std::string& new_title); | |
260 virtual ~RenameResourceRequest(); | |
261 | |
262 protected: | |
263 // UrlFetchRequestBase overrides. | |
264 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
265 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
266 virtual GURL GetURL() const OVERRIDE; | |
267 virtual bool GetContentData(std::string* upload_content_type, | |
268 std::string* upload_content) OVERRIDE; | |
269 | |
270 private: | |
271 const GDataWapiUrlGenerator url_generator_; | |
272 const std::string resource_id_; | |
273 const std::string new_title_; | |
274 | |
275 DISALLOW_COPY_AND_ASSIGN(RenameResourceRequest); | |
276 }; | |
277 | |
278 //=========================== AuthorizeAppRequest ========================== | |
279 | |
280 // This class performs the request for authorizing an application specified | |
281 // by |app_id| to access a document specified by |resource_id|. | |
282 class AuthorizeAppRequest : public GetDataRequest { | |
283 public: | |
284 // |callback| must not be null. | |
285 AuthorizeAppRequest(RequestSender* sender, | |
286 const GDataWapiUrlGenerator& url_generator, | |
287 const AuthorizeAppCallback& callback, | |
288 const std::string& resource_id, | |
289 const std::string& app_id); | |
290 virtual ~AuthorizeAppRequest(); | |
291 | |
292 protected: | |
293 // UrlFetchRequestBase overrides. | |
294 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
295 virtual bool GetContentData(std::string* upload_content_type, | |
296 std::string* upload_content) OVERRIDE; | |
297 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
298 virtual GURL GetURL() const OVERRIDE; | |
299 | |
300 private: | |
301 const GDataWapiUrlGenerator url_generator_; | |
302 const std::string resource_id_; | |
303 const std::string app_id_; | |
304 | |
305 DISALLOW_COPY_AND_ASSIGN(AuthorizeAppRequest); | |
306 }; | |
307 | |
308 //======================= AddResourceToDirectoryRequest ====================== | |
309 | |
310 // This class performs the request for adding a document/file/directory | |
311 // to a directory. | |
312 class AddResourceToDirectoryRequest : public EntryActionRequest { | |
313 public: | |
314 // |callback| must not be null. | |
315 AddResourceToDirectoryRequest(RequestSender* sender, | |
316 const GDataWapiUrlGenerator& url_generator, | |
317 const EntryActionCallback& callback, | |
318 const std::string& parent_resource_id, | |
319 const std::string& resource_id); | |
320 virtual ~AddResourceToDirectoryRequest(); | |
321 | |
322 protected: | |
323 // UrlFetchRequestBase overrides. | |
324 virtual GURL GetURL() const OVERRIDE; | |
325 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
326 virtual bool GetContentData(std::string* upload_content_type, | |
327 std::string* upload_content) OVERRIDE; | |
328 | |
329 private: | |
330 const GDataWapiUrlGenerator url_generator_; | |
331 const std::string parent_resource_id_; | |
332 const std::string resource_id_; | |
333 | |
334 DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryRequest); | |
335 }; | |
336 | |
337 //==================== RemoveResourceFromDirectoryRequest ==================== | |
338 | |
339 // This class performs the request for removing a document/file/directory | |
340 // from a directory. | |
341 class RemoveResourceFromDirectoryRequest : public EntryActionRequest { | |
342 public: | |
343 // |callback| must not be null. | |
344 RemoveResourceFromDirectoryRequest(RequestSender* sender, | |
345 const GDataWapiUrlGenerator& url_generator, | |
346 const EntryActionCallback& callback, | |
347 const std::string& parent_resource_id, | |
348 const std::string& resource_id); | |
349 virtual ~RemoveResourceFromDirectoryRequest(); | |
350 | |
351 protected: | |
352 // UrlFetchRequestBase overrides. | |
353 virtual GURL GetURL() const OVERRIDE; | |
354 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
355 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
356 | |
357 private: | |
358 const GDataWapiUrlGenerator url_generator_; | |
359 const std::string resource_id_; | |
360 const std::string parent_resource_id_; | |
361 | |
362 DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryRequest); | |
363 }; | |
364 | |
365 //======================= InitiateUploadNewFileRequest ======================= | |
366 | |
367 // This class performs the request for initiating the upload of a new file. | |
368 class InitiateUploadNewFileRequest : public InitiateUploadRequestBase { | |
369 public: | |
370 // |title| should be set. | |
371 // |parent_upload_url| should be the upload_url() of the parent directory. | |
372 // (resumable-create-media URL) | |
373 // See also the comments of InitiateUploadRequestBase for more details | |
374 // about the other parameters. | |
375 InitiateUploadNewFileRequest(RequestSender* sender, | |
376 const GDataWapiUrlGenerator& url_generator, | |
377 const InitiateUploadCallback& callback, | |
378 const std::string& content_type, | |
379 int64 content_length, | |
380 const std::string& parent_resource_id, | |
381 const std::string& title); | |
382 virtual ~InitiateUploadNewFileRequest(); | |
383 | |
384 protected: | |
385 // UrlFetchRequestBase overrides. | |
386 virtual GURL GetURL() const OVERRIDE; | |
387 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
388 virtual bool GetContentData(std::string* upload_content_type, | |
389 std::string* upload_content) OVERRIDE; | |
390 | |
391 private: | |
392 const GDataWapiUrlGenerator url_generator_; | |
393 const std::string parent_resource_id_; | |
394 const std::string title_; | |
395 | |
396 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileRequest); | |
397 }; | |
398 | |
399 //==================== InitiateUploadExistingFileRequest ===================== | |
400 | |
401 // This class performs the request for initiating the upload of an existing | |
402 // file. | |
403 class InitiateUploadExistingFileRequest | |
404 : public InitiateUploadRequestBase { | |
405 public: | |
406 // |upload_url| should be the upload_url() of the file | |
407 // (resumable-create-media URL) | |
408 // |etag| should be set if it is available to detect the upload confliction. | |
409 // See also the comments of InitiateUploadRequestBase for more details | |
410 // about the other parameters. | |
411 InitiateUploadExistingFileRequest(RequestSender* sender, | |
412 const GDataWapiUrlGenerator& url_generator, | |
413 const InitiateUploadCallback& callback, | |
414 const std::string& content_type, | |
415 int64 content_length, | |
416 const std::string& resource_id, | |
417 const std::string& etag); | |
418 virtual ~InitiateUploadExistingFileRequest(); | |
419 | |
420 protected: | |
421 // UrlFetchRequestBase overrides. | |
422 virtual GURL GetURL() const OVERRIDE; | |
423 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | |
424 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
425 virtual bool GetContentData(std::string* upload_content_type, | |
426 std::string* upload_content) OVERRIDE; | |
427 | |
428 private: | |
429 const GDataWapiUrlGenerator url_generator_; | |
430 const std::string resource_id_; | |
431 const std::string etag_; | |
432 | |
433 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest); | |
434 }; | |
435 | |
436 //============================ ResumeUploadRequest =========================== | |
437 | |
438 // Performs the request for resuming the upload of a file. | |
439 class ResumeUploadRequest : public ResumeUploadRequestBase { | |
440 public: | |
441 // See also ResumeUploadRequestBase's comment for parameters meaning. | |
442 // |callback| must not be null. | |
443 ResumeUploadRequest(RequestSender* sender, | |
444 const UploadRangeCallback& callback, | |
445 const ProgressCallback& progress_callback, | |
446 const GURL& upload_location, | |
447 int64 start_position, | |
448 int64 end_position, | |
449 int64 content_length, | |
450 const std::string& content_type, | |
451 const base::FilePath& local_file_path); | |
452 virtual ~ResumeUploadRequest(); | |
453 | |
454 protected: | |
455 // UploadRangeRequestBase overrides. | |
456 virtual void OnRangeRequestComplete( | |
457 const UploadRangeResponse& response, | |
458 scoped_ptr<base::Value> value) OVERRIDE; | |
459 // content::UrlFetcherDelegate overrides. | |
460 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | |
461 int64 current, int64 total) OVERRIDE; | |
462 | |
463 private: | |
464 const UploadRangeCallback callback_; | |
465 const ProgressCallback progress_callback_; | |
466 | |
467 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest); | |
468 }; | |
469 | |
470 //========================== GetUploadStatusRequest ========================== | |
471 | |
472 // Performs the request to request the current upload status of a file. | |
473 class GetUploadStatusRequest : public GetUploadStatusRequestBase { | |
474 public: | |
475 // See also GetUploadStatusRequestBase's comment for parameters meaning. | |
476 // |callback| must not be null. | |
477 GetUploadStatusRequest(RequestSender* sender, | |
478 const UploadRangeCallback& callback, | |
479 const GURL& upload_url, | |
480 int64 content_length); | |
481 virtual ~GetUploadStatusRequest(); | |
482 | |
483 protected: | |
484 // UploadRangeRequestBase overrides. | |
485 virtual void OnRangeRequestComplete( | |
486 const UploadRangeResponse& response, | |
487 scoped_ptr<base::Value> value) OVERRIDE; | |
488 | |
489 private: | |
490 const UploadRangeCallback callback_; | |
491 | |
492 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest); | |
493 }; | |
494 | |
495 | |
496 //========================== DownloadFileRequest ========================== | |
497 | |
498 // This class performs the request for downloading of a specified file. | |
499 class DownloadFileRequest : public DownloadFileRequestBase { | |
500 public: | |
501 // See also DownloadFileRequestBase's comment for parameters meaning. | |
502 DownloadFileRequest(RequestSender* sender, | |
503 const GDataWapiUrlGenerator& url_generator, | |
504 const DownloadActionCallback& download_action_callback, | |
505 const GetContentCallback& get_content_callback, | |
506 const ProgressCallback& progress_callback, | |
507 const std::string& resource_id, | |
508 const base::FilePath& output_file_path); | |
509 virtual ~DownloadFileRequest(); | |
510 | |
511 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest); | |
512 }; | |
513 | |
514 } // namespace google_apis | |
515 | |
516 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_REQUESTS_H_ | |
OLD | NEW |