| 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_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 XLS, // Excel (spreadsheets only). | 50 XLS, // Excel (spreadsheets only). |
| 51 CSV, // Excel (spreadsheets only). | 51 CSV, // Excel (spreadsheets only). |
| 52 ODS, // Open Document Spreadsheet (spreadsheets only). | 52 ODS, // Open Document Spreadsheet (spreadsheets only). |
| 53 TSV, // Tab Separated Value (spreadsheets only). Only the first worksheet | 53 TSV, // Tab Separated Value (spreadsheets only). Only the first worksheet |
| 54 // is returned in TSV by default. | 54 // is returned in TSV by default. |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Different callback types for various functionalities in DocumentsService. | 57 // Different callback types for various functionalities in DocumentsService. |
| 58 typedef base::Callback<void(GDataErrorCode error, | 58 typedef base::Callback<void(GDataErrorCode error, |
| 59 const std::string& token)> AuthStatusCallback; | 59 const std::string& token)> AuthStatusCallback; |
| 60 |
| 61 // Note: feed_data argument should be passed using base::Passed(&feed_data), not |
| 62 // feed_data.Pass(). |
| 60 typedef base::Callback<void(GDataErrorCode error, | 63 typedef base::Callback<void(GDataErrorCode error, |
| 61 scoped_ptr<base::Value> feed_data)> GetDataCallback; | 64 scoped_ptr<base::Value> feed_data)> GetDataCallback; |
| 65 |
| 62 typedef base::Callback<void(GDataErrorCode error, | 66 typedef base::Callback<void(GDataErrorCode error, |
| 63 const GURL& document_url)> EntryActionCallback; | 67 const GURL& document_url)> EntryActionCallback; |
| 64 typedef base::Callback<void(GDataErrorCode error, | 68 typedef base::Callback<void(GDataErrorCode error, |
| 65 const GURL& content_url, | 69 const GURL& content_url, |
| 66 const FilePath& temp_file)> DownloadActionCallback; | 70 const FilePath& temp_file)> DownloadActionCallback; |
| 67 typedef base::Callback<void(GDataErrorCode error, | 71 typedef base::Callback<void(GDataErrorCode error, |
| 68 const GURL& upload_location)> | 72 const GURL& upload_location)> |
| 69 InitiateUploadCallback; | 73 InitiateUploadCallback; |
| 70 typedef base::Callback<void(GDataErrorCode error, | 74 typedef base::Callback<void(GDataErrorCode error, |
| 71 int64 start_range_received, | 75 int64 start_range_received, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 std::string auth_token_; | 190 std::string auth_token_; |
| 187 ObserverList<Observer> observers_; | 191 ObserverList<Observer> observers_; |
| 188 | 192 |
| 189 content::NotificationRegistrar registrar_; | 193 content::NotificationRegistrar registrar_; |
| 190 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; | 194 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; |
| 191 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; | 195 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; |
| 192 | 196 |
| 193 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); | 197 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); |
| 194 }; | 198 }; |
| 195 | 199 |
| 196 // This class provides documents feed service calls. | 200 // This defines an interface for sharing by DocumentService and |
| 197 class DocumentsService : public GDataAuthService::Observer { | 201 // MockDocumentService so that we can do testing of clients of DocumentService. |
| 202 class DocumentsServiceInterface { |
| 198 public: | 203 public: |
| 199 // DocumentsService is usually owned and created by GDataFileSystem. | 204 virtual ~DocumentsServiceInterface() {} |
| 200 DocumentsService(); | |
| 201 virtual ~DocumentsService(); | |
| 202 | 205 |
| 203 // Initializes the documents service tied with |profile|. | 206 // Initializes the documents service tied with |profile|. |
| 204 void Initialize(Profile* profile); | 207 virtual void Initialize(Profile* profile) = 0; |
| 205 | 208 |
| 206 // Cancels all in-flight operations. | 209 // Cancels all in-flight operations. |
| 207 void CancelAll(); | 210 virtual void CancelAll() = 0; |
| 208 | 211 |
| 209 // Authenticates the user by fetching the auth token as | 212 // Authenticates the user by fetching the auth token as |
| 210 // needed. |callback| will be run with the error code and the auth | 213 // needed. |callback| will be run with the error code and the auth |
| 211 // token, on the thread this function is run. | 214 // token, on the thread this function is run. |
| 212 // | 215 // |
| 213 // Can be called on any thread. | 216 // Can be called on any thread. |
| 214 void Authenticate(const AuthStatusCallback& callback); | 217 virtual void Authenticate(const AuthStatusCallback& callback) = 0; |
| 215 | 218 |
| 216 // Gets the document feed from |feed_url|. If this URL is empty, the call | 219 // Gets the document feed from |feed_url|. If this URL is empty, the call |
| 217 // will fetch the default ('root') document feed. Upon completion, | 220 // will fetch the default ('root') document feed. Upon completion, |
| 218 // invokes |callback| with results on the calling thread. | 221 // invokes |callback| with results on the calling thread. |
| 219 // | 222 // |
| 220 // Can be called on any thread. | 223 // Can be called on any thread. |
| 221 void GetDocuments(const GURL& feed_url, const GetDataCallback& callback); | 224 virtual void GetDocuments(const GURL& feed_url, |
| 225 const GetDataCallback& callback) = 0; |
| 222 | 226 |
| 223 // Delete a document identified by its 'self' |url| and |etag|. | 227 // Deletes a document identified by its 'self' |url| and |etag|. |
| 224 // Upon completion, invokes |callback| with results on the calling thread. | 228 // Upon completion, invokes |callback| with results on the calling thread. |
| 225 // | 229 // |
| 226 // Can be called on any thread. | 230 // Can be called on any thread. |
| 227 void DeleteDocument(const GURL& document_url, | 231 virtual void DeleteDocument(const GURL& document_url, |
| 228 const EntryActionCallback& callback); | 232 const EntryActionCallback& callback) = 0; |
| 229 | 233 |
| 230 // Downloads a document identified by its |content_url| in a given |format|. | 234 // Downloads a document identified by its |content_url| in a given |format|. |
| 231 // Upon completion, invokes |callback| with results on the calling thread. | 235 // Upon completion, invokes |callback| with results on the calling thread. |
| 232 // | 236 // |
| 233 // Can be called on any thread. | 237 // Can be called on any thread. |
| 234 void DownloadDocument(const GURL& content_url, | 238 virtual void DownloadDocument(const GURL& content_url, |
| 235 DocumentExportFormat format, | 239 DocumentExportFormat format, |
| 236 const DownloadActionCallback& callback); | 240 const DownloadActionCallback& callback) = 0; |
| 237 | 241 |
| 238 // Creates new collection with |directory_name| under parent directory | 242 // Creates new collection with |directory_name| under parent directory |
| 239 // identified with |parent_content_url|. If |parent_content_url| is empty, | 243 // identified with |parent_content_url|. If |parent_content_url| is empty, |
| 240 // the new collection will be created in the root. Upon completion, | 244 // the new collection will be created in the root. Upon completion, |
| 241 // invokes |callback| and passes newly created entry on the calling thread. | 245 // invokes |callback| and passes newly created entry on the calling thread. |
| 242 // | 246 // |
| 243 // Can be called on any thread. | 247 // Can be called on any thread. |
| 244 void CreateDirectory(const GURL& parent_content_url, | 248 virtual void CreateDirectory(const GURL& parent_content_url, |
| 245 const FilePath::StringType& directory_name, | 249 const FilePath::StringType& directory_name, |
| 246 const GetDataCallback& callback); | 250 const GetDataCallback& callback) = 0; |
| 247 | 251 |
| 248 // Downloads a file identified by its |content_url|. Upon completion, invokes | 252 // Downloads a file identified by its |content_url|. Upon completion, invokes |
| 249 // |callback| with results on the calling thread. | 253 // |callback| with results on the calling thread. |
| 250 // | 254 // |
| 251 // Can be called on any thread. | 255 // Can be called on any thread. |
| 252 void DownloadFile(const GURL& content_url, | 256 virtual void DownloadFile(const GURL& content_url, |
| 253 const DownloadActionCallback& callback); | 257 const DownloadActionCallback& callback) = 0; |
| 254 | 258 |
| 255 // Initiate uploading of a document/file. | 259 // Initiates uploading of a document/file. |
| 256 // | 260 // |
| 257 // Can be called on any thread. | 261 // Can be called on any thread. |
| 258 void InitiateUpload(const InitiateUploadParams& params, | 262 virtual void InitiateUpload(const InitiateUploadParams& params, |
| 259 const InitiateUploadCallback& callback); | 263 const InitiateUploadCallback& callback) = 0; |
| 260 | 264 |
| 261 // Resume uploading of a document/file on the calling thread. | 265 // Resumes uploading of a document/file on the calling thread. |
| 262 // | 266 // |
| 263 // Can be called on any thread. | 267 // Can be called on any thread. |
| 264 void ResumeUpload(const ResumeUploadParams& params, | 268 virtual void ResumeUpload(const ResumeUploadParams& params, |
| 265 const ResumeUploadCallback& callback); | 269 const ResumeUploadCallback& callback) = 0; |
| 270 }; |
| 271 |
| 272 // This class provides documents feed service calls. |
| 273 class DocumentsService |
| 274 : public DocumentsServiceInterface, |
| 275 public GDataAuthService::Observer { |
| 276 public: |
| 277 // DocumentsService is usually owned and created by GDataFileSystem. |
| 278 DocumentsService(); |
| 279 virtual ~DocumentsService(); |
| 280 |
| 281 // DocumentsServiceInterface Overrides |
| 282 virtual void Initialize(Profile* profile) OVERRIDE; |
| 283 virtual void CancelAll() OVERRIDE; |
| 284 virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE; |
| 285 virtual void GetDocuments(const GURL& feed_url, |
| 286 const GetDataCallback& callback) OVERRIDE; |
| 287 virtual void DeleteDocument(const GURL& document_url, |
| 288 const EntryActionCallback& callback) OVERRIDE; |
| 289 virtual void DownloadDocument( |
| 290 const GURL& content_url, |
| 291 DocumentExportFormat format, |
| 292 const DownloadActionCallback& callback) OVERRIDE; |
| 293 virtual void CreateDirectory(const GURL& parent_content_url, |
| 294 const FilePath::StringType& directory_name, |
| 295 const GetDataCallback& callback) OVERRIDE; |
| 296 virtual void DownloadFile(const GURL& content_url, |
| 297 const DownloadActionCallback& callback) OVERRIDE; |
| 298 virtual void InitiateUpload(const InitiateUploadParams& params, |
| 299 const InitiateUploadCallback& callback) OVERRIDE; |
| 300 virtual void ResumeUpload(const ResumeUploadParams& params, |
| 301 const ResumeUploadCallback& callback) OVERRIDE; |
| 266 | 302 |
| 267 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); } | 303 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); } |
| 268 | 304 |
| 269 private: | 305 private: |
| 270 // GDataAuthService::Observer override. | 306 // GDataAuthService::Observer override. |
| 271 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; | 307 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; |
| 272 | 308 |
| 273 // Submits an operation implementing the GDataOperationInterface interface | 309 // Submits an operation implementing the GDataOperationInterface interface |
| 274 // to run on the UI thread, and makes the operation retry upon authentication | 310 // to run on the UI thread, and makes the operation retry upon authentication |
| 275 // failures by calling back to DocumentsService::RetryOperation. | 311 // failures by calling back to DocumentsService::RetryOperation. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 302 scoped_ptr<GDataOperationRegistry> operation_registry_; | 338 scoped_ptr<GDataOperationRegistry> operation_registry_; |
| 303 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_; | 339 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_; |
| 304 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_; | 340 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_; |
| 305 | 341 |
| 306 DISALLOW_COPY_AND_ASSIGN(DocumentsService); | 342 DISALLOW_COPY_AND_ASSIGN(DocumentsService); |
| 307 }; | 343 }; |
| 308 | 344 |
| 309 } // namespace gdata | 345 } // namespace gdata |
| 310 | 346 |
| 311 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ | 347 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ |
| OLD | NEW |