1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_SERVICE_INTERFACE_H_
#define CHROME_BROWSER_GOOGLE_APIS_DRIVE_SERVICE_INTERFACE_H_
#include <string>
// TODO(kochi): Further split gdata_operations.h and include only necessary
// headers. http://crbug.com/141469
// DownloadActionCallback
#include "chrome/browser/google_apis/base_operations.h"
class Profile;
namespace net {
class IOBuffer;
} // namespace net
namespace google_apis {
class AboutResource;
class AccountMetadata;
class AppList;
class ResourceEntry;
class ResourceList;
// Observer interface for DriveServiceInterface.
class DriveServiceObserver {
public:
// Triggered when the service gets ready to perform operations.
virtual void OnReadyToPerformOperations() {}
// Called when the refresh token was found to be invalid.
virtual void OnRefreshTokenInvalid() {}
protected:
virtual ~DriveServiceObserver() {}
};
// Callback used for GetResourceList().
typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<ResourceList> resource_list)>
GetResourceListCallback;
// Callback used for GetResourceEntry().
typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<ResourceEntry> entry)>
GetResourceEntryCallback;
// Callback used for GetAccountMetadata().
typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<AccountMetadata> account_metadata)>
GetAccountMetadataCallback;
// Callback used for GetAboutResource().
typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<AboutResource> about_resource)>
GetAboutResourceCallback;
// Callback used for GetApplicationInfo().
typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<AppList> app_list)>
GetAppListCallback;
// Callback used for ResumeUpload() and GetUploadStatus().
typedef base::Callback<void(
const UploadRangeResponse& response,
scoped_ptr<ResourceEntry> new_entry)> UploadRangeCallback;
// Callback used for AuthorizeApp(). |open_url| is used to open the target
// file with the authorized app.
typedef base::Callback<void(GDataErrorCode error,
const GURL& open_url)>
AuthorizeAppCallback;
// This defines an interface for sharing by DriveService and MockDriveService
// so that we can do testing of clients of DriveService.
//
// All functions must be called on UI thread. DriveService is built on top of
// URLFetcher that runs on UI thread.
class DriveServiceInterface {
public:
virtual ~DriveServiceInterface() {}
// Common service:
// Initializes the documents service tied with |profile|.
virtual void Initialize(Profile* profile) = 0;
// Adds an observer.
virtual void AddObserver(DriveServiceObserver* observer) = 0;
// Removes an observer.
virtual void RemoveObserver(DriveServiceObserver* observer) = 0;
// True if ready to start operations.
virtual bool CanStartOperation() const = 0;
// Cancels all in-flight operations.
virtual void CancelAll() = 0;
// Cancels ongoing operation for a given virtual |file_path|. Returns true if
// the operation was found and canceled.
virtual bool CancelForFilePath(const base::FilePath& file_path) = 0;
// Authentication service:
// True if OAuth2 access token is retrieved and believed to be fresh.
virtual bool HasAccessToken() const = 0;
// True if OAuth2 refresh token is present.
virtual bool HasRefreshToken() const = 0;
// Clears OAuth2 access token.
virtual void ClearAccessToken() = 0;
// Clears OAuth2 refresh token.
virtual void ClearRefreshToken() = 0;
// Document access:
// Returns the resource id for the root directory.
virtual std::string GetRootResourceId() const = 0;
// Fetches a resource list of the account. |callback| will be called upon
// completion.
// If the list is too long, it may be paged. In such a case, a URL to fetch
// remaining results will be included in the returned result. See also
// ContinueGetResourceList.
//
// |callback| must not be null.
virtual void GetAllResourceList(
const GetResourceListCallback& callback) = 0;
// Fetches a resource list in the directory with |directory_resource_id|.
// |callback| will be called upon completion.
// If the list is too long, it may be paged. In such a case, a URL to fetch
// remaining results will be included in the returned result. See also
// ContinueGetResourceList.
//
// |directory_resource_id| must not be empty.
// |callback| must not be null.
virtual void GetResourceListInDirectory(
const std::string& directory_resource_id,
const GetResourceListCallback& callback) = 0;
// Searches the resources for the |search_query| from all the user's
// resources. |callback| will be called upon completion.
// If the list is too long, it may be paged. In such a case, a URL to fetch
// remaining results will be included in the returned result. See also
// ContinueGetResourceList.
//
// |search_query| must not be empty.
// |callback| must not be null.
virtual void Search(
const std::string& search_query,
const GetResourceListCallback& callback) = 0;
// Searches the resources with the |title|.
// |directory_resource_id| is an optional prameter. If it is empty,
// the search target is all the existing resources. Otherwise, it is
// the resources directly under the directory with |directory_resource_id|.
// If the list is too long, it may be paged. In such a case, a URL to fetch
// remaining results will be included in the returned result. See also
// ContinueGetResourceList.
//
// |title| must not be empty, and |callback| must not be null.
virtual void SearchByTitle(
const std::string& title,
const std::string& directory_resource_id,
const GetResourceListCallback& callback) = 0;
// Fetches change list since |start_changestamp|. |callback| will be
// called upon completion.
// If the list is too long, it may be paged. In such a case, a URL to fetch
// remaining results will be included in the returned result. See also
// ContinueGetResourceList.
//
// |callback| must not be null.
virtual void GetChangeList(
int64 start_changestamp,
const GetResourceListCallback& callback) = 0;
// Operations returning GetResourceList may be paged. In such a case,
// a URL to fetch remaining result is returned. The URL can be used for this
// method. |callback| will be called upon completion.
//
// |override_url| must not be empty.
// |callback| must not be null.
virtual void ContinueGetResourceList(
const GURL& override_url,
const GetResourceListCallback& callback) = 0;
// Fetches single entry metadata from server. The entry's resource id equals
// |resource_id|.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void GetResourceEntry(const std::string& resource_id,
const GetResourceEntryCallback& callback) = 0;
// Gets the account metadata from the server using the default account
// metadata URL. Upon completion, invokes |callback| with results on the
// calling thread.
// |callback| must not be null.
virtual void GetAccountMetadata(
const GetAccountMetadataCallback& callback) = 0;
// Gets the about resource information from the server.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void GetAboutResource(const GetAboutResourceCallback& callback) = 0;
// Gets the application information from the server.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void GetAppList(const GetAppListCallback& callback) = 0;
// Deletes a resource identified by its |resource_id|.
// If |etag| is not empty and did not match, the deletion fails with
// HTTP_PRECONDITION error.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void DeleteResource(const std::string& resource_id,
const std::string& etag,
const EntryActionCallback& callback) = 0;
// Makes a copy of a hosted document identified by its |resource_id|.
// The copy is named as the UTF-8 encoded |new_name| and is not added to any
// collection. Use AddResourceToDirectory() to add the copy to a collection
// when needed. Upon completion, invokes |callback| with results on the
// calling thread.
// |callback| must not be null.
virtual void CopyHostedDocument(
const std::string& resource_id,
const std::string& new_name,
const GetResourceEntryCallback& callback) = 0;
// Renames a document or collection identified by its |resource_id|
// to the UTF-8 encoded |new_name|. Upon completion,
// invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void RenameResource(const std::string& resource_id,
const std::string& new_name,
const EntryActionCallback& callback) = 0;
// Adds a resource (document, file, or collection) identified by its
// |resource_id| to a collection represented by the |parent_resource_id|.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void AddResourceToDirectory(const std::string& parent_resource_id,
const std::string& resource_id,
const EntryActionCallback& callback) = 0;
// Removes a resource (document, file, collection) identified by its
// |resource_id| from a collection represented by the |parent_resource_id|.
// Upon completion, invokes |callback| with results on the calling thread.
// |callback| must not be null.
virtual void RemoveResourceFromDirectory(
const std::string& parent_resource_id,
const std::string& resource_id,
const EntryActionCallback& callback) = 0;
// Adds new collection with |directory_name| under parent directory
// identified with |parent_resource_id|. |parent_resource_id| can be the
// value returned by GetRootResourceId to represent the root directory.
// Upon completion, invokes |callback| and passes newly created entry on
// the calling thread.
// This function cannot be named as "CreateDirectory" as it conflicts with
// a macro on Windows.
// |callback| must not be null.
virtual void AddNewDirectory(const std::string& parent_resource_id,
const std::string& directory_name,
const GetResourceEntryCallback& callback) = 0;
// Downloads a file from |download_url|. The downloaded file will
// be stored at |local_cache_path| location. Upon completion, invokes
// |download_action_callback| with results on the calling thread.
// If |get_content_callback| is not empty,
// URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in
// turn invoke |get_content_callback| on the calling thread.
// If |progress_callback| is not empty, it is invoked periodically when
// the download made some progress.
//
// |download_action_callback| must not be null.
// |get_content_callback| and |progress_callback| may be null.
virtual void DownloadFile(
const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback,
const ProgressCallback& progress_callback) = 0;
// Initiates uploading of a new document/file.
// |content_type| and |content_length| should be the ones of the file to be
// uploaded.
// |callback| must not be null.
virtual void InitiateUploadNewFile(
const base::FilePath& drive_file_path,
const std::string& content_type,
int64 content_length,
const std::string& parent_resource_id,
const std::string& title,
const InitiateUploadCallback& callback) = 0;
// Initiates uploading of an existing document/file.
// |content_type| and |content_length| should be the ones of the file to be
// uploaded.
// |callback| must not be null.
virtual void InitiateUploadExistingFile(
const base::FilePath& drive_file_path,
const std::string& content_type,
int64 content_length,
const std::string& resource_id,
const std::string& etag,
const InitiateUploadCallback& callback) = 0;
// Resumes uploading of a document/file on the calling thread.
// |callback| must not be null. |progress_callback| may be null.
virtual void ResumeUpload(
UploadMode upload_mode,
const base::FilePath& drive_file_path,
const GURL& upload_url,
int64 start_position,
int64 end_position,
int64 content_length,
const std::string& content_type,
const scoped_refptr<net::IOBuffer>& buf,
const UploadRangeCallback& callback,
const ProgressCallback& progress_callback) = 0;
// Gets the current status of the uploading to |upload_url| from the server.
// |upload_mode|, |drive_file_path| and |content_length| should be set to
// the same value which is used for ResumeUpload.
// |callback| must not be null.
virtual void GetUploadStatus(
UploadMode upload_mode,
const base::FilePath& drive_file_path,
const GURL& upload_url,
int64 content_length,
const UploadRangeCallback& callback) = 0;
// Authorizes a Drive app with the id |app_id| to open the given file.
// Upon completion, invokes |callback| with the link to open the file with
// the provided app. |callback| must not be null.
virtual void AuthorizeApp(const std::string& resource_id,
const std::string& app_id,
const AuthorizeAppCallback& callback) = 0;
};
} // namespace google_apis
#endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_SERVICE_INTERFACE_H_
|