Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / sync / api / syncable_service.h
blob17feb63bce44c5e24673cb7cde79e9630f445daa
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_
8 #include <vector>
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"
22 namespace syncer {
24 class SyncErrorFactory;
26 // TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService
27 // implementers provide a way of getting a weak pointer to themselves.
28 // See crbug.com/100114.
29 class SYNC_EXPORT SyncableService
30 : public SyncChangeProcessor,
31 public base::SupportsWeakPtr<SyncableService> {
32 public:
33 // A StartSyncFlare is useful when your SyncableService has a need for sync
34 // to start ASAP, typically because a local change event has occurred but
35 // MergeDataAndStartSyncing hasn't been called yet, meaning you don't have a
36 // SyncChangeProcessor. The sync subsystem will respond soon after invoking
37 // Run() on your flare by calling MergeDataAndStartSyncing. The ModelType
38 // parameter is included so that the recieving end can track usage and timing
39 // statistics, make optimizations or tradeoffs by type, etc.
40 typedef base::Callback<void(ModelType)> StartSyncFlare;
42 // Informs the service to begin syncing the specified synced datatype |type|.
43 // The service should then merge |initial_sync_data| into it's local data,
44 // calling |sync_processor|'s ProcessSyncChanges as necessary to reconcile the
45 // two. After this, the SyncableService's local data should match the server
46 // data, and the service should be ready to receive and process any further
47 // SyncChange's as they occur.
48 // Returns: a SyncMergeResult whose error field reflects whether an error
49 // was encountered while merging the two models. The merge result
50 // may also contain optional merge statistics.
51 virtual SyncMergeResult MergeDataAndStartSyncing(
52 ModelType type,
53 const SyncDataList& initial_sync_data,
54 scoped_ptr<SyncChangeProcessor> sync_processor,
55 scoped_ptr<SyncErrorFactory> error_handler) = 0;
57 // Stop syncing the specified type and reset state.
58 virtual void StopSyncing(ModelType type) = 0;
60 // SyncChangeProcessor interface.
61 // Process a list of new SyncChanges and update the local data as necessary.
62 // Returns: A default SyncError (IsSet() == false) if no errors were
63 // encountered, and a filled SyncError (IsSet() == true)
64 // otherwise.
65 virtual SyncError ProcessSyncChanges(
66 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 protected:
80 ~SyncableService() override;
83 } // namespace syncer
85 #endif // SYNC_API_SYNCABLE_SERVICE_H_