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