OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DOCUMENTS_SERVICE_INTERFACE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DOCUMENTS_SERVICE_INTERFACE_H_ |
7 | 7 |
8 #include <string> | 8 #include "chrome/browser/chromeos/gdata/operations_base.h" |
| 9 // TODO(kochi): Further split gdata_operations.h and include only necessary |
| 10 // headers. http://crbug.com/141469 |
| 11 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
9 | 12 |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | |
13 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h" | |
14 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | |
15 | |
16 class FilePath; | |
17 class GURL; | |
18 class Profile; | 13 class Profile; |
19 | 14 |
20 namespace gdata { | 15 namespace gdata { |
21 | 16 |
22 class GDataOperationInterface; | |
23 class GDataOperationRegistry; | 17 class GDataOperationRegistry; |
24 class GDataOperationRunner; | |
25 | 18 |
26 // Document export format. | 19 // Document export format. |
27 enum DocumentExportFormat { | 20 enum DocumentExportFormat { |
28 PDF, // Portable Document Format. (all documents) | 21 PDF, // Portable Document Format. (all documents) |
29 PNG, // Portable Networks Graphic Image Format (all documents) | 22 PNG, // Portable Networks Graphic Image Format (all documents) |
30 HTML, // HTML Format (text documents and spreadsheets). | 23 HTML, // HTML Format (text documents and spreadsheets). |
31 TXT, // Text file (text documents and presentations). | 24 TXT, // Text file (text documents and presentations). |
32 DOC, // Word (text documents only). | 25 DOC, // Word (text documents only). |
33 ODT, // Open Document Format (text documents only). | 26 ODT, // Open Document Format (text documents only). |
34 RTF, // Rich Text Format (text documents only). | 27 RTF, // Rich Text Format (text documents only). |
(...skipping 11 matching lines...) Expand all Loading... |
46 }; | 39 }; |
47 | 40 |
48 // This defines an interface for sharing by DocumentService and | 41 // This defines an interface for sharing by DocumentService and |
49 // MockDocumentService so that we can do testing of clients of DocumentService. | 42 // MockDocumentService so that we can do testing of clients of DocumentService. |
50 // | 43 // |
51 // All functions must be called on UI thread. DocumentService is built on top | 44 // All functions must be called on UI thread. DocumentService is built on top |
52 // of URLFetcher that runs on UI thread. | 45 // of URLFetcher that runs on UI thread. |
53 // | 46 // |
54 // TODO(zel,benchan): Make the terminology/naming convention (e.g. file vs | 47 // TODO(zel,benchan): Make the terminology/naming convention (e.g. file vs |
55 // document vs resource, directory vs collection) more consistent and precise. | 48 // document vs resource, directory vs collection) more consistent and precise. |
| 49 // TODO(kochi): Rename this to DriveServiceInterface. http://crbug.com/143661. |
56 class DocumentsServiceInterface { | 50 class DocumentsServiceInterface { |
57 public: | 51 public: |
58 virtual ~DocumentsServiceInterface() {} | 52 virtual ~DocumentsServiceInterface() {} |
59 | 53 |
| 54 // Common service: |
| 55 |
60 // Initializes the documents service tied with |profile|. | 56 // Initializes the documents service tied with |profile|. |
61 virtual void Initialize(Profile* profile) = 0; | 57 virtual void Initialize(Profile* profile) = 0; |
62 | 58 |
63 // Retrieves the operation registry. | 59 // Retrieves the operation registry. |
64 virtual GDataOperationRegistry* operation_registry() const = 0; | 60 virtual GDataOperationRegistry* operation_registry() const = 0; |
65 | 61 |
66 // Cancels all in-flight operations. | 62 // Cancels all in-flight operations. |
67 virtual void CancelAll() = 0; | 63 virtual void CancelAll() = 0; |
68 | 64 |
| 65 // Authentication service: |
| 66 |
69 // Authenticates the user by fetching the auth token as | 67 // Authenticates the user by fetching the auth token as |
70 // needed. |callback| will be run with the error code and the auth | 68 // needed. |callback| will be run with the error code and the auth |
71 // token, on the thread this function is run. | 69 // token, on the thread this function is run. |
72 virtual void Authenticate(const AuthStatusCallback& callback) = 0; | 70 virtual void Authenticate(const AuthStatusCallback& callback) = 0; |
73 | 71 |
| 72 // True if OAuth2 access token is retrieved and believed to be fresh. |
| 73 virtual bool HasAccessToken() const = 0; |
| 74 |
| 75 // True if OAuth2 refresh token is present. |
| 76 virtual bool HasRefreshToken() const = 0; |
| 77 |
| 78 // Document access: |
| 79 |
74 // Fetches the document feed from |feed_url| with |start_changestamp|. If this | 80 // Fetches the document feed from |feed_url| with |start_changestamp|. If this |
75 // URL is empty, the call will fetch the default root or change document feed. | 81 // URL is empty, the call will fetch the default root or change document feed. |
76 // |start_changestamp| specifies the starting point from change feeds only. | 82 // |start_changestamp| specifies the starting point from change feeds only. |
77 // Value different than 0, it would trigger delta feed fetching. | 83 // Value different than 0, it would trigger delta feed fetching. |
78 // | 84 // |
79 // |search_query| specifies search query to be sent to the server. It will be | 85 // |search_query| specifies search query to be sent to the server. It will be |
80 // used only if |start_changestamp| is 0. If empty string is passed, | 86 // used only if |start_changestamp| is 0. If empty string is passed, |
81 // |search_query| is ignored. | 87 // |search_query| is ignored. |
82 // | 88 // |
83 // |directory_resource_id| specifies the directory from which documents are | 89 // |directory_resource_id| specifies the directory from which documents are |
84 // fetched. It will be used only if |start_changestamp| is 0. If empty | 90 // fetched. It will be used only if |start_changestamp| is 0. If empty |
85 // string is passed, |directory_resource_id| is ignored. | 91 // string is passed, |directory_resource_id| is ignored. |
86 // | 92 // |
87 // Upon completion, invokes |callback| with results on the calling thread. | 93 // Upon completion, invokes |callback| with results on the calling thread. |
88 // TODO(satorux): Refactor this function: crbug.com/128746 | 94 // TODO(satorux): Refactor this function: crbug.com/128746 |
89 virtual void GetDocuments(const GURL& feed_url, | 95 virtual void GetDocuments(const GURL& feed_url, |
90 int start_changestamp, | 96 int64 start_changestamp, |
91 const std::string& search_query, | 97 const std::string& search_query, |
92 const std::string& directory_resource_id, | 98 const std::string& directory_resource_id, |
93 const GetDataCallback& callback) = 0; | 99 const GetDataCallback& callback) = 0; |
94 | 100 |
95 // Fetches a changelist from |url| with |start_changestamp|, using Drive V2 | |
96 // API. If this URL is empty the call will use the default URL. Specify |url| | |
97 // when pagenated request should be issued. | |
98 // |start_changestamp| specifies the starting point of change list or 0 if | |
99 // all changes are necessary. | |
100 // Upon completion, invokes |callback| with results on calling thread. | |
101 virtual void GetChangelist(const GURL& url, | |
102 int64 start_changestamp, | |
103 const GetDataCallback& callback) = 0; | |
104 | |
105 // Fetches a filelist from |url| with |search_query|, using Drive V2 API. If | |
106 // this URL is empty the call will use the default URL. Specify |url| when | |
107 // pagenated request should be issued. | |
108 // |search_query| specifies query string, whose syntax is described at | |
109 // https://developers.google.com/drive/search-parameters | |
110 virtual void GetFilelist(const GURL& url, | |
111 const std::string& search_query, | |
112 const GetDataCallback& callback) = 0; | |
113 | |
114 // Fetches single entry metadata from server. The entry's resource id equals | 101 // Fetches single entry metadata from server. The entry's resource id equals |
115 // |resource_id|. | 102 // |resource_id|. |
116 // Upon completion, invokes |callback| with results on the calling thread. | 103 // Upon completion, invokes |callback| with results on the calling thread. |
117 virtual void GetDocumentEntry(const std::string& resource_id, | 104 virtual void GetDocumentEntry(const std::string& resource_id, |
118 const GetDataCallback& callback) = 0; | 105 const GetDataCallback& callback) = 0; |
119 | 106 |
120 // Fetches single entry metadata from server. The entry's file id equals | |
121 // |file_id|. | |
122 // Upon completion, invokes |callback| with results on the calling thread. | |
123 // https://developers.google.com/drive/v2/reference/files/get | |
124 virtual void GetFile(const std::string& file_id, | |
125 const GetDataCallback& callback) = 0; | |
126 | |
127 // Gets the account metadata from the server using the default account | 107 // Gets the account metadata from the server using the default account |
128 // metadata URL. Upon completion, invokes |callback| with results on the | 108 // metadata URL. Upon completion, invokes |callback| with results on the |
129 // calling thread. | 109 // calling thread. |
130 virtual void GetAccountMetadata(const GetDataCallback& callback) = 0; | 110 virtual void GetAccountMetadata(const GetDataCallback& callback) = 0; |
131 | 111 |
132 // Gets the About resource from the server for the current account. | 112 // Gets the application information from the server. |
133 // Upon completion, invokes |callback| with results on the calling thread. | 113 // Upon completion, invokes |callback| with results on the calling thread. |
134 // (For Drive V2 API only) | 114 virtual void GetApplicationInfo(const GetDataCallback& callback) = 0; |
135 virtual void GetAboutResource(const GetDataCallback& callback) = 0; | |
136 | |
137 // Gets the application list (For Drive V2 API only). | |
138 virtual void GetApplicationList(const GetDataCallback& callback) = 0; | |
139 | 115 |
140 // Deletes a document identified by its 'self' |url| and |etag|. | 116 // Deletes a document identified by its 'self' |url| and |etag|. |
141 // Upon completion, invokes |callback| with results on the calling thread. | 117 // Upon completion, invokes |callback| with results on the calling thread. |
142 virtual void DeleteDocument(const GURL& document_url, | 118 virtual void DeleteDocument(const GURL& document_url, |
143 const EntryActionCallback& callback) = 0; | 119 const EntryActionCallback& callback) = 0; |
144 | 120 |
145 // Downloads a document identified by its |content_url| in a given |format|. | 121 // Downloads a document identified by its |content_url| in a given |format|. |
146 // Upon completion, invokes |callback| with results on the calling thread. | 122 // Upon completion, invokes |callback| with results on the calling thread. |
147 virtual void DownloadDocument(const FilePath& virtual_path, | 123 virtual void DownloadDocument(const FilePath& virtual_path, |
148 const FilePath& local_cache_path, | 124 const FilePath& local_cache_path, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 187 |
212 // Resumes uploading of a document/file on the calling thread. | 188 // Resumes uploading of a document/file on the calling thread. |
213 virtual void ResumeUpload(const ResumeUploadParams& params, | 189 virtual void ResumeUpload(const ResumeUploadParams& params, |
214 const ResumeUploadCallback& callback) = 0; | 190 const ResumeUploadCallback& callback) = 0; |
215 | 191 |
216 // Authorizes a Drive app with the id |app_id| to open the given document. | 192 // Authorizes a Drive app with the id |app_id| to open the given document. |
217 // Upon completion, invokes |callback| with results on the calling thread. | 193 // Upon completion, invokes |callback| with results on the calling thread. |
218 virtual void AuthorizeApp(const GURL& resource_url, | 194 virtual void AuthorizeApp(const GURL& resource_url, |
219 const std::string& app_id, | 195 const std::string& app_id, |
220 const GetDataCallback& callback) = 0; | 196 const GetDataCallback& callback) = 0; |
221 | |
222 // True if OAuth2 access token is retrieved and believed to be fresh. | |
223 virtual bool HasAccessToken() const = 0; | |
224 | |
225 // True if OAuth2 refresh token is present. | |
226 virtual bool HasRefreshToken() const = 0; | |
227 }; | |
228 | |
229 // This class provides documents feed service calls. | |
230 class DocumentsService : public DocumentsServiceInterface { | |
231 public: | |
232 // DocumentsService is usually owned and created by GDataFileSystem. | |
233 DocumentsService(); | |
234 virtual ~DocumentsService(); | |
235 | |
236 GDataAuthService* auth_service_for_testing(); | |
237 | |
238 // DocumentsServiceInterface Overrides | |
239 virtual void Initialize(Profile* profile) OVERRIDE; | |
240 virtual GDataOperationRegistry* operation_registry() const OVERRIDE; | |
241 virtual void CancelAll() OVERRIDE; | |
242 virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE; | |
243 virtual void GetDocuments(const GURL& feed_url, | |
244 int start_changestamp, | |
245 const std::string& search_query, | |
246 const std::string& directory_resource_id, | |
247 const GetDataCallback& callback) OVERRIDE; | |
248 virtual void GetFilelist(const GURL& url, | |
249 const std::string& search_query, | |
250 const GetDataCallback& callback) OVERRIDE; | |
251 virtual void GetChangelist(const GURL& url, | |
252 int64 start_changestamp, | |
253 const GetDataCallback& callback) OVERRIDE; | |
254 virtual void GetDocumentEntry(const std::string& resource_id, | |
255 const GetDataCallback& callback) OVERRIDE; | |
256 virtual void GetFile(const std::string& file_id, | |
257 const GetDataCallback& callback) OVERRIDE; | |
258 | |
259 virtual void GetAccountMetadata(const GetDataCallback& callback) OVERRIDE; | |
260 virtual void GetAboutResource(const GetDataCallback& callback) OVERRIDE; | |
261 virtual void GetApplicationList(const GetDataCallback& callback) OVERRIDE; | |
262 virtual void DeleteDocument(const GURL& document_url, | |
263 const EntryActionCallback& callback) OVERRIDE; | |
264 virtual void DownloadDocument( | |
265 const FilePath& virtual_path, | |
266 const FilePath& local_cache_path, | |
267 const GURL& content_url, | |
268 DocumentExportFormat format, | |
269 const DownloadActionCallback& callback) OVERRIDE; | |
270 virtual void DownloadFile( | |
271 const FilePath& virtual_path, | |
272 const FilePath& local_cache_path, | |
273 const GURL& content_url, | |
274 const DownloadActionCallback& download_action_callback, | |
275 const GetContentCallback& get_content_callback) OVERRIDE; | |
276 virtual void CopyDocument(const std::string& resource_id, | |
277 const FilePath::StringType& new_name, | |
278 const GetDataCallback& callback) OVERRIDE; | |
279 virtual void RenameResource(const GURL& document_url, | |
280 const FilePath::StringType& new_name, | |
281 const EntryActionCallback& callback) OVERRIDE; | |
282 virtual void AddResourceToDirectory( | |
283 const GURL& parent_content_url, | |
284 const GURL& resource_url, | |
285 const EntryActionCallback& callback) OVERRIDE; | |
286 virtual void RemoveResourceFromDirectory( | |
287 const GURL& parent_content_url, | |
288 const GURL& resource_url, | |
289 const std::string& resource_id, | |
290 const EntryActionCallback& callback) OVERRIDE; | |
291 virtual void CreateDirectory(const GURL& parent_content_url, | |
292 const FilePath::StringType& directory_name, | |
293 const GetDataCallback& callback) OVERRIDE; | |
294 virtual void InitiateUpload(const InitiateUploadParams& params, | |
295 const InitiateUploadCallback& callback) OVERRIDE; | |
296 virtual void ResumeUpload(const ResumeUploadParams& params, | |
297 const ResumeUploadCallback& callback) OVERRIDE; | |
298 virtual void AuthorizeApp(const GURL& resource_url, | |
299 const std::string& app_id, | |
300 const GetDataCallback& callback) OVERRIDE; | |
301 virtual bool HasAccessToken() const OVERRIDE; | |
302 virtual bool HasRefreshToken() const OVERRIDE; | |
303 | |
304 private: | |
305 Profile* profile_; | |
306 | |
307 scoped_ptr<GDataOperationRunner> runner_; | |
308 | |
309 DISALLOW_COPY_AND_ASSIGN(DocumentsService); | |
310 }; | 197 }; |
311 | 198 |
312 } // namespace gdata | 199 } // namespace gdata |
313 | 200 |
314 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | 201 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DOCUMENTS_SERVICE_INTERFACE_H_ |
OLD | NEW |