syncable_service.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 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.
4
5#ifndef SYNC_API_SYNCABLE_SERVICE_H_
6#define SYNC_API_SYNCABLE_SERVICE_H_
7
8#include <vector>
9
10#include "base/compiler_specific.h"
11#include "base/memory/scoped_ptr.h"
12#include "base/memory/weak_ptr.h"
13#include "sync/api/sync_change_processor.h"
14#include "sync/api/sync_data.h"
15#include "sync/api/sync_error.h"
16#include "sync/internal_api/public/base/model_type.h"
17
18namespace syncer {
19
20class SyncErrorFactory;
21
22typedef std::vector<SyncData> SyncDataList;
23
24// TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService
25// implementers provide a way of getting a weak pointer to themselves.
26// See crbug.com/100114.
27class SyncableService : public SyncChangeProcessor,
28                        public base::SupportsWeakPtr<SyncableService> {
29 public:
30  // Informs the service to begin syncing the specified synced datatype |type|.
31  // The service should then merge |initial_sync_data| into it's local data,
32  // calling |sync_processor|'s ProcessSyncChanges as necessary to reconcile the
33  // two. After this, the SyncableService's local data should match the server
34  // data, and the service should be ready to receive and process any further
35  // SyncChange's as they occur.
36  // Returns: A default SyncError (IsSet() == false) if no errors were
37  //          encountered, and a filled SyncError (IsSet() == true)
38  //          otherwise.
39  virtual SyncError MergeDataAndStartSyncing(
40      ModelType type,
41      const SyncDataList& initial_sync_data,
42      scoped_ptr<SyncChangeProcessor> sync_processor,
43      scoped_ptr<SyncErrorFactory> error_handler) = 0;
44
45  // Stop syncing the specified type and reset state.
46  virtual void StopSyncing(ModelType type) = 0;
47
48  // Fills a list of SyncData from the local data. This should create an up
49  // to date representation of the SyncableService's view of that datatype, and
50  // should match/be a subset of the server's view of that datatype.
51  virtual SyncDataList GetAllSyncData(ModelType type) const = 0;
52
53  // SyncChangeProcessor interface.
54  // Process a list of new SyncChanges and update the local data as necessary.
55  // Returns: A default SyncError (IsSet() == false) if no errors were
56  //          encountered, and a filled SyncError (IsSet() == true)
57  //          otherwise.
58  virtual SyncError ProcessSyncChanges(
59      const tracked_objects::Location& from_here,
60      const SyncChangeList& change_list) OVERRIDE = 0;
61
62 protected:
63  virtual ~SyncableService();
64};
65
66}  // namespace syncer
67
68#endif  // SYNC_API_SYNCABLE_SERVICE_H_
69