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_GDATA_WAPI_OPERATIONS_H_
6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_
11 #include "chrome/browser/google_apis/base_operations.h"
12 #include "chrome/browser/google_apis/drive_service_interface.h"
13 #include "chrome/browser/google_apis/drive_upload_mode.h"
14 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
15 #include "net/base/io_buffer.h"
18 class URLRequestContextGetter
;
21 namespace google_apis
{
23 class GDataWapiUrlGenerator
;
26 //============================ GetResourceListOperation ========================
28 // This class performs the operation for fetching a resource list.
29 class GetResourceListOperation
: public GetDataOperation
{
32 // If empty, a hard-coded base URL of the WAPI server is used to fetch
33 // the first page of the feed. This parameter is used for fetching 2nd
37 // This parameter specifies the starting point of a delta feed or 0 if a
38 // full feed is necessary.
41 // If non-empty, fetches a list of resources that match the search
44 // directory_resource_id:
45 // If non-empty, fetches a list of resources in a particular directory.
48 // Called once the feed is fetched. Must not be null.
49 GetResourceListOperation(
50 OperationRegistry
* registry
,
51 net::URLRequestContextGetter
* url_request_context_getter
,
52 const GDataWapiUrlGenerator
& url_generator
,
53 const GURL
& override_url
,
54 int start_changestamp
,
55 const std::string
& search_string
,
56 const std::string
& directory_resource_id
,
57 const GetResourceListCallback
& callback
);
58 virtual ~GetResourceListOperation();
61 // UrlFetchOperationBase overrides.
62 virtual GURL
GetURL() const OVERRIDE
;
65 const GDataWapiUrlGenerator url_generator_
;
66 const GURL override_url_
;
67 const int start_changestamp_
;
68 const std::string search_string_
;
69 const std::string directory_resource_id_
;
71 DISALLOW_COPY_AND_ASSIGN(GetResourceListOperation
);
74 //========================= GetResourceEntryOperation ==========================
76 // This class performs the operation for fetching a single resource entry.
77 class GetResourceEntryOperation
: public GetDataOperation
{
79 // |callback| must not be null.
80 GetResourceEntryOperation(
81 OperationRegistry
* registry
,
82 net::URLRequestContextGetter
* url_request_context_getter
,
83 const GDataWapiUrlGenerator
& url_generator
,
84 const std::string
& resource_id
,
85 const GetDataCallback
& callback
);
86 virtual ~GetResourceEntryOperation();
89 // UrlFetchOperationBase overrides.
90 virtual GURL
GetURL() const OVERRIDE
;
93 const GDataWapiUrlGenerator url_generator_
;
94 // Resource id of the requested entry.
95 const std::string resource_id_
;
97 DISALLOW_COPY_AND_ASSIGN(GetResourceEntryOperation
);
100 //========================= GetAccountMetadataOperation ========================
102 // This class performs the operation for fetching account metadata.
103 class GetAccountMetadataOperation
: public GetDataOperation
{
105 // If |include_installed_apps| is set to true, the result should include
106 // the list of installed third party applications.
107 // |callback| must not be null.
108 GetAccountMetadataOperation(
109 OperationRegistry
* registry
,
110 net::URLRequestContextGetter
* url_request_context_getter
,
111 const GDataWapiUrlGenerator
& url_generator
,
112 const GetAccountMetadataCallback
& callback
,
113 bool include_installed_apps
);
114 virtual ~GetAccountMetadataOperation();
117 // UrlFetchOperationBase overrides.
118 virtual GURL
GetURL() const OVERRIDE
;
121 const GDataWapiUrlGenerator url_generator_
;
122 const bool include_installed_apps_
;
124 DISALLOW_COPY_AND_ASSIGN(GetAccountMetadataOperation
);
127 //=========================== DeleteResourceOperation ==========================
129 // This class performs the operation for deleting a resource.
131 // In WAPI, "gd:deleted" means that the resource was put in the trash, and
132 // "docs:removed" means its permanently gone. Since what the class does is to
133 // put the resource into trash, we have chosen "Delete" in the name, even though
134 // we are preferring the term "Remove" in drive/google_api code.
135 class DeleteResourceOperation
: public EntryActionOperation
{
137 // |callback| must not be null.
138 DeleteResourceOperation(
139 OperationRegistry
* registry
,
140 net::URLRequestContextGetter
* url_request_context_getter
,
141 const GDataWapiUrlGenerator
& url_generator
,
142 const EntryActionCallback
& callback
,
143 const std::string
& resource_id
,
144 const std::string
& etag
);
145 virtual ~DeleteResourceOperation();
148 // UrlFetchOperationBase overrides.
149 virtual GURL
GetURL() const OVERRIDE
;
150 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
151 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
154 const GDataWapiUrlGenerator url_generator_
;
155 const std::string resource_id_
;
156 const std::string etag_
;
158 DISALLOW_COPY_AND_ASSIGN(DeleteResourceOperation
);
161 //========================== CreateDirectoryOperation ==========================
163 // This class performs the operation for creating a directory.
164 class CreateDirectoryOperation
: public GetDataOperation
{
166 // A new directory will be created under a directory specified by
167 // |parent_resource_id|. If this parameter is empty, a new directory will
168 // be created in the root directory.
169 // |callback| must not be null.
170 CreateDirectoryOperation(
171 OperationRegistry
* registry
,
172 net::URLRequestContextGetter
* url_request_context_getter
,
173 const GDataWapiUrlGenerator
& url_generator
,
174 const GetDataCallback
& callback
,
175 const std::string
& parent_resource_id
,
176 const std::string
& directory_name
);
177 virtual ~CreateDirectoryOperation();
180 // UrlFetchOperationBase overrides.
181 virtual GURL
GetURL() const OVERRIDE
;
182 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
183 virtual bool GetContentData(std::string
* upload_content_type
,
184 std::string
* upload_content
) OVERRIDE
;
187 const GDataWapiUrlGenerator url_generator_
;
188 const std::string parent_resource_id_
;
189 const std::string directory_name_
;
191 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation
);
194 //============================ CopyHostedDocumentOperation =====================
196 // This class performs the operation for making a copy of a hosted document.
197 // Note that this function cannot be used to copy regular files, as it's not
198 // supported by WAPI.
199 class CopyHostedDocumentOperation
: public GetDataOperation
{
201 // |callback| must not be null.
202 CopyHostedDocumentOperation(
203 OperationRegistry
* registry
,
204 net::URLRequestContextGetter
* url_request_context_getter
,
205 const GDataWapiUrlGenerator
& url_generator
,
206 const GetDataCallback
& callback
,
207 const std::string
& resource_id
,
208 const std::string
& new_name
);
209 virtual ~CopyHostedDocumentOperation();
212 // UrlFetchOperationBase overrides.
213 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
214 virtual GURL
GetURL() const OVERRIDE
;
215 virtual bool GetContentData(std::string
* upload_content_type
,
216 std::string
* upload_content
) OVERRIDE
;
219 const GDataWapiUrlGenerator url_generator_
;
220 const std::string resource_id_
;
221 const std::string new_name_
;
223 DISALLOW_COPY_AND_ASSIGN(CopyHostedDocumentOperation
);
226 //=========================== RenameResourceOperation ==========================
228 // This class performs the operation for renaming a document/file/directory.
229 class RenameResourceOperation
: public EntryActionOperation
{
231 // |callback| must not be null.
232 RenameResourceOperation(
233 OperationRegistry
* registry
,
234 net::URLRequestContextGetter
* url_request_context_getter
,
235 const GDataWapiUrlGenerator
& url_generator
,
236 const EntryActionCallback
& callback
,
237 const std::string
& resource_id
,
238 const std::string
& new_name
);
239 virtual ~RenameResourceOperation();
242 // UrlFetchOperationBase overrides.
243 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
244 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
245 virtual GURL
GetURL() const OVERRIDE
;
246 virtual bool GetContentData(std::string
* upload_content_type
,
247 std::string
* upload_content
) OVERRIDE
;
250 const GDataWapiUrlGenerator url_generator_
;
251 const std::string resource_id_
;
252 const std::string new_name_
;
254 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation
);
257 //=========================== AuthorizeAppOperation ==========================
259 // This class performs the operation for authorizing an application specified
260 // by |app_id| to access a document specified by |resource_id|.
261 class AuthorizeAppOperation
: public GetDataOperation
{
263 // |callback| must not be null.
264 AuthorizeAppOperation(
265 OperationRegistry
* registry
,
266 net::URLRequestContextGetter
* url_request_context_getter
,
267 const GDataWapiUrlGenerator
& url_generator
,
268 const AuthorizeAppCallback
& callback
,
269 const std::string
& resource_id
,
270 const std::string
& app_id
);
271 virtual ~AuthorizeAppOperation();
274 // UrlFetchOperationBase overrides.
275 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
276 virtual bool GetContentData(std::string
* upload_content_type
,
277 std::string
* upload_content
) OVERRIDE
;
278 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
279 virtual GURL
GetURL() const OVERRIDE
;
282 const GDataWapiUrlGenerator url_generator_
;
283 const std::string resource_id_
;
284 const std::string app_id_
;
286 DISALLOW_COPY_AND_ASSIGN(AuthorizeAppOperation
);
289 //======================= AddResourceToDirectoryOperation ======================
291 // This class performs the operation for adding a document/file/directory
293 class AddResourceToDirectoryOperation
: public EntryActionOperation
{
295 // |callback| must not be null.
296 AddResourceToDirectoryOperation(
297 OperationRegistry
* registry
,
298 net::URLRequestContextGetter
* url_request_context_getter
,
299 const GDataWapiUrlGenerator
& url_generator
,
300 const EntryActionCallback
& callback
,
301 const std::string
& parent_resource_id
,
302 const std::string
& resource_id
);
303 virtual ~AddResourceToDirectoryOperation();
306 // UrlFetchOperationBase overrides.
307 virtual GURL
GetURL() const OVERRIDE
;
308 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
309 virtual bool GetContentData(std::string
* upload_content_type
,
310 std::string
* upload_content
) OVERRIDE
;
313 const GDataWapiUrlGenerator url_generator_
;
314 const std::string parent_resource_id_
;
315 const std::string resource_id_
;
317 DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryOperation
);
320 //==================== RemoveResourceFromDirectoryOperation ====================
322 // This class performs the operation for removing a document/file/directory
324 class RemoveResourceFromDirectoryOperation
: public EntryActionOperation
{
326 // |callback| must not be null.
327 RemoveResourceFromDirectoryOperation(
328 OperationRegistry
* registry
,
329 net::URLRequestContextGetter
* url_request_context_getter
,
330 const GDataWapiUrlGenerator
& url_generator
,
331 const EntryActionCallback
& callback
,
332 const std::string
& parent_resource_id
,
333 const std::string
& resource_id
);
334 virtual ~RemoveResourceFromDirectoryOperation();
337 // UrlFetchOperationBase overrides.
338 virtual GURL
GetURL() const OVERRIDE
;
339 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
340 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
343 const GDataWapiUrlGenerator url_generator_
;
344 const std::string resource_id_
;
345 const std::string parent_resource_id_
;
347 DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryOperation
);
350 //======================= InitiateUploadNewFileOperation =======================
352 // This class performs the operation for initiating the upload of a new file.
353 class InitiateUploadNewFileOperation
: public InitiateUploadOperationBase
{
355 // |title| should be set.
356 // |parent_upload_url| should be the upload_url() of the parent directory.
357 // (resumable-create-media URL)
358 // See also the comments of InitiateUploadOperationBase for more details
359 // about the other parameters.
360 InitiateUploadNewFileOperation(
361 OperationRegistry
* registry
,
362 net::URLRequestContextGetter
* url_request_context_getter
,
363 const GDataWapiUrlGenerator
& url_generator
,
364 const InitiateUploadCallback
& callback
,
365 const base::FilePath
& drive_file_path
,
366 const std::string
& content_type
,
367 int64 content_length
,
368 const std::string
& parent_resource_id
,
369 const std::string
& title
);
370 virtual ~InitiateUploadNewFileOperation();
373 // UrlFetchOperationBase overrides.
374 virtual GURL
GetURL() const OVERRIDE
;
375 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
376 virtual bool GetContentData(std::string
* upload_content_type
,
377 std::string
* upload_content
) OVERRIDE
;
380 const GDataWapiUrlGenerator url_generator_
;
381 const std::string parent_resource_id_
;
382 const std::string title_
;
384 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileOperation
);
387 //==================== InitiateUploadExistingFileOperation =====================
389 // This class performs the operation for initiating the upload of an existing
391 class InitiateUploadExistingFileOperation
392 : public InitiateUploadOperationBase
{
394 // |upload_url| should be the upload_url() of the file
395 // (resumable-create-media URL)
396 // |etag| should be set if it is available to detect the upload confliction.
397 // See also the comments of InitiateUploadOperationBase for more details
398 // about the other parameters.
399 InitiateUploadExistingFileOperation(
400 OperationRegistry
* registry
,
401 net::URLRequestContextGetter
* url_request_context_getter
,
402 const GDataWapiUrlGenerator
& url_generator
,
403 const InitiateUploadCallback
& callback
,
404 const base::FilePath
& drive_file_path
,
405 const std::string
& content_type
,
406 int64 content_length
,
407 const std::string
& resource_id
,
408 const std::string
& etag
);
409 virtual ~InitiateUploadExistingFileOperation();
412 // UrlFetchOperationBase overrides.
413 virtual GURL
GetURL() const OVERRIDE
;
414 virtual net::URLFetcher::RequestType
GetRequestType() const OVERRIDE
;
415 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
416 virtual bool GetContentData(std::string
* upload_content_type
,
417 std::string
* upload_content
) OVERRIDE
;
420 const GDataWapiUrlGenerator url_generator_
;
421 const std::string resource_id_
;
422 const std::string etag_
;
424 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileOperation
);
427 //============================ ResumeUploadOperation ===========================
429 // Performs the operation for resuming the upload of a file.
430 class ResumeUploadOperation
: public ResumeUploadOperationBase
{
432 // See also ResumeUploadOperationBase's comment for parameters meaining.
433 // |callback| must not be null.
434 ResumeUploadOperation(
435 OperationRegistry
* registry
,
436 net::URLRequestContextGetter
* url_request_context_getter
,
437 const UploadRangeCallback
& callback
,
438 const ProgressCallback
& progress_callback
,
439 UploadMode upload_mode
,
440 const base::FilePath
& drive_file_path
,
441 const GURL
& upload_location
,
442 int64 start_position
,
444 int64 content_length
,
445 const std::string
& content_type
,
446 const scoped_refptr
<net::IOBuffer
>& buf
);
447 virtual ~ResumeUploadOperation();
450 // UploadRangeOperationBase overrides.
451 virtual void OnRangeOperationComplete(
452 const UploadRangeResponse
& response
,
453 scoped_ptr
<base::Value
> value
) OVERRIDE
;
454 // content::UrlFetcherDelegate overrides.
455 virtual void OnURLFetchUploadProgress(const net::URLFetcher
* source
,
456 int64 current
, int64 total
) OVERRIDE
;
459 const UploadRangeCallback callback_
;
460 const ProgressCallback progress_callback_
;
462 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation
);
465 //========================== GetUploadStatusOperation ==========================
467 // This class performs the operation for getting the current upload status
469 // This operation calls |callback| with:
470 // - HTTP_RESUME_INCOMPLETE and the range of previously uploaded data,
471 // if a file has been partially uploaded. |new_entry| of the |callback| is
473 // - HTTP_SUCCESS or HTTP_CREATED (up to the upload mode) and |new_entry|
474 // for the uploaded data, if a file has been completely uploaded.
475 // |range| of the |callback| is not used.
476 // See also UploadRangeOperationBase.
477 class GetUploadStatusOperation
: public UploadRangeOperationBase
{
479 // |callback| must not be null. See also UploadRangeOperationBase's
480 // constructor for more details.
481 // |content_length| is the whole data size to be uploaded.
482 GetUploadStatusOperation(
483 OperationRegistry
* registry
,
484 net::URLRequestContextGetter
* url_request_context_getter
,
485 const UploadRangeCallback
& callback
,
486 UploadMode upload_mode
,
487 const base::FilePath
& drive_file_path
,
488 const GURL
& upload_url
,
489 int64 content_length
);
490 virtual ~GetUploadStatusOperation();
493 // UrlFetchOperationBase overrides.
494 virtual std::vector
<std::string
> GetExtraRequestHeaders() const OVERRIDE
;
496 // UploadRangeOperationBase overrides.
497 virtual void OnRangeOperationComplete(
498 const UploadRangeResponse
& response
,
499 scoped_ptr
<base::Value
> value
) OVERRIDE
;
502 const UploadRangeCallback callback_
;
503 const int64 content_length_
;
505 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusOperation
);
508 } // namespace google_apis
510 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_