Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / drive / drive_service_interface.h
blob1f789a8d0fa3d31f8c8e27c76a46d56136031a79
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() and
57 // MultipartUploadNewFile().
58 struct UploadNewFileOptions {
59 UploadNewFileOptions();
60 ~UploadNewFileOptions();
62 // modified_date of the file.
63 // Pass the null Time if you are not interested in setting this property.
64 base::Time modified_date;
66 // last_viewed_by_me_date of the file.
67 // Pass the null Time if you are not interested in setting this property.
68 base::Time last_viewed_by_me_date;
71 // Optional parameters for InitiateUploadExistingFile() and
72 // MultipartUploadExistingFile().
73 struct UploadExistingFileOptions {
74 UploadExistingFileOptions();
75 ~UploadExistingFileOptions();
77 // Expected ETag of the file. UPLOAD_ERROR_CONFLICT error is generated when
78 // matching fails.
79 // Pass the empty string to disable this behavior.
80 std::string etag;
82 // New parent of the file.
83 // Pass the empty string to keep the property unchanged.
84 std::string parent_resource_id;
86 // New title of the file.
87 // Pass the empty string to keep the property unchanged.
88 std::string title;
90 // New modified_date of the file.
91 // Pass the null Time if you are not interested in setting this property.
92 base::Time modified_date;
94 // New last_viewed_by_me_date of the file.
95 // Pass the null Time if you are not interested in setting this property.
96 base::Time last_viewed_by_me_date;
99 virtual ~DriveServiceInterface() {}
101 // Common service:
103 // Initializes the documents service with |account_id|.
104 virtual void Initialize(const std::string& account_id) = 0;
106 // Adds an observer.
107 virtual void AddObserver(DriveServiceObserver* observer) = 0;
109 // Removes an observer.
110 virtual void RemoveObserver(DriveServiceObserver* observer) = 0;
112 // True if ready to send requests.
113 virtual bool CanSendRequest() const = 0;
115 // Authentication service:
117 // True if OAuth2 access token is retrieved and believed to be fresh.
118 virtual bool HasAccessToken() const = 0;
120 // Gets the cached OAuth2 access token or if empty, then fetches a new one.
121 virtual void RequestAccessToken(
122 const google_apis::AuthStatusCallback& callback) = 0;
124 // True if OAuth2 refresh token is present.
125 virtual bool HasRefreshToken() const = 0;
127 // Clears OAuth2 access token.
128 virtual void ClearAccessToken() = 0;
130 // Clears OAuth2 refresh token.
131 virtual void ClearRefreshToken() = 0;
133 // Document access:
135 // Returns the resource id for the root directory.
136 virtual std::string GetRootResourceId() const = 0;
138 // Fetches a file list of the account. |callback| will be called upon
139 // completion.
140 // If the list is too long, it may be paged. In such a case, a URL to fetch
141 // remaining results will be included in the returned result. See also
142 // GetRemainingFileList.
144 // |callback| must not be null.
145 virtual google_apis::CancelCallback GetAllFileList(
146 const google_apis::FileListCallback& callback) = 0;
148 // Fetches a file list in the directory with |directory_resource_id|.
149 // |callback| will be called upon completion.
150 // If the list is too long, it may be paged. In such a case, a URL to fetch
151 // remaining results will be included in the returned result. See also
152 // GetRemainingFileList.
154 // |directory_resource_id| must not be empty.
155 // |callback| must not be null.
156 virtual google_apis::CancelCallback GetFileListInDirectory(
157 const std::string& directory_resource_id,
158 const google_apis::FileListCallback& callback) = 0;
160 // Searches the resources for the |search_query| from all the user's
161 // resources. |callback| will be called upon completion.
162 // If the list is too long, it may be paged. In such a case, a URL to fetch
163 // remaining results will be included in the returned result. See also
164 // GetRemainingFileList.
166 // |search_query| must not be empty.
167 // |callback| must not be null.
168 virtual google_apis::CancelCallback Search(
169 const std::string& search_query,
170 const google_apis::FileListCallback& callback) = 0;
172 // Searches the resources with the |title|.
173 // |directory_resource_id| is an optional parameter. If it is empty,
174 // the search target is all the existing resources. Otherwise, it is
175 // the resources directly under the directory with |directory_resource_id|.
176 // If the list is too long, it may be paged. In such a case, a URL to fetch
177 // remaining results will be included in the returned result. See also
178 // GetRemainingFileList.
180 // |title| must not be empty, and |callback| must not be null.
181 virtual google_apis::CancelCallback SearchByTitle(
182 const std::string& title,
183 const std::string& directory_resource_id,
184 const google_apis::FileListCallback& callback) = 0;
186 // Fetches change list since |start_changestamp|. |callback| will be
187 // called upon completion.
188 // If the list is too long, it may be paged. In such a case, a URL to fetch
189 // remaining results will be included in the returned result. See also
190 // GetRemainingChangeList.
192 // |callback| must not be null.
193 virtual google_apis::CancelCallback GetChangeList(
194 int64 start_changestamp,
195 const google_apis::ChangeListCallback& callback) = 0;
197 // The result of GetChangeList() may be paged.
198 // In such a case, a next link to fetch remaining result is returned.
199 // The page token can be used for this method. |callback| will be called upon
200 // completion.
202 // |next_link| must not be empty. |callback| must not be null.
203 virtual google_apis::CancelCallback GetRemainingChangeList(
204 const GURL& next_link,
205 const google_apis::ChangeListCallback& callback) = 0;
207 // The result of GetAllFileList(), GetFileListInDirectory(), Search()
208 // and SearchByTitle() may be paged. In such a case, a next link to fetch
209 // remaining result is returned. The page token can be used for this method.
210 // |callback| will be called upon completion.
212 // |next_link| must not be empty. |callback| must not be null.
213 virtual google_apis::CancelCallback GetRemainingFileList(
214 const GURL& next_link,
215 const google_apis::FileListCallback& callback) = 0;
217 // Fetches single entry metadata from server. The entry's file id equals
218 // |resource_id|.
219 // Upon completion, invokes |callback| with results on the calling thread.
220 // |callback| must not be null.
221 virtual google_apis::CancelCallback GetFileResource(
222 const std::string& resource_id,
223 const google_apis::FileResourceCallback& callback) = 0;
225 // Fetches an url for the sharing dialog for a single entry with id
226 // |resource_id|, to be embedded in a webview or an iframe with origin
227 // |embed_origin|. The url is returned via |callback| with results on the
228 // calling thread. |callback| must not be null.
229 virtual google_apis::CancelCallback GetShareUrl(
230 const std::string& resource_id,
231 const GURL& embed_origin,
232 const google_apis::GetShareUrlCallback& callback) = 0;
234 // Gets the about resource information from the server.
235 // Upon completion, invokes |callback| with results on the calling thread.
236 // |callback| must not be null.
237 virtual google_apis::CancelCallback GetAboutResource(
238 const google_apis::AboutResourceCallback& callback) = 0;
240 // Gets the application information from the server.
241 // Upon completion, invokes |callback| with results on the calling thread.
242 // |callback| must not be null.
243 virtual google_apis::CancelCallback GetAppList(
244 const google_apis::AppListCallback& callback) = 0;
246 // Permanently deletes a resource identified by its |resource_id|.
247 // If |etag| is not empty and did not match, the deletion fails with
248 // HTTP_PRECONDITION error.
249 // Upon completion, invokes |callback| with results on the calling thread.
250 // |callback| must not be null.
251 virtual google_apis::CancelCallback DeleteResource(
252 const std::string& resource_id,
253 const std::string& etag,
254 const google_apis::EntryActionCallback& callback) = 0;
256 // Trashes a resource identified by its |resource_id|.
257 // Upon completion, invokes |callback| with results on the calling thread.
258 // |callback| must not be null.
259 virtual google_apis::CancelCallback TrashResource(
260 const std::string& resource_id,
261 const google_apis::EntryActionCallback& callback) = 0;
263 // Makes a copy of a resource with |resource_id|.
264 // The new resource will be put under a directory with |parent_resource_id|,
265 // and it'll be named |new_title|.
266 // If |last_modified| is not null, the modified date of the resource on the
267 // server will be set to the date.
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 // If |properties| are specified, then they will be set on |resource_id|.
282 // Upon completion, invokes |callback| with results on the calling thread.
283 // |callback| must not be null.
284 virtual google_apis::CancelCallback UpdateResource(
285 const std::string& resource_id,
286 const std::string& parent_resource_id,
287 const std::string& new_title,
288 const base::Time& last_modified,
289 const base::Time& last_viewed_by_me,
290 const google_apis::drive::Properties& properties,
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 UploadNewFileOptions& 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 UploadExistingFileOptions& 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 // Uploads a file by a single request with multipart body. It's more efficient
388 // for small files than using |InitiateUploadNewFile| and |ResumeUpload|.
389 // |content_type| and |content_length| should be the ones of the file to be
390 // uploaded. |callback| must not be null. |progress_callback| may be null.
391 virtual google_apis::CancelCallback MultipartUploadNewFile(
392 const std::string& content_type,
393 int64 content_length,
394 const std::string& parent_resource_id,
395 const std::string& title,
396 const base::FilePath& local_file_path,
397 const UploadNewFileOptions& options,
398 const google_apis::FileResourceCallback& callback,
399 const google_apis::ProgressCallback& progress_callback) = 0;
401 // Uploads a file by a single request with multipart body. It's more efficient
402 // for small files than using |InitiateUploadExistingFile| and |ResumeUpload|.
403 // |content_type| and |content_length| should be the ones of the file to be
404 // uploaded. |callback| must not be null. |progress_callback| may be null.
405 virtual google_apis::CancelCallback MultipartUploadExistingFile(
406 const std::string& content_type,
407 int64 content_length,
408 const std::string& resource_id,
409 const base::FilePath& local_file_path,
410 const UploadExistingFileOptions& options,
411 const google_apis::FileResourceCallback& callback,
412 const google_apis::ProgressCallback& progress_callback) = 0;
414 // Authorizes a Drive app with the id |app_id| to open the given file.
415 // Upon completion, invokes |callback| with the link to open the file with
416 // the provided app. |callback| must not be null.
417 virtual google_apis::CancelCallback AuthorizeApp(
418 const std::string& resource_id,
419 const std::string& app_id,
420 const google_apis::AuthorizeAppCallback& callback) = 0;
422 // Uninstalls a Drive app with the id |app_id|. |callback| must not be null.
423 virtual google_apis::CancelCallback UninstallApp(
424 const std::string& app_id,
425 const google_apis::EntryActionCallback& callback) = 0;
427 // Authorizes the account |email| to access |resource_id| as a |role|.
428 // |callback| must not be null.
429 virtual google_apis::CancelCallback AddPermission(
430 const std::string& resource_id,
431 const std::string& email,
432 google_apis::drive::PermissionRole role,
433 const google_apis::EntryActionCallback& callback) = 0;
436 } // namespace drive
438 #endif // CHROME_BROWSER_DRIVE_DRIVE_SERVICE_INTERFACE_H_