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_
10 #include "google_apis/drive/auth_service_interface.h"
11 #include "google_apis/drive/base_requests.h"
12 #include "google_apis/drive/drive_common_callbacks.h"
20 // Function which converts the given resource ID into the desired format.
21 typedef base::Callback
<std::string(
22 const std::string
& resource_id
)> ResourceIdCanonicalizer
;
24 // Observer interface for DriveServiceInterface.
25 class DriveServiceObserver
{
27 // Triggered when the service gets ready to send requests.
28 virtual void OnReadyToSendRequests() {}
30 // Called when the refresh token was found to be invalid.
31 virtual void OnRefreshTokenInvalid() {}
34 virtual ~DriveServiceObserver() {}
37 // This defines an interface for sharing by DriveService and MockDriveService
38 // so that we can do testing of clients of DriveService.
40 // All functions must be called on UI thread. DriveService is built on top of
41 // URLFetcher that runs on UI thread.
42 class DriveServiceInterface
{
44 virtual ~DriveServiceInterface() {}
48 // Initializes the documents service with |account_id|.
49 virtual void Initialize(const std::string
& account_id
) = 0;
52 virtual void AddObserver(DriveServiceObserver
* observer
) = 0;
54 // Removes an observer.
55 virtual void RemoveObserver(DriveServiceObserver
* observer
) = 0;
57 // True if ready to send requests.
58 virtual bool CanSendRequest() const = 0;
60 // Returns a function which converts the given resource ID into the desired
62 virtual ResourceIdCanonicalizer
GetResourceIdCanonicalizer() const = 0;
64 // Authentication service:
66 // True if OAuth2 access token is retrieved and believed to be fresh.
67 virtual bool HasAccessToken() const = 0;
69 // Gets the cached OAuth2 access token or if empty, then fetches a new one.
70 virtual void RequestAccessToken(
71 const google_apis::AuthStatusCallback
& callback
) = 0;
73 // True if OAuth2 refresh token is present.
74 virtual bool HasRefreshToken() const = 0;
76 // Clears OAuth2 access token.
77 virtual void ClearAccessToken() = 0;
79 // Clears OAuth2 refresh token.
80 virtual void ClearRefreshToken() = 0;
84 // Returns the resource id for the root directory.
85 virtual std::string
GetRootResourceId() const = 0;
87 // Fetches a resource list of the account. |callback| will be called upon
89 // If the list is too long, it may be paged. In such a case, a URL to fetch
90 // remaining results will be included in the returned result. See also
91 // GetRemainingFileList.
93 // |callback| must not be null.
94 virtual google_apis::CancelCallback
GetAllResourceList(
95 const google_apis::GetResourceListCallback
& callback
) = 0;
97 // Fetches a resource list in the directory with |directory_resource_id|.
98 // |callback| will be called upon completion.
99 // If the list is too long, it may be paged. In such a case, a URL to fetch
100 // remaining results will be included in the returned result. See also
101 // GetRemainingFileList.
103 // |directory_resource_id| must not be empty.
104 // |callback| must not be null.
105 virtual google_apis::CancelCallback
GetResourceListInDirectory(
106 const std::string
& directory_resource_id
,
107 const google_apis::GetResourceListCallback
& callback
) = 0;
109 // Searches the resources for the |search_query| from all the user's
110 // resources. |callback| will be called upon completion.
111 // If the list is too long, it may be paged. In such a case, a URL to fetch
112 // remaining results will be included in the returned result. See also
113 // GetRemainingFileList.
115 // |search_query| must not be empty.
116 // |callback| must not be null.
117 virtual google_apis::CancelCallback
Search(
118 const std::string
& search_query
,
119 const google_apis::GetResourceListCallback
& callback
) = 0;
121 // Searches the resources with the |title|.
122 // |directory_resource_id| is an optional parameter. If it is empty,
123 // the search target is all the existing resources. Otherwise, it is
124 // the resources directly under the directory with |directory_resource_id|.
125 // If the list is too long, it may be paged. In such a case, a URL to fetch
126 // remaining results will be included in the returned result. See also
127 // GetRemainingFileList.
129 // |title| must not be empty, and |callback| must not be null.
130 virtual google_apis::CancelCallback
SearchByTitle(
131 const std::string
& title
,
132 const std::string
& directory_resource_id
,
133 const google_apis::GetResourceListCallback
& callback
) = 0;
135 // Fetches change list since |start_changestamp|. |callback| will be
136 // called upon completion.
137 // If the list is too long, it may be paged. In such a case, a URL to fetch
138 // remaining results will be included in the returned result. See also
139 // GetRemainingChangeList.
141 // |callback| must not be null.
142 virtual google_apis::CancelCallback
GetChangeList(
143 int64 start_changestamp
,
144 const google_apis::GetResourceListCallback
& callback
) = 0;
146 // The result of GetChangeList() and GetAllResourceList() may be paged.
147 // In such a case, a next link to fetch remaining result is returned.
148 // The page token can be used for this method. |callback| will be called upon
151 // |next_link| must not be empty. |callback| must not be null.
152 virtual google_apis::CancelCallback
GetRemainingChangeList(
153 const GURL
& next_link
,
154 const google_apis::GetResourceListCallback
& callback
) = 0;
156 // The result of GetResourceListInDirectory(), Search() and SearchByTitle()
157 // may be paged. In such a case, a next link to fetch remaining result is
158 // returned. The page token can be used for this method. |callback| will be
159 // called upon completion.
161 // |next_link| must not be empty. |callback| must not be null.
162 virtual google_apis::CancelCallback
GetRemainingFileList(
163 const GURL
& next_link
,
164 const google_apis::GetResourceListCallback
& callback
) = 0;
166 // Fetches single entry metadata from server. The entry's resource id equals
168 // Upon completion, invokes |callback| with results on the calling thread.
169 // |callback| must not be null.
170 virtual google_apis::CancelCallback
GetResourceEntry(
171 const std::string
& resource_id
,
172 const google_apis::GetResourceEntryCallback
& callback
) = 0;
174 // Fetches an url for the sharing dialog for a single entry with id
175 // |resource_id|, to be embedded in a webview or an iframe with origin
176 // |embed_origin|. The url is returned via |callback| with results on the
177 // calling thread. |callback| must not be null.
178 virtual google_apis::CancelCallback
GetShareUrl(
179 const std::string
& resource_id
,
180 const GURL
& embed_origin
,
181 const google_apis::GetShareUrlCallback
& callback
) = 0;
183 // Gets the about resource information from the server.
184 // Upon completion, invokes |callback| with results on the calling thread.
185 // |callback| must not be null.
186 virtual google_apis::CancelCallback
GetAboutResource(
187 const google_apis::AboutResourceCallback
& callback
) = 0;
189 // Gets the application information from the server.
190 // Upon completion, invokes |callback| with results on the calling thread.
191 // |callback| must not be null.
192 virtual google_apis::CancelCallback
GetAppList(
193 const google_apis::AppListCallback
& callback
) = 0;
195 // Permanently deletes a resource identified by its |resource_id|.
196 // If |etag| is not empty and did not match, the deletion fails with
197 // HTTP_PRECONDITION error.
198 // Upon completion, invokes |callback| with results on the calling thread.
199 // |callback| must not be null.
200 virtual google_apis::CancelCallback
DeleteResource(
201 const std::string
& resource_id
,
202 const std::string
& etag
,
203 const google_apis::EntryActionCallback
& callback
) = 0;
205 // Trashes a resource identified by its |resource_id|.
206 // Upon completion, invokes |callback| with results on the calling thread.
207 // |callback| must not be null.
208 virtual google_apis::CancelCallback
TrashResource(
209 const std::string
& resource_id
,
210 const google_apis::EntryActionCallback
& callback
) = 0;
212 // Makes a copy of a resource with |resource_id|.
213 // The new resource will be put under a directory with |parent_resource_id|,
214 // and it'll be named |new_title|.
215 // If |last_modified| is not null, the modified date of the resource on the
216 // server will be set to the date.
217 // This request is supported only on DriveAPIService, because GData WAPI
218 // doesn't support the function unfortunately.
219 // Upon completion, invokes |callback| with results on the calling thread.
220 // |callback| must not be null.
221 virtual google_apis::CancelCallback
CopyResource(
222 const std::string
& resource_id
,
223 const std::string
& parent_resource_id
,
224 const std::string
& new_title
,
225 const base::Time
& last_modified
,
226 const google_apis::GetResourceEntryCallback
& callback
) = 0;
228 // Updates a resource with |resource_id| to the directory of
229 // |parent_resource_id| with renaming to |new_title|.
230 // If |last_modified| or |last_accessed| is not null, the modified/accessed
231 // date of the resource on the server will be set to the date.
232 // This request is supported only on DriveAPIService, because GData WAPI
233 // doesn't support the function unfortunately.
234 // Upon completion, invokes |callback| with results on the calling thread.
235 // |callback| must not be null.
236 virtual google_apis::CancelCallback
UpdateResource(
237 const std::string
& resource_id
,
238 const std::string
& parent_resource_id
,
239 const std::string
& new_title
,
240 const base::Time
& last_modified
,
241 const base::Time
& last_viewed_by_me
,
242 const google_apis::GetResourceEntryCallback
& callback
) = 0;
244 // Renames a document or collection identified by its |resource_id|
245 // to the UTF-8 encoded |new_title|. Upon completion,
246 // invokes |callback| with results on the calling thread.
247 // |callback| must not be null.
248 virtual google_apis::CancelCallback
RenameResource(
249 const std::string
& resource_id
,
250 const std::string
& new_title
,
251 const google_apis::EntryActionCallback
& callback
) = 0;
253 // Adds a resource (document, file, or collection) identified by its
254 // |resource_id| to a collection represented by the |parent_resource_id|.
255 // Upon completion, invokes |callback| with results on the calling thread.
256 // |callback| must not be null.
257 virtual google_apis::CancelCallback
AddResourceToDirectory(
258 const std::string
& parent_resource_id
,
259 const std::string
& resource_id
,
260 const google_apis::EntryActionCallback
& callback
) = 0;
262 // Removes a resource (document, file, collection) identified by its
263 // |resource_id| from a collection represented by the |parent_resource_id|.
264 // Upon completion, invokes |callback| with results on the calling thread.
265 // |callback| must not be null.
266 virtual google_apis::CancelCallback
RemoveResourceFromDirectory(
267 const std::string
& parent_resource_id
,
268 const std::string
& resource_id
,
269 const google_apis::EntryActionCallback
& callback
) = 0;
271 // Adds new collection with |directory_title| under parent directory
272 // identified with |parent_resource_id|. |parent_resource_id| can be the
273 // value returned by GetRootResourceId to represent the root directory.
274 // Upon completion, invokes |callback| and passes newly created entry on
275 // the calling thread.
276 // This function cannot be named as "CreateDirectory" as it conflicts with
277 // a macro on Windows.
278 // |callback| must not be null.
279 virtual google_apis::CancelCallback
AddNewDirectory(
280 const std::string
& parent_resource_id
,
281 const std::string
& directory_title
,
282 const google_apis::GetResourceEntryCallback
& callback
) = 0;
284 // Downloads a file with |resourced_id|. The downloaded file will
285 // be stored at |local_cache_path| location. Upon completion, invokes
286 // |download_action_callback| with results on the calling thread.
287 // If |get_content_callback| is not empty,
288 // URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in
289 // turn invoke |get_content_callback| on the calling thread.
290 // If |progress_callback| is not empty, it is invoked periodically when
291 // the download made some progress.
293 // |download_action_callback| must not be null.
294 // |get_content_callback| and |progress_callback| may be null.
295 virtual google_apis::CancelCallback
DownloadFile(
296 const base::FilePath
& local_cache_path
,
297 const std::string
& resource_id
,
298 const google_apis::DownloadActionCallback
& download_action_callback
,
299 const google_apis::GetContentCallback
& get_content_callback
,
300 const google_apis::ProgressCallback
& progress_callback
) = 0;
302 // Initiates uploading of a new document/file.
303 // |content_type| and |content_length| should be the ones of the file to be
305 // |callback| must not be null.
306 virtual google_apis::CancelCallback
InitiateUploadNewFile(
307 const std::string
& content_type
,
308 int64 content_length
,
309 const std::string
& parent_resource_id
,
310 const std::string
& title
,
311 const google_apis::InitiateUploadCallback
& callback
) = 0;
313 // Initiates uploading of an existing document/file.
314 // |content_type| and |content_length| should be the ones of the file to be
316 // |callback| must not be null.
317 virtual google_apis::CancelCallback
InitiateUploadExistingFile(
318 const std::string
& content_type
,
319 int64 content_length
,
320 const std::string
& resource_id
,
321 const std::string
& etag
,
322 const google_apis::InitiateUploadCallback
& callback
) = 0;
324 // Resumes uploading of a document/file on the calling thread.
325 // |callback| must not be null. |progress_callback| may be null.
326 virtual google_apis::CancelCallback
ResumeUpload(
327 const GURL
& upload_url
,
328 int64 start_position
,
330 int64 content_length
,
331 const std::string
& content_type
,
332 const base::FilePath
& local_file_path
,
333 const google_apis::UploadRangeCallback
& callback
,
334 const google_apis::ProgressCallback
& progress_callback
) = 0;
336 // Gets the current status of the uploading to |upload_url| from the server.
337 // |drive_file_path| and |content_length| should be set to the same value
338 // which is used for ResumeUpload.
339 // |callback| must not be null.
340 virtual google_apis::CancelCallback
GetUploadStatus(
341 const GURL
& upload_url
,
342 int64 content_length
,
343 const google_apis::UploadRangeCallback
& callback
) = 0;
345 // Authorizes a Drive app with the id |app_id| to open the given file.
346 // Upon completion, invokes |callback| with the link to open the file with
347 // the provided app. |callback| must not be null.
348 virtual google_apis::CancelCallback
AuthorizeApp(
349 const std::string
& resource_id
,
350 const std::string
& app_id
,
351 const google_apis::AuthorizeAppCallback
& callback
) = 0;
353 // Uninstalls a Drive app with the id |app_id|. |callback| must not be null.
354 virtual google_apis::CancelCallback
UninstallApp(
355 const std::string
& app_id
,
356 const google_apis::EntryActionCallback
& callback
) = 0;
358 // This is introduced as a temporary short term solution of the performance
359 // regression issue on Drive API v2.
361 // This fetches the resource list in a directory by using GData WAPI
362 // regardless of base protocol. In other words, even if we enables Drive API
363 // v2, this method uses GData WAPI to fetch the resource list.
365 // |directory_resource_id| must not be empty.
366 // |callback| must not be null.
367 virtual google_apis::CancelCallback
GetResourceListInDirectoryByWapi(
368 const std::string
& directory_resource_id
,
369 const google_apis::GetResourceListCallback
& callback
) = 0;
371 // GetResourceListInDirectoryByWapi can be paged. This method fetches the
374 // |callback| must not be null.
375 virtual google_apis::CancelCallback
GetRemainingResourceList(
376 const GURL
& next_link
,
377 const google_apis::GetResourceListCallback
& callback
) = 0;
382 #endif // CHROME_BROWSER_DRIVE_DRIVE_SERVICE_INTERFACE_H_