| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "sync/api/attachments/attachment.h" | 12 #include "sync/api/attachments/attachment.h" |
| 13 #include "sync/base/sync_export.h" | 13 #include "sync/base/sync_export.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 | 16 |
| 17 class AttachmentStore; | |
| 18 class SyncData; | 17 class SyncData; |
| 19 | 18 |
| 20 // AttachmentService is responsible for managing a model type's attachments. | 19 // AttachmentService is responsible for managing a model type's attachments. |
| 21 // | 20 // |
| 22 // Outside of sync code, AttachmentService shouldn't be used directly. Instead | 21 // Outside of sync code, AttachmentService shouldn't be used directly. Instead |
| 23 // use the functionality provided by SyncData and SyncChangeProcessor. | 22 // use the functionality provided by SyncData and SyncChangeProcessor. |
| 24 // | 23 // |
| 25 // Destroying this object does not necessarily cancel outstanding async | 24 // Destroying this object does not necessarily cancel outstanding async |
| 26 // operations. If you need cancel like semantics, use WeakPtr in the callbacks. | 25 // operations. If you need cancel like semantics, use WeakPtr in the callbacks. |
| 27 class SYNC_EXPORT AttachmentService { | 26 class SYNC_EXPORT AttachmentService { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 | 37 |
| 39 // The result of a DropAttachments operation. | 38 // The result of a DropAttachments operation. |
| 40 enum DropResult { | 39 enum DropResult { |
| 41 DROP_SUCCESS, // No error, all attachments dropped. | 40 DROP_SUCCESS, // No error, all attachments dropped. |
| 42 DROP_UNSPECIFIED_ERROR, // An unspecified error occurred. Some or all | 41 DROP_UNSPECIFIED_ERROR, // An unspecified error occurred. Some or all |
| 43 // attachments may not have been dropped. | 42 // attachments may not have been dropped. |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 typedef base::Callback<void(const DropResult&)> DropCallback; | 45 typedef base::Callback<void(const DropResult&)> DropCallback; |
| 47 | 46 |
| 47 // The result of a StoreAttachments operation. |
| 48 enum StoreResult { |
| 49 STORE_SUCCESS, // No error, all attachments stored (at least |
| 50 // locally). |
| 51 STORE_UNSPECIFIED_ERROR, // An unspecified error occurred. Some or all |
| 52 // attachments may not have been stored. |
| 53 }; |
| 54 |
| 55 typedef base::Callback<void(const StoreResult&)> StoreCallback; |
| 56 |
| 48 // An interface that embedder code implements to be notified about different | 57 // An interface that embedder code implements to be notified about different |
| 49 // events that originate from AttachmentService. | 58 // events that originate from AttachmentService. |
| 50 // This interface will be called from the same thread AttachmentService was | 59 // This interface will be called from the same thread AttachmentService was |
| 51 // created and called. | 60 // created and called. |
| 52 class Delegate { | 61 class Delegate { |
| 53 public: | 62 public: |
| 54 virtual ~Delegate() {} | 63 virtual ~Delegate() {} |
| 55 | 64 |
| 56 // Attachment is uploaded to server and attachment_id is updated with server | 65 // Attachment is uploaded to server and attachment_id is updated with server |
| 57 // url. | 66 // url. |
| 58 virtual void OnAttachmentUploaded(const AttachmentId& attachment_id) = 0; | 67 virtual void OnAttachmentUploaded(const AttachmentId& attachment_id) = 0; |
| 59 }; | 68 }; |
| 60 | 69 |
| 61 AttachmentService(); | 70 AttachmentService(); |
| 62 virtual ~AttachmentService(); | 71 virtual ~AttachmentService(); |
| 63 | 72 |
| 64 // Return a pointer to the AttachmentStore owned by this object. | |
| 65 // | |
| 66 // May return NULL. | |
| 67 virtual AttachmentStore* GetStore() = 0; | |
| 68 | |
| 69 // See SyncData::GetOrDownloadAttachments. | 73 // See SyncData::GetOrDownloadAttachments. |
| 70 virtual void GetOrDownloadAttachments( | 74 virtual void GetOrDownloadAttachments( |
| 71 const AttachmentIdList& attachment_ids, | 75 const AttachmentIdList& attachment_ids, |
| 72 const GetOrDownloadCallback& callback) = 0; | 76 const GetOrDownloadCallback& callback) = 0; |
| 73 | 77 |
| 74 // See SyncData::DropAttachments. | 78 // See SyncData::DropAttachments. |
| 75 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | 79 virtual void DropAttachments(const AttachmentIdList& attachment_ids, |
| 76 const DropCallback& callback) = 0; | 80 const DropCallback& callback) = 0; |
| 77 | 81 |
| 78 // Schedules the attachments identified by |attachment_ids| to be uploaded to | 82 // Store |attachments| on device and (eventually) upload them to the server. |
| 79 // the server. | |
| 80 // | 83 // |
| 81 // Assumes the attachments are already in the attachment store. | 84 // Invokes |callback| once the attachments have been written to device |
| 82 // | 85 // storage. |
| 83 // A request to upload attachments is persistent in that uploads will be | 86 virtual void StoreAttachments(const AttachmentList& attachments, |
| 84 // automatically retried if transient errors occur. | 87 const StoreCallback& callback) = 0; |
| 85 // | |
| 86 // A request to upload attachments does not persist across restarts of Chrome. | |
| 87 // | |
| 88 // Invokes OnAttachmentUploaded on the Delegate (if provided). | |
| 89 virtual void UploadAttachments(const AttachmentIdSet& attachment_ids) = 0; | |
| 90 }; | 88 }; |
| 91 | 89 |
| 92 } // namespace syncer | 90 } // namespace syncer |
| 93 | 91 |
| 94 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ | 92 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_ |
| OLD | NEW |