sync_change_processor.h revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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.
4
5#ifndef SYNC_API_SYNC_CHANGE_PROCESSOR_H_
6#define SYNC_API_SYNC_CHANGE_PROCESSOR_H_
7
8#include <vector>
9
10#include "sync/api/sync_data.h"
11#include "sync/api/sync_error.h"
12#include "sync/base/sync_export.h"
13#include "sync/internal_api/public/base/model_type.h"
14
15namespace tracked_objects {
16class Location;
17}  // namespace tracked_objects
18
19namespace syncer {
20
21class SyncChange;
22
23typedef std::vector<SyncChange> SyncChangeList;
24
25// An interface for services that handle receiving SyncChanges.
26class SYNC_EXPORT SyncChangeProcessor {
27 public:
28  typedef base::Callback<void(const SyncData&)> GetSyncDataCallback;
29
30  SyncChangeProcessor();
31  virtual ~SyncChangeProcessor();
32
33  // Process a list of SyncChanges.
34  // Returns: A default SyncError (IsSet() == false) if no errors were
35  //          encountered, and a filled SyncError (IsSet() == true)
36  //          otherwise.
37  // Inputs:
38  //   |from_here|: allows tracking of where sync changes originate.
39  //   |change_list|: is the list of sync changes in need of processing.
40  virtual SyncError ProcessSyncChanges(
41      const tracked_objects::Location& from_here,
42      const SyncChangeList& change_list) = 0;
43
44  // Fills a list of SyncData. This should create an up to date representation
45  // of all the data known to the ChangeProcessor for |datatype|, and
46  // should match/be a subset of the server's view of that datatype.
47  //
48  // WARNING: This can be a potentially slow & memory intensive operation and
49  // should only be used when absolutely necessary / sparingly.
50  virtual SyncDataList GetAllSyncData(ModelType type) const = 0;
51
52  // Retrieves the SyncData identified by |type| and |sync_tag| and invokes
53  // |callback| asynchronously. If no such SyncData exists locally, IsValid on
54  // the SyncData passed to |callback| will return false.
55  //
56  // This is an asynchronous local operation that may result in disk IO.
57  //
58  // Refer to sync_data.h for a description of |sync_tag|.
59  //
60  // TODO:(maniscalco): N.B. this method should really be pure virtual. An
61  // implentation is provided here just to verify that everything compiles.
62  // Update this method to be pure virtual (bug 353300).
63  virtual void GetSyncData(const ModelType& type,
64                           const std::string& sync_tag,
65                           const GetSyncDataCallback& callback) const {}
66};
67
68}  // namespace syncer
69
70#endif  // SYNC_API_SYNC_CHANGE_PROCESSOR_H_
71