Update V8 to version 4.7.21.
[chromium-blink-merge.git] / sync / api / syncable_service.h
bloba6f8b813977586cd908470618129bdd61e6f58fe
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 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> {
33 public:
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(
53 ModelType type,
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)
65 // otherwise.
66 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here,
67 const SyncChangeList& change_list) override = 0;
69 // Returns AttachmentStore for use by sync when uploading or downloading
70 // attachments.
71 // GetAttachmentStoreForSync is called right before MergeDataAndStartSyncing.
72 // If at that time GetAttachmentStoreForSync returns NULL then datatype is
73 // considered not using attachments and all attempts to upload/download
74 // attachments will fail. Default implementation returns NULL. Datatype that
75 // uses sync attachments should create attachment store, implement
76 // GetAttachmentStoreForSync to return result of
77 // AttachmentStore::CreateAttachmentStoreForSync() from attachment store
78 // object.
79 virtual scoped_ptr<AttachmentStoreForSync> GetAttachmentStoreForSync();
81 // Called by sync to provide AttachmentService to be used to download
82 // attachments.
83 // SetAttachmentService is called after GetAttachmentStore and right before
84 // MergeDataAndStartSyncing and only if GetAttachmentStore has returned a
85 // non-NULL store instance. Default implementation does nothing.
86 // Datatype that uses attachments must take ownerhip of the provided
87 // AttachmentService instance.
88 virtual void SetAttachmentService(
89 scoped_ptr<AttachmentService> attachment_service);
91 protected:
92 ~SyncableService() override;
95 } // namespace syncer
97 #endif // SYNC_API_SYNCABLE_SERVICE_H_