Chromium Code Reviews| 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. |
| 56 class DocumentsServiceInterface { | 49 class DocumentsServiceInterface { |
|
satorux1
2012/08/17 12:05:48
DocumentsServiceInterface is probably not a good n
kochi
2012/08/20 09:17:30
Looks like changing so touches many files and it w
| |
| 57 public: | 50 public: |
| 58 virtual ~DocumentsServiceInterface() {} | 51 virtual ~DocumentsServiceInterface() {} |
| 59 | 52 |
| 53 // Common service: | |
| 54 | |
| 60 // Initializes the documents service tied with |profile|. | 55 // Initializes the documents service tied with |profile|. |
| 61 virtual void Initialize(Profile* profile) = 0; | 56 virtual void Initialize(Profile* profile) = 0; |
| 62 | 57 |
| 63 // Retrieves the operation registry. | 58 // Retrieves the operation registry. |
| 64 virtual GDataOperationRegistry* operation_registry() const = 0; | 59 virtual GDataOperationRegistry* operation_registry() const = 0; |
| 65 | 60 |
| 66 // Cancels all in-flight operations. | 61 // Cancels all in-flight operations. |
| 67 virtual void CancelAll() = 0; | 62 virtual void CancelAll() = 0; |
| 68 | 63 |
| 64 // Authentication service: | |
| 65 | |
| 69 // Authenticates the user by fetching the auth token as | 66 // Authenticates the user by fetching the auth token as |
| 70 // needed. |callback| will be run with the error code and the auth | 67 // needed. |callback| will be run with the error code and the auth |
| 71 // token, on the thread this function is run. | 68 // token, on the thread this function is run. |
| 72 virtual void Authenticate(const AuthStatusCallback& callback) = 0; | 69 virtual void Authenticate(const AuthStatusCallback& callback) = 0; |
| 73 | 70 |
| 71 // True if OAuth2 access token is retrieved and believed to be fresh. | |
| 72 virtual bool HasAccessToken() const = 0; | |
| 73 | |
| 74 // True if OAuth2 refresh token is present. | |
| 75 virtual bool HasRefreshToken() const = 0; | |
| 76 | |
| 77 // Document access: | |
| 78 | |
| 74 // Fetches the document feed from |feed_url| with |start_changestamp|. If this | 79 // 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. | 80 // 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. | 81 // |start_changestamp| specifies the starting point from change feeds only. |
| 77 // Value different than 0, it would trigger delta feed fetching. | 82 // Value different than 0, it would trigger delta feed fetching. |
| 78 // | 83 // |
| 79 // |search_query| specifies search query to be sent to the server. It will be | 84 // |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, | 85 // used only if |start_changestamp| is 0. If empty string is passed, |
| 81 // |search_query| is ignored. | 86 // |search_query| is ignored. |
| 82 // | 87 // |
| 83 // |directory_resource_id| specifies the directory from which documents are | 88 // |directory_resource_id| specifies the directory from which documents are |
| 84 // fetched. It will be used only if |start_changestamp| is 0. If empty | 89 // fetched. It will be used only if |start_changestamp| is 0. If empty |
| 85 // string is passed, |directory_resource_id| is ignored. | 90 // string is passed, |directory_resource_id| is ignored. |
| 86 // | 91 // |
| 87 // Upon completion, invokes |callback| with results on the calling thread. | 92 // Upon completion, invokes |callback| with results on the calling thread. |
| 88 // TODO(satorux): Refactor this function: crbug.com/128746 | 93 // TODO(satorux): Refactor this function: crbug.com/128746 |
| 89 virtual void GetDocuments(const GURL& feed_url, | 94 virtual void GetDocuments(const GURL& feed_url, |
| 90 int start_changestamp, | 95 int64 start_changestamp, |
| 91 const std::string& search_query, | 96 const std::string& search_query, |
| 92 const std::string& directory_resource_id, | 97 const std::string& directory_resource_id, |
| 93 const GetDataCallback& callback) = 0; | 98 const GetDataCallback& callback) = 0; |
| 94 | 99 |
| 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 | 100 // Fetches single entry metadata from server. The entry's resource id equals |
| 115 // |resource_id|. | 101 // |resource_id|. |
| 116 // Upon completion, invokes |callback| with results on the calling thread. | 102 // Upon completion, invokes |callback| with results on the calling thread. |
| 117 virtual void GetDocumentEntry(const std::string& resource_id, | 103 virtual void GetDocumentEntry(const std::string& resource_id, |
| 118 const GetDataCallback& callback) = 0; | 104 const GetDataCallback& callback) = 0; |
| 119 | 105 |
| 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 | 106 // Gets the account metadata from the server using the default account |
| 128 // metadata URL. Upon completion, invokes |callback| with results on the | 107 // metadata URL. Upon completion, invokes |callback| with results on the |
| 129 // calling thread. | 108 // calling thread. |
| 130 virtual void GetAccountMetadata(const GetDataCallback& callback) = 0; | 109 virtual void GetAccountMetadata(const GetDataCallback& callback) = 0; |
| 131 | 110 |
| 132 // Gets the About resource from the server for the current account. | 111 // Gets the application information from the server. |
| 133 // Upon completion, invokes |callback| with results on the calling thread. | 112 // Upon completion, invokes |callback| with results on the calling thread. |
| 134 // (For Drive V2 API only) | 113 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 | 114 |
| 140 // Deletes a document identified by its 'self' |url| and |etag|. | 115 // Deletes a document identified by its 'self' |url| and |etag|. |
| 141 // Upon completion, invokes |callback| with results on the calling thread. | 116 // Upon completion, invokes |callback| with results on the calling thread. |
| 142 virtual void DeleteDocument(const GURL& document_url, | 117 virtual void DeleteDocument(const GURL& document_url, |
| 143 const EntryActionCallback& callback) = 0; | 118 const EntryActionCallback& callback) = 0; |
| 144 | 119 |
| 145 // Downloads a document identified by its |content_url| in a given |format|. | 120 // Downloads a document identified by its |content_url| in a given |format|. |
| 146 // Upon completion, invokes |callback| with results on the calling thread. | 121 // Upon completion, invokes |callback| with results on the calling thread. |
| 147 virtual void DownloadDocument(const FilePath& virtual_path, | 122 virtual void DownloadDocument(const FilePath& virtual_path, |
| 148 const FilePath& local_cache_path, | 123 const FilePath& local_cache_path, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 186 |
| 212 // Resumes uploading of a document/file on the calling thread. | 187 // Resumes uploading of a document/file on the calling thread. |
| 213 virtual void ResumeUpload(const ResumeUploadParams& params, | 188 virtual void ResumeUpload(const ResumeUploadParams& params, |
| 214 const ResumeUploadCallback& callback) = 0; | 189 const ResumeUploadCallback& callback) = 0; |
| 215 | 190 |
| 216 // Authorizes a Drive app with the id |app_id| to open the given document. | 191 // 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. | 192 // Upon completion, invokes |callback| with results on the calling thread. |
| 218 virtual void AuthorizeApp(const GURL& resource_url, | 193 virtual void AuthorizeApp(const GURL& resource_url, |
| 219 const std::string& app_id, | 194 const std::string& app_id, |
| 220 const GetDataCallback& callback) = 0; | 195 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 }; | 196 }; |
| 311 | 197 |
| 312 } // namespace gdata | 198 } // namespace gdata |
| 313 | 199 |
| 314 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | 200 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DOCUMENTS_SERVICE_INTERFACE_H_ |
| OLD | NEW |