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_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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 std::string auth_token_; | 186 std::string auth_token_; |
| 187 ObserverList<Observer> observers_; | 187 ObserverList<Observer> observers_; |
| 188 | 188 |
| 189 content::NotificationRegistrar registrar_; | 189 content::NotificationRegistrar registrar_; |
| 190 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; | 190 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; |
| 191 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; | 191 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; |
| 192 | 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); | 193 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 // This class provides documents feed service calls. | 196 // This defines an interface for sharing by DocumentService and |
| 197 class DocumentsService : public GDataAuthService::Observer { | 197 // MockDocumentService so that we can do testing of clients of DocumentService. |
| 198 class DocumentsServiceInterface { | |
| 198 public: | 199 public: |
| 199 // DocumentsService is usually owned and created by GDataFileSystem. | 200 virtual ~DocumentsServiceInterface() {} |
| 200 DocumentsService(); | |
| 201 virtual ~DocumentsService(); | |
| 202 | 201 |
| 203 // Initializes the documents service tied with |profile|. | 202 // Initializes the documents service tied with |profile|. |
| 204 void Initialize(Profile* profile); | 203 virtual void Initialize(Profile* profile) = 0; |
| 205 | 204 |
| 206 // Cancels all in-flight operations. | 205 // Cancels all in-flight operations. |
| 207 void CancelAll(); | 206 virtual void CancelAll() = 0; |
| 208 | 207 |
| 209 // Authenticates the user by fetching the auth token as | 208 // Authenticates the user by fetching the auth token as |
| 210 // needed. |callback| will be run with the error code and the auth | 209 // needed. |callback| will be run with the error code and the auth |
| 211 // token, on the thread this function is run. | 210 // token, on the thread this function is run. |
| 212 // | 211 // |
| 213 // Can be called on any thread. | 212 // Can be called on any thread. |
| 214 void Authenticate(const AuthStatusCallback& callback); | 213 virtual void Authenticate(const AuthStatusCallback& callback) = 0; |
| 215 | 214 |
| 216 // Gets the document feed from |feed_url|. If this URL is empty, the call | 215 // Gets the document feed from |feed_url|. If this URL is empty, the call |
| 217 // will fetch the default ('root') document feed. Upon completion, | 216 // will fetch the default ('root') document feed. Upon completion, |
| 218 // invokes |callback| with results on the calling thread. | 217 // invokes |callback| with results on the calling thread. |
| 219 // | 218 // |
| 220 // Can be called on any thread. | 219 // Can be called on any thread. |
| 221 void GetDocuments(const GURL& feed_url, const GetDataCallback& callback); | 220 virtual void GetDocuments(const GURL& feed_url, |
| 221 const GetDataCallback& callback) = 0; | |
| 222 | 222 |
| 223 // Delete a document identified by its 'self' |url| and |etag|. | 223 // Deletes a document identified by its 'self' |url| and |etag|. |
| 224 // Upon completion, invokes |callback| with results on the calling thread. | 224 // Upon completion, invokes |callback| with results on the calling thread. |
| 225 // | 225 // |
| 226 // Can be called on any thread. | 226 // Can be called on any thread. |
| 227 void DeleteDocument(const GURL& document_url, | 227 virtual void DeleteDocument(const GURL& document_url, |
| 228 const EntryActionCallback& callback); | 228 const EntryActionCallback& callback) = 0; |
| 229 | 229 |
| 230 // Downloads a document identified by its |content_url| in a given |format|. | 230 // Downloads a document identified by its |content_url| in a given |format|. |
| 231 // Upon completion, invokes |callback| with results on the calling thread. | 231 // Upon completion, invokes |callback| with results on the calling thread. |
| 232 // | 232 // |
| 233 // Can be called on any thread. | 233 // Can be called on any thread. |
| 234 void DownloadDocument(const GURL& content_url, | 234 virtual void DownloadDocument(const GURL& content_url, |
| 235 DocumentExportFormat format, | 235 DocumentExportFormat format, |
| 236 const DownloadActionCallback& callback); | 236 const DownloadActionCallback& callback) = 0; |
| 237 | 237 |
| 238 // Creates new collection with |directory_name| under parent directory | 238 // Creates new collection with |directory_name| under parent directory |
| 239 // identified with |parent_content_url|. If |parent_content_url| is empty, | 239 // identified with |parent_content_url|. If |parent_content_url| is empty, |
| 240 // the new collection will be created in the root. Upon completion, | 240 // the new collection will be created in the root. Upon completion, |
| 241 // invokes |callback| and passes newly created entry on the calling thread. | 241 // invokes |callback| and passes newly created entry on the calling thread. |
| 242 // | 242 // |
| 243 // Can be called on any thread. | 243 // Can be called on any thread. |
| 244 void CreateDirectory(const GURL& parent_content_url, | 244 virtual void CreateDirectory(const GURL& parent_content_url, |
| 245 const FilePath::StringType& directory_name, | 245 const FilePath::StringType& directory_name, |
| 246 const GetDataCallback& callback); | 246 const GetDataCallback& callback) = 0; |
| 247 | 247 |
| 248 // Downloads a file identified by its |content_url|. Upon completion, invokes | 248 // Downloads a file identified by its |content_url|. Upon completion, invokes |
| 249 // |callback| with results on the calling thread. | 249 // |callback| with results on the calling thread. |
| 250 // | 250 // |
| 251 // Can be called on any thread. | 251 // Can be called on any thread. |
| 252 void DownloadFile(const GURL& content_url, | 252 virtual void DownloadFile(const GURL& content_url, |
| 253 const DownloadActionCallback& callback); | 253 const DownloadActionCallback& callback) = 0; |
| 254 | 254 |
| 255 // Initiate uploading of a document/file. | 255 // Initiates uploading of a document/file. |
| 256 // | 256 // |
| 257 // Can be called on any thread. | 257 // Can be called on any thread. |
| 258 void InitiateUpload(const InitiateUploadParams& params, | 258 virtual void InitiateUpload(const InitiateUploadParams& params, |
| 259 const InitiateUploadCallback& callback); | 259 const InitiateUploadCallback& callback) = 0; |
| 260 | 260 |
| 261 // Resume uploading of a document/file on the calling thread. | 261 // Resumes uploading of a document/file on the calling thread. |
| 262 // | 262 // |
| 263 // Can be called on any thread. | 263 // Can be called on any thread. |
| 264 void ResumeUpload(const ResumeUploadParams& params, | 264 virtual void ResumeUpload(const ResumeUploadParams& params, |
| 265 const ResumeUploadCallback& callback); | 265 const ResumeUploadCallback& callback) = 0; |
| 266 }; | |
| 267 | |
| 268 // This class provides documents feed service calls. | |
| 269 class DocumentsService | |
| 270 : public DocumentsServiceInterface, | |
| 271 public GDataAuthService::Observer { | |
| 272 public: | |
| 273 // DocumentsService is usually owned and created by GDataFileSystem. | |
| 274 DocumentsService(); | |
| 275 virtual ~DocumentsService(); | |
| 276 | |
| 277 // DocumentsServiceInterface Overrides | |
| 278 virtual void Initialize(Profile* profile) OVERRIDE; | |
| 279 virtual void CancelAll() OVERRIDE; | |
| 280 virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE; | |
| 281 virtual void GetDocuments(const GURL& feed_url, | |
| 282 const GetDataCallback& callback) OVERRIDE; | |
|
zel
2012/03/08 19:14:08
indentation - here an for all methods derived from
| |
| 283 virtual void DeleteDocument(const GURL& document_url, | |
| 284 const EntryActionCallback& callback) OVERRIDE; | |
| 285 virtual void DownloadDocument(const GURL& content_url, | |
| 286 DocumentExportFormat format, | |
| 287 const DownloadActionCallback& callback) OVERRIDE; | |
| 288 virtual void CreateDirectory(const GURL& parent_content_url, | |
| 289 const FilePath::StringType& directory_name, | |
| 290 const GetDataCallback& callback) OVERRIDE; | |
| 291 virtual void DownloadFile(const GURL& content_url, | |
| 292 const DownloadActionCallback& callback) OVERRIDE; | |
| 293 virtual void InitiateUpload(const InitiateUploadParams& params, | |
| 294 const InitiateUploadCallback& callback) OVERRIDE; | |
| 295 virtual void ResumeUpload(const ResumeUploadParams& params, | |
| 296 const ResumeUploadCallback& callback) OVERRIDE; | |
| 266 | 297 |
| 267 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); } | 298 GDataAuthService* gdata_auth_service() { return gdata_auth_service_.get(); } |
| 268 | 299 |
| 269 private: | 300 private: |
| 270 // GDataAuthService::Observer override. | 301 // GDataAuthService::Observer override. |
| 271 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; | 302 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; |
| 272 | 303 |
| 273 // Submits an operation implementing the GDataOperationInterface interface | 304 // Submits an operation implementing the GDataOperationInterface interface |
| 274 // to run on the UI thread, and makes the operation retry upon authentication | 305 // to run on the UI thread, and makes the operation retry upon authentication |
| 275 // failures by calling back to DocumentsService::RetryOperation. | 306 // failures by calling back to DocumentsService::RetryOperation. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 302 scoped_ptr<GDataOperationRegistry> operation_registry_; | 333 scoped_ptr<GDataOperationRegistry> operation_registry_; |
| 303 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_; | 334 base::WeakPtrFactory<DocumentsService> weak_ptr_factory_; |
| 304 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_; | 335 base::WeakPtr<DocumentsService> weak_ptr_bound_to_ui_thread_; |
| 305 | 336 |
| 306 DISALLOW_COPY_AND_ASSIGN(DocumentsService); | 337 DISALLOW_COPY_AND_ASSIGN(DocumentsService); |
| 307 }; | 338 }; |
| 308 | 339 |
| 309 } // namespace gdata | 340 } // namespace gdata |
| 310 | 341 |
| 311 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ | 342 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_H_ |
| OLD | NEW |