Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / drive / service / drive_service_interface.h
blob31b90dfa9dd8e4d27d5d0f25e8b208f099ce2188
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 COMPONENTS_DRIVE_SERVICE_DRIVE_SERVICE_INTERFACE_H_
6 #define COMPONENTS_DRIVE_SERVICE_DRIVE_SERVICE_INTERFACE_H_
8 #include <string>
10 #include "base/time/time.h"
11 #include "google_apis/drive/auth_service_interface.h"
12 #include "google_apis/drive/base_requests.h"
13 #include "google_apis/drive/drive_api_requests.h"
14 #include "google_apis/drive/drive_common_callbacks.h"
16 namespace base {
17 class Time;
20 namespace drive {
22 // Observer interface for DriveServiceInterface.
23 class DriveServiceObserver {
24 public:
25 // Triggered when the service gets ready to send requests.
26 virtual void OnReadyToSendRequests() {}
28 // Called when the refresh token was found to be invalid.
29 virtual void OnRefreshTokenInvalid() {}
31 protected:
32 virtual ~DriveServiceObserver() {}
35 // Optional parameters for AddNewDirectory().
36 struct AddNewDirectoryOptions {
37 AddNewDirectoryOptions();
38 ~AddNewDirectoryOptions();
40 // visibility of the new directory.
41 google_apis::drive::FileVisibility visibility;
43 // modified_date of the directory.
44 // Pass the null Time if you are not interested in setting this property.
45 base::Time modified_date;
47 // last_viewed_by_me_date of the directory.
48 // Pass the null Time if you are not interested in setting this property.
49 base::Time last_viewed_by_me_date;
51 // List of properties for a new directory.
52 google_apis::drive::Properties properties;
55 // Optional parameters for InitiateUploadNewFile() and
56 // MultipartUploadNewFile().
57 struct UploadNewFileOptions {
58 UploadNewFileOptions();
59 ~UploadNewFileOptions();
61 // modified_date of the file.
62 // Pass the null Time if you are not interested in setting this property.
63 base::Time modified_date;
65 // last_viewed_by_me_date of the file.
66 // Pass the null Time if you are not interested in setting this property.
67 base::Time last_viewed_by_me_date;
69 // List of properties for a new file.
70 google_apis::drive::Properties properties;
73 // Optional parameters for InitiateUploadExistingFile() and
74 // MultipartUploadExistingFile().
75 struct UploadExistingFileOptions {
76 UploadExistingFileOptions();
77 ~UploadExistingFileOptions();
79 // Expected ETag of the file. UPLOAD_ERROR_CONFLICT error is generated when
80 // matching fails.
81 // Pass the empty string to disable this behavior.
82 std::string etag;
84 // New parent of the file.
85 // Pass the empty string to keep the property unchanged.
86 std::string parent_resource_id;
88 // New title of the file.
89 // Pass the empty string to keep the property unchanged.
90 std::string title;
92 // New modified_date of the file.
93 // Pass the null Time if you are not interested in setting this property.
94 base::Time modified_date;
96 // New last_viewed_by_me_date of the file.
97 // Pass the null Time if you are not interested in setting this property.
98 base::Time last_viewed_by_me_date;
100 // List of new properties for an existing file (it will be merged with
101 // existing properties).
102 google_apis::drive::Properties properties;
105 // Interface where we define operations that can be sent in batch requests.
106 class DriveServiceBatchOperationsInterface {
107 public:
108 virtual ~DriveServiceBatchOperationsInterface() {}
110 // Uploads a file by a single request with multipart body. It's more efficient
111 // for small files than using |InitiateUploadNewFile| and |ResumeUpload|.
112 // |content_type| and |content_length| should be the ones of the file to be
113 // uploaded. |callback| must not be null. |progress_callback| may be null.
114 virtual google_apis::CancelCallback MultipartUploadNewFile(
115 const std::string& content_type,
116 int64 content_length,
117 const std::string& parent_resource_id,
118 const std::string& title,
119 const base::FilePath& local_file_path,
120 const UploadNewFileOptions& options,
121 const google_apis::FileResourceCallback& callback,
122 const google_apis::ProgressCallback& progress_callback) = 0;
124 // Uploads a file by a single request with multipart body. It's more efficient
125 // for small files than using |InitiateUploadExistingFile| and |ResumeUpload|.
126 // |content_type| and |content_length| should be the ones of the file to be
127 // uploaded. |callback| must not be null. |progress_callback| may be null.
128 virtual google_apis::CancelCallback MultipartUploadExistingFile(
129 const std::string& content_type,
130 int64 content_length,
131 const std::string& resource_id,
132 const base::FilePath& local_file_path,
133 const UploadExistingFileOptions& options,
134 const google_apis::FileResourceCallback& callback,
135 const google_apis::ProgressCallback& progress_callback) = 0;
138 // Builder returned by DriveServiceInterface to build batch request.
139 class BatchRequestConfiguratorInterface
140 : public DriveServiceBatchOperationsInterface {
141 public:
142 ~BatchRequestConfiguratorInterface() override {}
144 // Commits and sends the batch request.
145 virtual void Commit() = 0;
148 // This defines an interface for sharing by DriveService and MockDriveService
149 // so that we can do testing of clients of DriveService.
151 // All functions must be called on UI thread. DriveService is built on top of
152 // URLFetcher that runs on UI thread.
153 class DriveServiceInterface : public DriveServiceBatchOperationsInterface {
154 public:
155 ~DriveServiceInterface() override {}
157 // Common service:
159 // Initializes the documents service with |account_id|.
160 virtual void Initialize(const std::string& account_id) = 0;
162 // Adds an observer.
163 virtual void AddObserver(DriveServiceObserver* observer) = 0;
165 // Removes an observer.
166 virtual void RemoveObserver(DriveServiceObserver* observer) = 0;
168 // True if ready to send requests.
169 virtual bool CanSendRequest() const = 0;
171 // Authentication service:
173 // True if OAuth2 access token is retrieved and believed to be fresh.
174 virtual bool HasAccessToken() const = 0;
176 // Gets the cached OAuth2 access token or if empty, then fetches a new one.
177 virtual void RequestAccessToken(
178 const google_apis::AuthStatusCallback& callback) = 0;
180 // True if OAuth2 refresh token is present.
181 virtual bool HasRefreshToken() const = 0;
183 // Clears OAuth2 access token.
184 virtual void ClearAccessToken() = 0;
186 // Clears OAuth2 refresh token.
187 virtual void ClearRefreshToken() = 0;
189 // Document access:
191 // Returns the resource id for the root directory.
192 virtual std::string GetRootResourceId() const = 0;
194 // Fetches a file list of the account. |callback| will be called upon
195 // completion.
196 // If the list is too long, it may be paged. In such a case, a URL to fetch
197 // remaining results will be included in the returned result. See also
198 // GetRemainingFileList.
200 // |callback| must not be null.
201 virtual google_apis::CancelCallback GetAllFileList(
202 const google_apis::FileListCallback& callback) = 0;
204 // Fetches a file list in the directory with |directory_resource_id|.
205 // |callback| will be called upon completion.
206 // If the list is too long, it may be paged. In such a case, a URL to fetch
207 // remaining results will be included in the returned result. See also
208 // GetRemainingFileList.
210 // |directory_resource_id| must not be empty.
211 // |callback| must not be null.
212 virtual google_apis::CancelCallback GetFileListInDirectory(
213 const std::string& directory_resource_id,
214 const google_apis::FileListCallback& callback) = 0;
216 // Searches the resources for the |search_query| from all the user's
217 // resources. |callback| will be called upon completion.
218 // If the list is too long, it may be paged. In such a case, a URL to fetch
219 // remaining results will be included in the returned result. See also
220 // GetRemainingFileList.
222 // |search_query| must not be empty.
223 // |callback| must not be null.
224 virtual google_apis::CancelCallback Search(
225 const std::string& search_query,
226 const google_apis::FileListCallback& callback) = 0;
228 // Searches the resources with the |title|.
229 // |directory_resource_id| is an optional parameter. If it is empty,
230 // the search target is all the existing resources. Otherwise, it is
231 // the resources directly under the directory with |directory_resource_id|.
232 // If the list is too long, it may be paged. In such a case, a URL to fetch
233 // remaining results will be included in the returned result. See also
234 // GetRemainingFileList.
236 // |title| must not be empty, and |callback| must not be null.
237 virtual google_apis::CancelCallback SearchByTitle(
238 const std::string& title,
239 const std::string& directory_resource_id,
240 const google_apis::FileListCallback& callback) = 0;
242 // Fetches change list since |start_changestamp|. |callback| will be
243 // called upon completion.
244 // If the list is too long, it may be paged. In such a case, a URL to fetch
245 // remaining results will be included in the returned result. See also
246 // GetRemainingChangeList.
248 // |callback| must not be null.
249 virtual google_apis::CancelCallback GetChangeList(
250 int64 start_changestamp,
251 const google_apis::ChangeListCallback& callback) = 0;
253 // The result of GetChangeList() may be paged.
254 // In such a case, a next link to fetch remaining result is returned.
255 // The page token can be used for this method. |callback| will be called upon
256 // completion.
258 // |next_link| must not be empty. |callback| must not be null.
259 virtual google_apis::CancelCallback GetRemainingChangeList(
260 const GURL& next_link,
261 const google_apis::ChangeListCallback& callback) = 0;
263 // The result of GetAllFileList(), GetFileListInDirectory(), Search()
264 // and SearchByTitle() may be paged. In such a case, a next link to fetch
265 // remaining result is returned. The page token can be used for this method.
266 // |callback| will be called upon completion.
268 // |next_link| must not be empty. |callback| must not be null.
269 virtual google_apis::CancelCallback GetRemainingFileList(
270 const GURL& next_link,
271 const google_apis::FileListCallback& callback) = 0;
273 // Fetches single entry metadata from server. The entry's file id equals
274 // |resource_id|.
275 // Upon completion, invokes |callback| with results on the calling thread.
276 // |callback| must not be null.
277 virtual google_apis::CancelCallback GetFileResource(
278 const std::string& resource_id,
279 const google_apis::FileResourceCallback& callback) = 0;
281 // Fetches an url for the sharing dialog for a single entry with id
282 // |resource_id|, to be embedded in a webview or an iframe with origin
283 // |embed_origin|. The url is returned via |callback| with results on the
284 // calling thread. |callback| must not be null.
285 virtual google_apis::CancelCallback GetShareUrl(
286 const std::string& resource_id,
287 const GURL& embed_origin,
288 const google_apis::GetShareUrlCallback& callback) = 0;
290 // Gets the about resource information from the server.
291 // Upon completion, invokes |callback| with results on the calling thread.
292 // |callback| must not be null.
293 virtual google_apis::CancelCallback GetAboutResource(
294 const google_apis::AboutResourceCallback& callback) = 0;
296 // Gets the application information from the server.
297 // Upon completion, invokes |callback| with results on the calling thread.
298 // |callback| must not be null.
299 virtual google_apis::CancelCallback GetAppList(
300 const google_apis::AppListCallback& callback) = 0;
302 // Permanently deletes a resource identified by its |resource_id|.
303 // If |etag| is not empty and did not match, the deletion fails with
304 // HTTP_PRECONDITION error.
305 // Upon completion, invokes |callback| with results on the calling thread.
306 // |callback| must not be null.
307 virtual google_apis::CancelCallback DeleteResource(
308 const std::string& resource_id,
309 const std::string& etag,
310 const google_apis::EntryActionCallback& callback) = 0;
312 // Trashes a resource identified by its |resource_id|.
313 // Upon completion, invokes |callback| with results on the calling thread.
314 // |callback| must not be null.
315 virtual google_apis::CancelCallback TrashResource(
316 const std::string& resource_id,
317 const google_apis::EntryActionCallback& callback) = 0;
319 // Makes a copy of a resource with |resource_id|.
320 // The new resource will be put under a directory with |parent_resource_id|,
321 // and it'll be named |new_title|.
322 // If |last_modified| is not null, the modified date of the resource on the
323 // server will be set to the date.
324 // Upon completion, invokes |callback| with results on the calling thread.
325 // |callback| must not be null.
326 virtual google_apis::CancelCallback CopyResource(
327 const std::string& resource_id,
328 const std::string& parent_resource_id,
329 const std::string& new_title,
330 const base::Time& last_modified,
331 const google_apis::FileResourceCallback& callback) = 0;
333 // Updates a resource with |resource_id| to the directory of
334 // |parent_resource_id| with renaming to |new_title|.
335 // If |last_modified| or |last_accessed| is not null, the modified/accessed
336 // date of the resource on the server will be set to the date.
337 // If |properties| are specified, then they will be set on |resource_id|.
338 // Upon completion, invokes |callback| with results on the calling thread.
339 // |callback| must not be null.
340 virtual google_apis::CancelCallback UpdateResource(
341 const std::string& resource_id,
342 const std::string& parent_resource_id,
343 const std::string& new_title,
344 const base::Time& last_modified,
345 const base::Time& last_viewed_by_me,
346 const google_apis::drive::Properties& properties,
347 const google_apis::FileResourceCallback& callback) = 0;
349 // Adds a resource (document, file, or collection) identified by its
350 // |resource_id| to a collection represented by the |parent_resource_id|.
351 // Upon completion, invokes |callback| with results on the calling thread.
352 // |callback| must not be null.
353 virtual google_apis::CancelCallback AddResourceToDirectory(
354 const std::string& parent_resource_id,
355 const std::string& resource_id,
356 const google_apis::EntryActionCallback& callback) = 0;
358 // Removes a resource (document, file, collection) identified by its
359 // |resource_id| from a collection represented by the |parent_resource_id|.
360 // Upon completion, invokes |callback| with results on the calling thread.
361 // |callback| must not be null.
362 virtual google_apis::CancelCallback RemoveResourceFromDirectory(
363 const std::string& parent_resource_id,
364 const std::string& resource_id,
365 const google_apis::EntryActionCallback& callback) = 0;
367 // Adds new collection with |directory_title| under parent directory
368 // identified with |parent_resource_id|. |parent_resource_id| can be the
369 // value returned by GetRootResourceId to represent the root directory.
370 // Upon completion, invokes |callback| and passes newly created entry on
371 // the calling thread.
372 // This function cannot be named as "CreateDirectory" as it conflicts with
373 // a macro on Windows.
374 // |callback| must not be null.
375 virtual google_apis::CancelCallback AddNewDirectory(
376 const std::string& parent_resource_id,
377 const std::string& directory_title,
378 const AddNewDirectoryOptions& options,
379 const google_apis::FileResourceCallback& callback) = 0;
381 // Downloads a file with |resourced_id|. The downloaded file will
382 // be stored at |local_cache_path| location. Upon completion, invokes
383 // |download_action_callback| with results on the calling thread.
384 // If |get_content_callback| is not empty,
385 // URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in
386 // turn invoke |get_content_callback| on the calling thread.
387 // If |progress_callback| is not empty, it is invoked periodically when
388 // the download made some progress.
390 // |download_action_callback| must not be null.
391 // |get_content_callback| and |progress_callback| may be null.
392 virtual google_apis::CancelCallback DownloadFile(
393 const base::FilePath& local_cache_path,
394 const std::string& resource_id,
395 const google_apis::DownloadActionCallback& download_action_callback,
396 const google_apis::GetContentCallback& get_content_callback,
397 const google_apis::ProgressCallback& progress_callback) = 0;
399 // Initiates uploading of a new document/file.
400 // |content_type| and |content_length| should be the ones of the file to be
401 // uploaded.
402 // |callback| must not be null.
403 virtual google_apis::CancelCallback InitiateUploadNewFile(
404 const std::string& content_type,
405 int64 content_length,
406 const std::string& parent_resource_id,
407 const std::string& title,
408 const UploadNewFileOptions& options,
409 const google_apis::InitiateUploadCallback& callback) = 0;
411 // Initiates uploading of an existing document/file.
412 // |content_type| and |content_length| should be the ones of the file to be
413 // uploaded.
414 // |callback| must not be null.
415 virtual google_apis::CancelCallback InitiateUploadExistingFile(
416 const std::string& content_type,
417 int64 content_length,
418 const std::string& resource_id,
419 const UploadExistingFileOptions& options,
420 const google_apis::InitiateUploadCallback& callback) = 0;
422 // Resumes uploading of a document/file on the calling thread.
423 // |callback| must not be null. |progress_callback| may be null.
424 virtual google_apis::CancelCallback ResumeUpload(
425 const GURL& upload_url,
426 int64 start_position,
427 int64 end_position,
428 int64 content_length,
429 const std::string& content_type,
430 const base::FilePath& local_file_path,
431 const google_apis::drive::UploadRangeCallback& callback,
432 const google_apis::ProgressCallback& progress_callback) = 0;
434 // Gets the current status of the uploading to |upload_url| from the server.
435 // |drive_file_path| and |content_length| should be set to the same value
436 // which is used for ResumeUpload.
437 // |callback| must not be null.
438 virtual google_apis::CancelCallback GetUploadStatus(
439 const GURL& upload_url,
440 int64 content_length,
441 const google_apis::drive::UploadRangeCallback& callback) = 0;
443 // Authorizes a Drive app with the id |app_id| to open the given file.
444 // Upon completion, invokes |callback| with the link to open the file with
445 // the provided app. |callback| must not be null.
446 virtual google_apis::CancelCallback AuthorizeApp(
447 const std::string& resource_id,
448 const std::string& app_id,
449 const google_apis::AuthorizeAppCallback& callback) = 0;
451 // Uninstalls a Drive app with the id |app_id|. |callback| must not be null.
452 virtual google_apis::CancelCallback UninstallApp(
453 const std::string& app_id,
454 const google_apis::EntryActionCallback& callback) = 0;
456 // Authorizes the account |email| to access |resource_id| as a |role|.
457 // |callback| must not be null.
458 virtual google_apis::CancelCallback AddPermission(
459 const std::string& resource_id,
460 const std::string& email,
461 google_apis::drive::PermissionRole role,
462 const google_apis::EntryActionCallback& callback) = 0;
464 // Starts batch request and returns |BatchRequestConfigurator|.
465 virtual scoped_ptr<BatchRequestConfiguratorInterface> StartBatchRequest() = 0;
468 } // namespace drive
470 #endif // COMPONENTS_DRIVE_SERVICE_DRIVE_SERVICE_INTERFACE_H_