Fix build break
[chromium-blink-merge.git] / chrome / browser / google_apis / drive_api_operations.h
blobbba076d3154f0b5594d88629397c4d93f6520b00
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 CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_
6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "chrome/browser/google_apis/base_operations.h"
12 #include "chrome/browser/google_apis/drive_api_url_generator.h"
13 #include "chrome/browser/google_apis/drive_service_interface.h"
15 namespace net {
16 class URLRequestContextGetter;
17 } // namespace net
19 namespace google_apis {
21 class FileResource;
23 // Callback used for operations that the server returns FileResource data
24 // formatted into JSON value.
25 typedef base::Callback<void(GDataErrorCode error,
26 scoped_ptr<FileResource> entry)>
27 FileResourceCallback;
30 //============================== GetAboutOperation =============================
32 // This class performs the operation for fetching About data.
33 class GetAboutOperation : public GetDataOperation {
34 public:
35 GetAboutOperation(OperationRegistry* registry,
36 net::URLRequestContextGetter* url_request_context_getter,
37 const DriveApiUrlGenerator& url_generator,
38 const GetAboutResourceCallback& callback);
39 virtual ~GetAboutOperation();
41 protected:
42 // Overridden from GetDataOperation.
43 virtual GURL GetURL() const OVERRIDE;
45 private:
46 const DriveApiUrlGenerator url_generator_;
48 DISALLOW_COPY_AND_ASSIGN(GetAboutOperation);
51 //============================= GetApplistOperation ============================
53 // This class performs the operation for fetching Applist.
54 class GetApplistOperation : public GetDataOperation {
55 public:
56 GetApplistOperation(OperationRegistry* registry,
57 net::URLRequestContextGetter* url_request_context_getter,
58 const DriveApiUrlGenerator& url_generator,
59 const GetDataCallback& callback);
60 virtual ~GetApplistOperation();
62 protected:
63 // Overridden from GetDataOperation.
64 virtual GURL GetURL() const OVERRIDE;
66 private:
67 const DriveApiUrlGenerator url_generator_;
69 DISALLOW_COPY_AND_ASSIGN(GetApplistOperation);
72 //============================ GetChangelistOperation ==========================
74 // This class performs the operation for fetching changelist.
75 // The result may contain only first part of the result. The remaining result
76 // should be able to be fetched by ContinueGetFileListOperation defined below.
77 class GetChangelistOperation : public GetDataOperation {
78 public:
79 // |include_deleted| specifies if the response should contain the changes
80 // for deleted entries or not.
81 // |start_changestamp| specifies the starting point of change list or 0 if
82 // all changes are necessary.
83 GetChangelistOperation(
84 OperationRegistry* registry,
85 net::URLRequestContextGetter* url_request_context_getter,
86 const DriveApiUrlGenerator& url_generator,
87 bool include_deleted,
88 int64 start_changestamp,
89 const GetDataCallback& callback);
90 virtual ~GetChangelistOperation();
92 protected:
93 // Overridden from GetDataOperation.
94 virtual GURL GetURL() const OVERRIDE;
96 private:
97 const DriveApiUrlGenerator url_generator_;
98 const bool include_deleted_;
99 const int64 start_changestamp_;
101 DISALLOW_COPY_AND_ASSIGN(GetChangelistOperation);
104 //============================= GetFilelistOperation ===========================
106 // This class performs the operation for fetching Filelist.
107 // The result may contain only first part of the result. The remaining result
108 // should be able to be fetched by ContinueGetFileListOperation defined below.
109 class GetFilelistOperation : public GetDataOperation {
110 public:
111 GetFilelistOperation(
112 OperationRegistry* registry,
113 net::URLRequestContextGetter* url_request_context_getter,
114 const DriveApiUrlGenerator& url_generator,
115 const std::string& search_string,
116 const GetDataCallback& callback);
117 virtual ~GetFilelistOperation();
119 protected:
120 // Overridden from GetDataOperation.
121 virtual GURL GetURL() const OVERRIDE;
123 private:
124 const DriveApiUrlGenerator url_generator_;
125 std::string search_string_;
127 DISALLOW_COPY_AND_ASSIGN(GetFilelistOperation);
130 //=============================== GetFileOperation =============================
132 // This class performs the operation for fetching a file.
133 class GetFileOperation : public GetDataOperation {
134 public:
135 GetFileOperation(OperationRegistry* registry,
136 net::URLRequestContextGetter* url_request_context_getter,
137 const DriveApiUrlGenerator& url_generator,
138 const std::string& file_id,
139 const FileResourceCallback& callback);
140 virtual ~GetFileOperation();
142 protected:
143 // Overridden from GetDataOperation.
144 virtual GURL GetURL() const OVERRIDE;
146 private:
147 const DriveApiUrlGenerator url_generator_;
148 std::string file_id_;
150 DISALLOW_COPY_AND_ASSIGN(GetFileOperation);
153 // This namespace is introduced to avoid class name confliction between
154 // the operations for Drive API v2 and GData WAPI for transition.
155 // And, when the migration is done and GData WAPI's code is cleaned up,
156 // classes inside this namespace should be moved to the google_apis namespace.
157 // TODO(hidehiko): Move all the operations defined in this file into drive
158 // namespace. crbug.com/180808
159 namespace drive {
161 //======================= ContinueGetFileListOperation =========================
163 // This class performs the operation to fetch remaining Filelist result.
164 class ContinueGetFileListOperation : public GetDataOperation {
165 public:
166 ContinueGetFileListOperation(
167 OperationRegistry* registry,
168 net::URLRequestContextGetter* url_request_context_getter,
169 const GURL& url,
170 const GetDataCallback& callback);
171 virtual ~ContinueGetFileListOperation();
173 protected:
174 virtual GURL GetURL() const OVERRIDE;
176 private:
177 const GURL url_;
179 DISALLOW_COPY_AND_ASSIGN(ContinueGetFileListOperation);
182 //========================== CreateDirectoryOperation ==========================
184 // This class performs the operation for creating a directory.
185 class CreateDirectoryOperation : public GetDataOperation {
186 public:
187 CreateDirectoryOperation(
188 OperationRegistry* registry,
189 net::URLRequestContextGetter* url_request_context_getter,
190 const DriveApiUrlGenerator& url_generator,
191 const std::string& parent_resource_id,
192 const std::string& directory_name,
193 const FileResourceCallback& callback);
194 virtual ~CreateDirectoryOperation();
196 protected:
197 // Overridden from GetDataOperation.
198 virtual GURL GetURL() const OVERRIDE;
199 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
200 virtual bool GetContentData(std::string* upload_content_type,
201 std::string* upload_content) OVERRIDE;
203 private:
204 const DriveApiUrlGenerator url_generator_;
205 const std::string parent_resource_id_;
206 const std::string directory_name_;
208 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation);
211 //=========================== RenameResourceOperation ==========================
213 // This class performs the operation for renaming a document/file/directory.
214 class RenameResourceOperation : public EntryActionOperation {
215 public:
216 // |callback| must not be null.
217 RenameResourceOperation(
218 OperationRegistry* registry,
219 net::URLRequestContextGetter* url_request_context_getter,
220 const DriveApiUrlGenerator& url_generator,
221 const std::string& resource_id,
222 const std::string& new_name,
223 const EntryActionCallback& callback);
224 virtual ~RenameResourceOperation();
226 protected:
227 // UrlFetchOperationBase overrides.
228 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
229 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
230 virtual GURL GetURL() const OVERRIDE;
231 virtual bool GetContentData(std::string* upload_content_type,
232 std::string* upload_content) OVERRIDE;
234 private:
235 const DriveApiUrlGenerator url_generator_;
237 const std::string resource_id_;
238 const std::string new_name_;
240 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation);
243 //=========================== CopyResourceOperation ============================
245 // This class performs the operation for copying a resource.
247 // This class is designed to copy only the hosted documents at the moment,
248 // but the operation (in server side) can work with regular files, too.
249 // TODO(hidehiko): Extend this operation to adapt copy regular files on
250 // server side (crbug.com/138273).
252 // Also, note that, at the moment, this operation copies the hosted document
253 // to the root directory. However, the operation (in server side) supports
254 // copying files into any directory on Drive API v2, while it is not supported
255 // on GData WAPI. Now, we are on the way of migration from GData WAPI to
256 // Drive API v2, so we drop the feature for now to reduce the migration
257 // complexity.
258 // TODO(hidehiko): Support the feature for the copy after the migration,
259 // which should be somehow benficial (at least we can simplify
260 // chromeos/drive/file_system/copy_operation).
261 class CopyResourceOperation : public GetDataOperation {
262 public:
263 // |resource_id| is the resource id of the file to be copied.
264 // |new_name| is the name of the copied (newly created) file.
265 // |callback| must not be null.
266 CopyResourceOperation(
267 OperationRegistry* registry,
268 net::URLRequestContextGetter* url_request_context_getter,
269 const DriveApiUrlGenerator& url_generator,
270 const std::string& resource_id,
271 const std::string& new_name,
272 const FileResourceCallback& callback);
273 virtual ~CopyResourceOperation();
275 protected:
276 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
277 virtual GURL GetURL() const OVERRIDE;
278 virtual bool GetContentData(std::string* upload_content_type,
279 std::string* upload_content) OVERRIDE;
280 private:
281 const DriveApiUrlGenerator url_generator_;
282 const std::string resource_id_;
283 const std::string new_name_;
285 DISALLOW_COPY_AND_ASSIGN(CopyResourceOperation);
288 //=========================== TrashResourceOperation ===========================
290 // This class performs the operation for trashing a resource.
292 // According to the document:
293 // https://developers.google.com/drive/v2/reference/files/trash
294 // the file resource will be returned from the server, which is not in the
295 // response from WAPI server. For the transition, we simply ignore the result,
296 // because now we do not handle resources in trash.
297 // Note for the naming: the name "trash" comes from the server's operation
298 // name. In order to be consistent with the server, we chose "trash" here,
299 // although we are preferring the term "remove" in drive/google_api code.
300 // TODO(hidehiko): Replace the base class to GetDataOperation.
301 class TrashResourceOperation : public EntryActionOperation {
302 public:
303 // |callback| must not be null.
304 TrashResourceOperation(
305 OperationRegistry* registry,
306 net::URLRequestContextGetter* url_request_context_getter,
307 const DriveApiUrlGenerator& url_generator,
308 const std::string& resource_id,
309 const EntryActionCallback& callback);
310 virtual ~TrashResourceOperation();
312 protected:
313 // UrlFetchOperationBase overrides.
314 virtual GURL GetURL() const OVERRIDE;
315 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
317 private:
318 const DriveApiUrlGenerator url_generator_;
319 const std::string resource_id_;
321 DISALLOW_COPY_AND_ASSIGN(TrashResourceOperation);
324 //========================== InsertResourceOperation ===========================
326 // This class performs the operation for inserting a resource to a directory.
327 // Note that this is the operation of "Children: insert" of the Drive API v2.
328 // https://developers.google.com/drive/v2/reference/children/insert.
329 class InsertResourceOperation : public EntryActionOperation {
330 public:
331 // |callback| must not be null.
332 InsertResourceOperation(
333 OperationRegistry* registry,
334 net::URLRequestContextGetter* url_request_context_getter,
335 const DriveApiUrlGenerator& url_generator,
336 const std::string& parent_resource_id,
337 const std::string& resource_id,
338 const EntryActionCallback& callback);
339 virtual ~InsertResourceOperation();
341 protected:
342 // UrlFetchOperationBase overrides.
343 virtual GURL GetURL() const OVERRIDE;
344 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
345 virtual bool GetContentData(std::string* upload_content_type,
346 std::string* upload_content) OVERRIDE;
348 private:
349 const DriveApiUrlGenerator url_generator_;
350 const std::string parent_resource_id_;
351 const std::string resource_id_;
353 DISALLOW_COPY_AND_ASSIGN(InsertResourceOperation);
356 //========================== DeleteResourceOperation ===========================
358 // This class performs the operation for removing a resource from a directory.
359 // Note that we use "delete" for the name of this class, which comes from the
360 // operation name of the Drive API v2, although we prefer "remove" for that
361 // sense in "drive/google_api"
362 // Also note that this is the operation of "Children: delete" of the Drive API
363 // v2. https://developers.google.com/drive/v2/reference/children/delete
364 class DeleteResourceOperation : public EntryActionOperation {
365 public:
366 // |callback| must not be null.
367 DeleteResourceOperation(
368 OperationRegistry* registry,
369 net::URLRequestContextGetter* url_request_context_getter,
370 const DriveApiUrlGenerator& url_generator,
371 const std::string& parent_resource_id,
372 const std::string& resource_id,
373 const EntryActionCallback& callback);
374 virtual ~DeleteResourceOperation();
376 protected:
377 // UrlFetchOperationBase overrides.
378 virtual GURL GetURL() const OVERRIDE;
379 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
381 private:
382 const DriveApiUrlGenerator url_generator_;
383 const std::string parent_resource_id_;
384 const std::string resource_id_;
386 DISALLOW_COPY_AND_ASSIGN(DeleteResourceOperation);
389 //======================= InitiateUploadNewFileOperation =======================
391 // This class performs the operation for initiating the upload of a new file.
392 class InitiateUploadNewFileOperation : public InitiateUploadOperationBase {
393 public:
394 // |parent_resource_id| should be the resource id of the parent directory.
395 // |title| should be set.
396 // See also the comments of InitiateUploadOperationBase for more details
397 // about the other parameters.
398 InitiateUploadNewFileOperation(
399 OperationRegistry* registry,
400 net::URLRequestContextGetter* url_request_context_getter,
401 const DriveApiUrlGenerator& url_generator,
402 const base::FilePath& drive_file_path,
403 const std::string& content_type,
404 int64 content_length,
405 const std::string& parent_resource_id,
406 const std::string& title,
407 const InitiateUploadCallback& callback);
408 virtual ~InitiateUploadNewFileOperation();
410 protected:
411 // UrlFetchOperationBase overrides.
412 virtual GURL GetURL() const OVERRIDE;
413 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
414 virtual bool GetContentData(std::string* upload_content_type,
415 std::string* upload_content) OVERRIDE;
417 private:
418 const DriveApiUrlGenerator url_generator_;
419 const std::string parent_resource_id_;
420 const std::string title_;
422 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileOperation);
425 //==================== InitiateUploadExistingFileOperation =====================
427 // This class performs the operation for initiating the upload of an existing
428 // file.
429 class InitiateUploadExistingFileOperation
430 : public InitiateUploadOperationBase {
431 public:
432 // |upload_url| should be the upload_url() of the file
433 // (resumable-create-media URL)
434 // |etag| should be set if it is available to detect the upload confliction.
435 // See also the comments of InitiateUploadOperationBase for more details
436 // about the other parameters.
437 InitiateUploadExistingFileOperation(
438 OperationRegistry* registry,
439 net::URLRequestContextGetter* url_request_context_getter,
440 const DriveApiUrlGenerator& url_generator,
441 const base::FilePath& drive_file_path,
442 const std::string& content_type,
443 int64 content_length,
444 const std::string& resource_id,
445 const std::string& etag,
446 const InitiateUploadCallback& callback);
447 virtual ~InitiateUploadExistingFileOperation();
449 protected:
450 // UrlFetchOperationBase overrides.
451 virtual GURL GetURL() const OVERRIDE;
452 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE;
453 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE;
455 private:
456 const DriveApiUrlGenerator url_generator_;
457 const std::string resource_id_;
458 const std::string etag_;
460 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileOperation);
463 // Callback used for ResumeUpload() (and will be used for GetUploadStatus()).
464 typedef base::Callback<void(
465 const UploadRangeResponse& response,
466 scoped_ptr<FileResource> new_resource)> UploadRangeCallback;
468 //============================ ResumeUploadOperation ===========================
470 // Performs the operation for resuming the upload of a file.
471 class ResumeUploadOperation : public ResumeUploadOperationBase {
472 public:
473 // See also ResumeUploadOperationBase's comment for parameters meaning.
474 // |callback| must not be null. |progress_callback| may be null.
475 ResumeUploadOperation(
476 OperationRegistry* registry,
477 net::URLRequestContextGetter* url_request_context_getter,
478 UploadMode upload_mode,
479 const base::FilePath& drive_file_path,
480 const GURL& upload_location,
481 int64 start_position,
482 int64 end_position,
483 int64 content_length,
484 const std::string& content_type,
485 const scoped_refptr<net::IOBuffer>& buf,
486 const UploadRangeCallback& callback,
487 const ProgressCallback& progress_callback);
488 virtual ~ResumeUploadOperation();
490 protected:
491 // UploadRangeOperationBase overrides.
492 virtual void OnRangeOperationComplete(
493 const UploadRangeResponse& response,
494 scoped_ptr<base::Value> value) OVERRIDE;
495 // content::UrlFetcherDelegate overrides.
496 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
497 int64 current, int64 total) OVERRIDE;
499 private:
500 const UploadRangeCallback callback_;
501 const ProgressCallback progress_callback_;
503 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation);
506 } // namespace drive
507 } // namespace google_apis
509 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_