1 // Copyright 2012 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_API_SYNCABLE_SERVICE_H_
6 #define SYNC_API_SYNCABLE_SERVICE_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "sync/api/attachments/attachment_store.h"
15 #include "sync/api/sync_change_processor.h"
16 #include "sync/api/sync_data.h"
17 #include "sync/api/sync_error.h"
18 #include "sync/api/sync_merge_result.h"
19 #include "sync/base/sync_export.h"
20 #include "sync/internal_api/public/base/model_type.h"
24 class AttachmentService
;
25 class SyncErrorFactory
;
27 // TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService
28 // implementers provide a way of getting a weak pointer to themselves.
29 // See crbug.com/100114.
30 class SYNC_EXPORT SyncableService
31 : public SyncChangeProcessor
,
32 public base::SupportsWeakPtr
<SyncableService
> {
34 // A StartSyncFlare is useful when your SyncableService has a need for sync
35 // to start ASAP, typically because a local change event has occurred but
36 // MergeDataAndStartSyncing hasn't been called yet, meaning you don't have a
37 // SyncChangeProcessor. The sync subsystem will respond soon after invoking
38 // Run() on your flare by calling MergeDataAndStartSyncing. The ModelType
39 // parameter is included so that the recieving end can track usage and timing
40 // statistics, make optimizations or tradeoffs by type, etc.
41 typedef base::Callback
<void(ModelType
)> StartSyncFlare
;
43 // Informs the service to begin syncing the specified synced datatype |type|.
44 // The service should then merge |initial_sync_data| into it's local data,
45 // calling |sync_processor|'s ProcessSyncChanges as necessary to reconcile the
46 // two. After this, the SyncableService's local data should match the server
47 // data, and the service should be ready to receive and process any further
48 // SyncChange's as they occur.
49 // Returns: a SyncMergeResult whose error field reflects whether an error
50 // was encountered while merging the two models. The merge result
51 // may also contain optional merge statistics.
52 virtual SyncMergeResult
MergeDataAndStartSyncing(
54 const SyncDataList
& initial_sync_data
,
55 scoped_ptr
<SyncChangeProcessor
> sync_processor
,
56 scoped_ptr
<SyncErrorFactory
> error_handler
) = 0;
58 // Stop syncing the specified type and reset state.
59 virtual void StopSyncing(ModelType type
) = 0;
61 // SyncChangeProcessor interface.
62 // Process a list of new SyncChanges and update the local data as necessary.
63 // Returns: A default SyncError (IsSet() == false) if no errors were
64 // encountered, and a filled SyncError (IsSet() == true)
66 SyncError
ProcessSyncChanges(const tracked_objects::Location
& from_here
,
67 const SyncChangeList
& change_list
) override
= 0;
69 // Returns AttachmentStore used by datatype. Attachment store is used by sync
70 // when uploading or downloading attachments.
71 // GetAttachmentStore is called right before MergeDataAndStartSyncing. If at
72 // that time GetAttachmentStore returns NULL then datatype is considered not
73 // using attachments and all attempts to upload/download attachments will
74 // fail. Default implementation returns NULL. Datatype that uses sync
75 // attachemnts should create attachment store and implement GetAttachmentStore
76 // to return pointer to it.
77 virtual scoped_refptr
<AttachmentStore
> GetAttachmentStore();
79 // Called by sync to provide AttachmentService to be used to download
81 // SetAttachmentService is called after GetAttachmentStore and right before
82 // MergeDataAndStartSyncing and only if GetAttachmentStore has returned a
83 // non-NULL store instance. Default implementation does nothing.
84 // Datatype that uses attachments must take ownerhip of the provided
85 // AttachmentService instance.
86 virtual void SetAttachmentService(
87 scoped_ptr
<AttachmentService
> attachment_service
);
90 ~SyncableService() override
;
95 #endif // SYNC_API_SYNCABLE_SERVICE_H_