Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / drive / drive_service_interface.h
blob7ef0151f5c247e00eecad68c09a745a2dac5a992
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_DRIVE_DRIVE_SERVICE_INTERFACE_H_
6 #define CHROME_BROWSER_DRIVE_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 // This defines an interface for sharing by DriveService and MockDriveService
36 // so that we can do testing of clients of DriveService.
38 // All functions must be called on UI thread. DriveService is built on top of
39 // URLFetcher that runs on UI thread.
40 class DriveServiceInterface {
41 public:
42 // Optional parameters for AddNewDirectory().
43 struct AddNewDirectoryOptions {
44 AddNewDirectoryOptions();
45 ~AddNewDirectoryOptions();
47 // modified_date of the directory.
48 // Pass the null Time if you are not interested in setting this property.
49 base::Time modified_date;
51 // last_viewed_by_me_date of the directory.
52 // Pass the null Time if you are not interested in setting this property.
53 base::Time last_viewed_by_me_date;
56 // Optional parameters for InitiateUploadNewFile().
57 struct InitiateUploadNewFileOptions {
58 InitiateUploadNewFileOptions();
59 ~InitiateUploadNewFileOptions();
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;
70 // Optional parameters for InitiateUploadExistingFile().
71 struct InitiateUploadExistingFileOptions {
72 InitiateUploadExistingFileOptions();
73 ~InitiateUploadExistingFileOptions();
75 // Expected ETag of the file. UPLOAD_ERROR_CONFLICT error is generated when
76 // matching fails.
77 // Pass the empty string to disable this behavior.
78 std::string etag;
80 // New parent of the file.
81 // Pass the empty string to keep the property unchanged.
82 std::string parent_resource_id;
84 // New title of the file.
85 // Pass the empty string to keep the property unchanged.
86 std::string title;
88 // New modified_date of the file.
89 // Pass the null Time if you are not interested in setting this property.
90 base::Time modified_date;
92 // New last_viewed_by_me_date of the file.
93 // Pass the null Time if you are not interested in setting this property.
94 base::Time last_viewed_by_me_date;
97 virtual ~DriveServiceInterface() {}
99 // Common service:
101 // Initializes the documents service with |account_id|.
102 virtual void Initialize(const std::string& account_id) = 0;
104 // Adds an observer.
105 virtual void AddObserver(DriveServiceObserver* observer) = 0;
107 // Removes an observer.
108 virtual void RemoveObserver(DriveServiceObserver* observer) = 0;
110 // True if ready to send requests.
111 virtual bool CanSendRequest() const = 0;
113 // Authentication service:
115 // True if OAuth2 access token is retrieved and believed to be fresh.
116 virtual bool HasAccessToken() const = 0;
118 // Gets the cached OAuth2 access token or if empty, then fetches a new one.
119 virtual void RequestAccessToken(
120 const google_apis::AuthStatusCallback& callback) = 0;
122 // True if OAuth2 refresh token is present.
123 virtual bool HasRefreshToken() const = 0;
125 // Clears OAuth2 access token.
126 virtual void ClearAccessToken() = 0;
128 // Clears OAuth2 refresh token.
129 virtual void ClearRefreshToken() = 0;
131 // Document access:
133 // Returns the resource id for the root directory.
134 virtual std::string GetRootResourceId() const = 0;
136 // Fetches a file list of the account. |callback| will be called upon
137 // completion.
138 // If the list is too long, it may be paged. In such a case, a URL to fetch
139 // remaining results will be included in the returned result. See also
140 // GetRemainingFileList.
142 // |callback| must not be null.
143 virtual google_apis::CancelCallback GetAllFileList(
144 const google_apis::FileListCallback& callback) = 0;
146 // Fetches a file list in the directory with |directory_resource_id|.
147 // |callback| will be called upon completion.
148 // If the list is too long, it may be paged. In such a case, a URL to fetch
149 // remaining results will be included in the returned result. See also
150 // GetRemainingFileList.
152 // |directory_resource_id| must not be empty.
153 // |callback| must not be null.
154 virtual google_apis::CancelCallback GetFileListInDirectory(
155 const std::string& directory_resource_id,
156 const google_apis::FileListCallback& callback) = 0;
158 // Searches the resources for the |search_query| from all the user's
159 // resources. |callback| will be called upon completion.
160 // If the list is too long, it may be paged. In such a case, a URL to fetch
161 // remaining results will be included in the returned result. See also
162 // GetRemainingFileList.
164 // |search_query| must not be empty.
165 // |callback| must not be null.
166 virtual google_apis::CancelCallback Search(
167 const std::string& search_query,
168 const google_apis::FileListCallback& callback) = 0;
170 // Searches the resources with the |title|.
171 // |directory_resource_id| is an optional parameter. If it is empty,
172 // the search target is all the existing resources. Otherwise, it is
173 // the resources directly under the directory with |directory_resource_id|.
174 // If the list is too long, it may be paged. In such a case, a URL to fetch
175 // remaining results will be included in the returned result. See also
176 // GetRemainingFileList.
178 // |title| must not be empty, and |callback| must not be null.
179 virtual google_apis::CancelCallback SearchByTitle(
180 const std::string& title,
181 const std::string& directory_resource_id,
182 const google_apis::FileListCallback& callback) = 0;
184 // Fetches change list since |start_changestamp|. |callback| will be
185 // called upon completion.
186 // If the list is too long, it may be paged. In such a case, a URL to fetch
187 // remaining results will be included in the returned result. See also
188 // GetRemainingChangeList.
190 // |callback| must not be null.
191 virtual google_apis::CancelCallback GetChangeList(
192 int64 start_changestamp,
193 const google_apis::ChangeListCallback& callback) = 0;
195 // The result of GetChangeList() may be paged.
196 // In such a case, a next link to fetch remaining result is returned.
197 // The page token can be used for this method. |callback| will be called upon
198 // completion.
200 // |next_link| must not be empty. |callback| must not be null.
201 virtual google_apis::CancelCallback GetRemainingChangeList(
202 const GURL& next_link,
203 const google_apis::ChangeListCallback& callback) = 0;
205 // The result of GetAllFileList(), GetFileListInDirectory(), Search()
206 // and SearchByTitle() may be paged. In such a case, a next link to fetch
207 // remaining result is returned. The page token can be used for this method.
208 // |callback| will be called upon completion.
210 // |next_link| must not be empty. |callback| must not be null.
211 virtual google_apis::CancelCallback GetRemainingFileList(
212 const GURL& next_link,
213 const google_apis::FileListCallback& callback) = 0;
215 // Fetches single entry metadata from server. The entry's file id equals
216 // |resource_id|.
217 // Upon completion, invokes |callback| with results on the calling thread.
218 // |callback| must not be null.
219 virtual google_apis::CancelCallback GetFileResource(
220 const std::string& resource_id,
221 const google_apis::FileResourceCallback& callback) = 0;
223 // Fetches an url for the sharing dialog for a single entry with id
224 // |resource_id|, to be embedded in a webview or an iframe with origin
225 // |embed_origin|. The url is returned via |callback| with results on the
226 // calling thread. |callback| must not be null.
227 virtual google_apis::CancelCallback GetShareUrl(
228 const std::string& resource_id,
229 const GURL& embed_origin,
230 const google_apis::GetShareUrlCallback& callback) = 0;
232 // Gets the about resource information from the server.
233 // Upon completion, invokes |callback| with results on the calling thread.
234 // |callback| must not be null.
235 virtual google_apis::CancelCallback GetAboutResource(
236 const google_apis::AboutResourceCallback& callback) = 0;
238 // Gets the application information from the server.
239 // Upon completion, invokes |callback| with results on the calling thread.
240 // |callback| must not be null.
241 virtual google_apis::CancelCallback GetAppList(
242 const google_apis::AppListCallback& callback) = 0;
244 // Permanently deletes a resource identified by its |resource_id|.
245 // If |etag| is not empty and did not match, the deletion fails with
246 // HTTP_PRECONDITION error.
247 // Upon completion, invokes |callback| with results on the calling thread.
248 // |callback| must not be null.
249 virtual google_apis::CancelCallback DeleteResource(
250 const std::string& resource_id,
251 const std::string& etag,
252 const google_apis::EntryActionCallback& callback) = 0;
254 // Trashes a resource identified by its |resource_id|.
255 // Upon completion, invokes |callback| with results on the calling thread.
256 // |callback| must not be null.
257 virtual google_apis::CancelCallback TrashResource(
258 const std::string& resource_id,
259 const google_apis::EntryActionCallback& callback) = 0;
261 // Makes a copy of a resource with |resource_id|.
262 // The new resource will be put under a directory with |parent_resource_id|,
263 // and it'll be named |new_title|.
264 // If |last_modified| is not null, the modified date of the resource on the
265 // server will be set to the date.
266 // This request is supported only on DriveAPIService, because GData WAPI
267 // doesn't support the function unfortunately.
268 // Upon completion, invokes |callback| with results on the calling thread.
269 // |callback| must not be null.
270 virtual google_apis::CancelCallback CopyResource(
271 const std::string& resource_id,
272 const std::string& parent_resource_id,
273 const std::string& new_title,
274 const base::Time& last_modified,
275 const google_apis::FileResourceCallback& callback) = 0;
277 // Updates a resource with |resource_id| to the directory of
278 // |parent_resource_id| with renaming to |new_title|.
279 // If |last_modified| or |last_accessed| is not null, the modified/accessed
280 // date of the resource on the server will be set to the date.
281 // This request is supported only on DriveAPIService, because GData WAPI
282 // doesn't support the function unfortunately.
283 // Upon completion, invokes |callback| with results on the calling thread.
284 // |callback| must not be null.
285 virtual google_apis::CancelCallback UpdateResource(
286 const std::string& resource_id,
287 const std::string& parent_resource_id,
288 const std::string& new_title,
289 const base::Time& last_modified,
290 const base::Time& last_viewed_by_me,
291 const google_apis::FileResourceCallback& callback) = 0;
293 // Adds a resource (document, file, or collection) identified by its
294 // |resource_id| to a collection represented by the |parent_resource_id|.
295 // Upon completion, invokes |callback| with results on the calling thread.
296 // |callback| must not be null.
297 virtual google_apis::CancelCallback AddResourceToDirectory(
298 const std::string& parent_resource_id,
299 const std::string& resource_id,
300 const google_apis::EntryActionCallback& callback) = 0;
302 // Removes a resource (document, file, collection) identified by its
303 // |resource_id| from a collection represented by the |parent_resource_id|.
304 // Upon completion, invokes |callback| with results on the calling thread.
305 // |callback| must not be null.
306 virtual google_apis::CancelCallback RemoveResourceFromDirectory(
307 const std::string& parent_resource_id,
308 const std::string& resource_id,
309 const google_apis::EntryActionCallback& callback) = 0;
311 // Adds new collection with |directory_title| under parent directory
312 // identified with |parent_resource_id|. |parent_resource_id| can be the
313 // value returned by GetRootResourceId to represent the root directory.
314 // Upon completion, invokes |callback| and passes newly created entry on
315 // the calling thread.
316 // This function cannot be named as "CreateDirectory" as it conflicts with
317 // a macro on Windows.
318 // |callback| must not be null.
319 virtual google_apis::CancelCallback AddNewDirectory(
320 const std::string& parent_resource_id,
321 const std::string& directory_title,
322 const AddNewDirectoryOptions& options,
323 const google_apis::FileResourceCallback& callback) = 0;
325 // Downloads a file with |resourced_id|. The downloaded file will
326 // be stored at |local_cache_path| location. Upon completion, invokes
327 // |download_action_callback| with results on the calling thread.
328 // If |get_content_callback| is not empty,
329 // URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in
330 // turn invoke |get_content_callback| on the calling thread.
331 // If |progress_callback| is not empty, it is invoked periodically when
332 // the download made some progress.
334 // |download_action_callback| must not be null.
335 // |get_content_callback| and |progress_callback| may be null.
336 virtual google_apis::CancelCallback DownloadFile(
337 const base::FilePath& local_cache_path,
338 const std::string& resource_id,
339 const google_apis::DownloadActionCallback& download_action_callback,
340 const google_apis::GetContentCallback& get_content_callback,
341 const google_apis::ProgressCallback& progress_callback) = 0;
343 // Initiates uploading of a new document/file.
344 // |content_type| and |content_length| should be the ones of the file to be
345 // uploaded.
346 // |callback| must not be null.
347 virtual google_apis::CancelCallback InitiateUploadNewFile(
348 const std::string& content_type,
349 int64 content_length,
350 const std::string& parent_resource_id,
351 const std::string& title,
352 const InitiateUploadNewFileOptions& options,
353 const google_apis::InitiateUploadCallback& callback) = 0;
355 // Initiates uploading of an existing document/file.
356 // |content_type| and |content_length| should be the ones of the file to be
357 // uploaded.
358 // |callback| must not be null.
359 virtual google_apis::CancelCallback InitiateUploadExistingFile(
360 const std::string& content_type,
361 int64 content_length,
362 const std::string& resource_id,
363 const InitiateUploadExistingFileOptions& options,
364 const google_apis::InitiateUploadCallback& callback) = 0;
366 // Resumes uploading of a document/file on the calling thread.
367 // |callback| must not be null. |progress_callback| may be null.
368 virtual google_apis::CancelCallback ResumeUpload(
369 const GURL& upload_url,
370 int64 start_position,
371 int64 end_position,
372 int64 content_length,
373 const std::string& content_type,
374 const base::FilePath& local_file_path,
375 const google_apis::drive::UploadRangeCallback& callback,
376 const google_apis::ProgressCallback& progress_callback) = 0;
378 // Gets the current status of the uploading to |upload_url| from the server.
379 // |drive_file_path| and |content_length| should be set to the same value
380 // which is used for ResumeUpload.
381 // |callback| must not be null.
382 virtual google_apis::CancelCallback GetUploadStatus(
383 const GURL& upload_url,
384 int64 content_length,
385 const google_apis::drive::UploadRangeCallback& callback) = 0;
387 // Authorizes a Drive app with the id |app_id| to open the given file.
388 // Upon completion, invokes |callback| with the link to open the file with
389 // the provided app. |callback| must not be null.
390 virtual google_apis::CancelCallback AuthorizeApp(
391 const std::string& resource_id,
392 const std::string& app_id,
393 const google_apis::AuthorizeAppCallback& callback) = 0;
395 // Uninstalls a Drive app with the id |app_id|. |callback| must not be null.
396 virtual google_apis::CancelCallback UninstallApp(
397 const std::string& app_id,
398 const google_apis::EntryActionCallback& callback) = 0;
400 // Authorizes the account |email| to access |resource_id| as a |role|.
402 // |callback| must not be null.
403 virtual google_apis::CancelCallback AddPermission(
404 const std::string& resource_id,
405 const std::string& email,
406 google_apis::drive::PermissionRole role,
407 const google_apis::EntryActionCallback& callback) = 0;
410 } // namespace drive
412 #endif // CHROME_BROWSER_DRIVE_DRIVE_SERVICE_INTERFACE_H_