| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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; | |
| 19 | |
| 20 namespace gdata { | |
| 21 | |
| 22 class GDataOperationInterface; | |
| 23 class GDataOperationRegistry; | |
| 24 class GDataOperationRunner; | |
| 25 | |
| 26 // Document export format. | |
| 27 enum DocumentExportFormat { | |
| 28 PDF, // Portable Document Format. (all documents) | |
| 29 PNG, // Portable Networks Graphic Image Format (all documents) | |
| 30 HTML, // HTML Format (text documents and spreadsheets). | |
| 31 TXT, // Text file (text documents and presentations). | |
| 32 DOC, // Word (text documents only). | |
| 33 ODT, // Open Document Format (text documents only). | |
| 34 RTF, // Rich Text Format (text documents only). | |
| 35 ZIP, // ZIP archive (text documents only). Contains the images (if any) | |
| 36 // used in the document as well as a .html file containing the | |
| 37 // document's text. | |
| 38 JPEG, // JPEG (drawings only). | |
| 39 SVG, // Scalable Vector Graphics Image Format (drawings only). | |
| 40 PPT, // Powerpoint (presentations only). | |
| 41 XLS, // Excel (spreadsheets only). | |
| 42 CSV, // Excel (spreadsheets only). | |
| 43 ODS, // Open Document Spreadsheet (spreadsheets only). | |
| 44 TSV, // Tab Separated Value (spreadsheets only). Only the first worksheet | |
| 45 // is returned in TSV by default. | |
| 46 }; | |
| 47 | |
| 48 // This defines an interface for sharing by DocumentService and | |
| 49 // MockDocumentService so that we can do testing of clients of DocumentService. | |
| 50 // | |
| 51 // All functions must be called on UI thread. DocumentService is built on top | |
| 52 // of URLFetcher that runs on UI thread. | |
| 53 // | |
| 54 // TODO(zel,benchan): Make the terminology/naming convention (e.g. file vs | |
| 55 // document vs resource, directory vs collection) more consistent and precise. | |
| 56 class DocumentsServiceInterface { | |
| 57 public: | |
| 58 virtual ~DocumentsServiceInterface() {} | |
| 59 | |
| 60 // Initializes the documents service tied with |profile|. | |
| 61 virtual void Initialize(Profile* profile) = 0; | |
| 62 | |
| 63 // Retrieves the operation registry. | |
| 64 virtual GDataOperationRegistry* operation_registry() const = 0; | |
| 65 | |
| 66 // Cancels all in-flight operations. | |
| 67 virtual void CancelAll() = 0; | |
| 68 | |
| 69 // Authenticates the user by fetching the auth token as | |
| 70 // needed. |callback| will be run with the error code and the auth | |
| 71 // token, on the thread this function is run. | |
| 72 virtual void Authenticate(const AuthStatusCallback& callback) = 0; | |
| 73 | |
| 74 // 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. | |
| 76 // |start_changestamp| specifies the starting point from change feeds only. | |
| 77 // Value different than 0, it would trigger delta feed fetching. | |
| 78 // | |
| 79 // |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, | |
| 81 // |search_query| is ignored. | |
| 82 // | |
| 83 // |directory_resource_id| specifies the directory from which documents are | |
| 84 // fetched. It will be used only if |start_changestamp| is 0. If empty | |
| 85 // string is passed, |directory_resource_id| is ignored. | |
| 86 // | |
| 87 // Upon completion, invokes |callback| with results on the calling thread. | |
| 88 // TODO(satorux): Refactor this function: crbug.com/128746 | |
| 89 virtual void GetDocuments(const GURL& feed_url, | |
| 90 int start_changestamp, | |
| 91 const std::string& search_query, | |
| 92 const std::string& directory_resource_id, | |
| 93 const GetDataCallback& callback) = 0; | |
| 94 | |
| 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 | |
| 115 // |resource_id|. | |
| 116 // Upon completion, invokes |callback| with results on the calling thread. | |
| 117 virtual void GetDocumentEntry(const std::string& resource_id, | |
| 118 const GetDataCallback& callback) = 0; | |
| 119 | |
| 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 | |
| 128 // metadata URL. Upon completion, invokes |callback| with results on the | |
| 129 // calling thread. | |
| 130 virtual void GetAccountMetadata(const GetDataCallback& callback) = 0; | |
| 131 | |
| 132 // Gets the About resource from the server for the current account. | |
| 133 // Upon completion, invokes |callback| with results on the calling thread. | |
| 134 // (For Drive V2 API only) | |
| 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 | |
| 140 // Deletes a document identified by its 'self' |url| and |etag|. | |
| 141 // Upon completion, invokes |callback| with results on the calling thread. | |
| 142 virtual void DeleteDocument(const GURL& document_url, | |
| 143 const EntryActionCallback& callback) = 0; | |
| 144 | |
| 145 // Downloads a document identified by its |content_url| in a given |format|. | |
| 146 // Upon completion, invokes |callback| with results on the calling thread. | |
| 147 virtual void DownloadDocument(const FilePath& virtual_path, | |
| 148 const FilePath& local_cache_path, | |
| 149 const GURL& content_url, | |
| 150 DocumentExportFormat format, | |
| 151 const DownloadActionCallback& callback) = 0; | |
| 152 | |
| 153 // Makes a copy of a document identified by its |resource_id|. | |
| 154 // The copy is named as the UTF-8 encoded |new_name| and is not added to any | |
| 155 // collection. Use AddResourceToDirectory() to add the copy to a collection | |
| 156 // when needed. Upon completion, invokes |callback| with results on the | |
| 157 // calling thread. | |
| 158 virtual void CopyDocument(const std::string& resource_id, | |
| 159 const FilePath::StringType& new_name, | |
| 160 const GetDataCallback& callback) = 0; | |
| 161 | |
| 162 // Renames a document or collection identified by its 'self' link | |
| 163 // |document_url| to the UTF-8 encoded |new_name|. Upon completion, | |
| 164 // invokes |callback| with results on the calling thread. | |
| 165 virtual void RenameResource(const GURL& resource_url, | |
| 166 const FilePath::StringType& new_name, | |
| 167 const EntryActionCallback& callback) = 0; | |
| 168 | |
| 169 // Adds a resource (document, file, or collection) identified by its | |
| 170 // 'self' link |resource_url| to a collection with a content link | |
| 171 // |parent_content_url|. Upon completion, invokes |callback| with | |
| 172 // results on the calling thread. | |
| 173 virtual void AddResourceToDirectory(const GURL& parent_content_url, | |
| 174 const GURL& resource_url, | |
| 175 const EntryActionCallback& callback) = 0; | |
| 176 | |
| 177 // Removes a resource (document, file, collection) identified by its | |
| 178 // 'self' link |resource_url| from a collection with a content link | |
| 179 // |parent_content_url|. Upon completion, invokes |callback| with | |
| 180 // results on the calling thread. | |
| 181 virtual void RemoveResourceFromDirectory( | |
| 182 const GURL& parent_content_url, | |
| 183 const GURL& resource_url, | |
| 184 const std::string& resource_id, | |
| 185 const EntryActionCallback& callback) = 0; | |
| 186 | |
| 187 // Creates new collection with |directory_name| under parent directory | |
| 188 // identified with |parent_content_url|. If |parent_content_url| is empty, | |
| 189 // the new collection will be created in the root. Upon completion, | |
| 190 // invokes |callback| and passes newly created entry on the calling thread. | |
| 191 virtual void CreateDirectory(const GURL& parent_content_url, | |
| 192 const FilePath::StringType& directory_name, | |
| 193 const GetDataCallback& callback) = 0; | |
| 194 | |
| 195 // Downloads a file identified by its |content_url|. The downloaded file will | |
| 196 // be stored at |local_cache_path| location. Upon completion, invokes | |
| 197 // |download_action_callback| with results on the calling thread. | |
| 198 // If |get_content_callback| is not empty, | |
| 199 // URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in | |
| 200 // turn invoke |get_content_callback| on the calling thread. | |
| 201 virtual void DownloadFile( | |
| 202 const FilePath& virtual_path, | |
| 203 const FilePath& local_cache_path, | |
| 204 const GURL& content_url, | |
| 205 const DownloadActionCallback& download_action_callback, | |
| 206 const GetContentCallback& get_content_callback) = 0; | |
| 207 | |
| 208 // Initiates uploading of a document/file. | |
| 209 virtual void InitiateUpload(const InitiateUploadParams& params, | |
| 210 const InitiateUploadCallback& callback) = 0; | |
| 211 | |
| 212 // Resumes uploading of a document/file on the calling thread. | |
| 213 virtual void ResumeUpload(const ResumeUploadParams& params, | |
| 214 const ResumeUploadCallback& callback) = 0; | |
| 215 | |
| 216 // 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. | |
| 218 virtual void AuthorizeApp(const GURL& resource_url, | |
| 219 const std::string& app_id, | |
| 220 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 }; | |
| 311 | |
| 312 } // namespace gdata | |
| 313 | |
| 314 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOCUMENTS_SERVICE_H_ | |
| OLD | NEW |