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