Support Promise<T> syntax in the IDL parser.
[chromium-blink-merge.git] / sync / internal_api / public / attachments / attachment_service.h
blob758f960a659b92a6c33fd7518ef6d98b68e7de9b
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
3 // found in the LICENSE file.
5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "sync/api/attachments/attachment.h"
13 #include "sync/base/sync_export.h"
15 namespace syncer {
17 class AttachmentStore;
18 class SyncData;
20 // AttachmentService is responsible for managing a model type's attachments.
22 // Outside of sync code, AttachmentService shouldn't be used directly. Instead
23 // use the functionality provided by SyncData and SyncChangeProcessor.
25 // Destroying this object does not necessarily cancel outstanding async
26 // operations. If you need cancel like semantics, use WeakPtr in the callbacks.
27 class SYNC_EXPORT AttachmentService {
28 public:
29 // The result of a GetOrDownloadAttachments operation.
30 enum GetOrDownloadResult {
31 GET_SUCCESS, // No error, all attachments returned.
32 GET_UNSPECIFIED_ERROR, // An unspecified error occurred.
35 typedef base::Callback<
36 void(const GetOrDownloadResult&, scoped_ptr<AttachmentMap> attachments)>
37 GetOrDownloadCallback;
39 // The result of a DropAttachments operation.
40 enum DropResult {
41 DROP_SUCCESS, // No error, all attachments dropped.
42 DROP_UNSPECIFIED_ERROR, // An unspecified error occurred. Some or all
43 // attachments may not have been dropped.
46 typedef base::Callback<void(const DropResult&)> DropCallback;
48 // An interface that embedder code implements to be notified about different
49 // events that originate from AttachmentService.
50 // This interface will be called from the same thread AttachmentService was
51 // created and called.
52 class Delegate {
53 public:
54 virtual ~Delegate() {}
56 // Attachment is uploaded to server and attachment_id is updated with server
57 // url.
58 virtual void OnAttachmentUploaded(const AttachmentId& attachment_id) = 0;
61 AttachmentService();
62 virtual ~AttachmentService();
64 // Return a pointer to the AttachmentStore owned by this object.
66 // May return NULL.
67 virtual AttachmentStore* GetStore() = 0;
69 // See SyncData::GetOrDownloadAttachments.
70 virtual void GetOrDownloadAttachments(
71 const AttachmentIdList& attachment_ids,
72 const GetOrDownloadCallback& callback) = 0;
74 // See SyncData::DropAttachments.
75 virtual void DropAttachments(const AttachmentIdList& attachment_ids,
76 const DropCallback& callback) = 0;
78 // Schedules the attachments identified by |attachment_ids| to be uploaded to
79 // the server.
81 // Assumes the attachments are already in the attachment store.
83 // A request to upload attachments is persistent in that uploads will be
84 // automatically retried if transient errors occur.
86 // A request to upload attachments does not persist across restarts of Chrome.
88 // Invokes OnAttachmentUploaded on the Delegate (if provided).
89 virtual void UploadAttachments(const AttachmentIdSet& attachment_ids) = 0;
92 } // namespace syncer
94 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_SERVICE_H_