Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / sync / api / sync_change_processor.h
blobb70ef3df1816f429352bb4b1a3e820f4209afaef
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_SYNC_CHANGE_PROCESSOR_H_
6 #define SYNC_API_SYNC_CHANGE_PROCESSOR_H_
8 #include <vector>
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"
15 namespace tracked_objects {
16 class Location;
17 } // namespace tracked_objects
19 namespace syncer {
21 class SyncChange;
23 typedef std::vector<SyncChange> SyncChangeList;
25 // An interface for services that handle receiving SyncChanges.
26 class SYNC_EXPORT SyncChangeProcessor {
27 public:
28 // Whether a context change should force a datatype refresh or not.
29 enum ContextRefreshStatus { NO_REFRESH, REFRESH_NEEDED };
30 typedef base::Callback<void(const SyncData&)> GetSyncDataCallback;
32 SyncChangeProcessor();
33 virtual ~SyncChangeProcessor();
35 // Process a list of SyncChanges.
36 // Returns: A default SyncError (IsSet() == false) if no errors were
37 // encountered, and a filled SyncError (IsSet() == true)
38 // otherwise.
39 // Inputs:
40 // |from_here|: allows tracking of where sync changes originate.
41 // |change_list|: is the list of sync changes in need of processing.
42 virtual SyncError ProcessSyncChanges(
43 const tracked_objects::Location& from_here,
44 const SyncChangeList& change_list) = 0;
46 // Fills a list of SyncData. This should create an up to date representation
47 // of all the data known to the ChangeProcessor for |datatype|, and
48 // should match/be a subset of the server's view of that datatype.
50 // WARNING: This can be a potentially slow & memory intensive operation and
51 // should only be used when absolutely necessary / sparingly.
52 virtual SyncDataList GetAllSyncData(ModelType type) const = 0;
54 // Retrieves the SyncData identified by |type| and |sync_tag| and invokes
55 // |callback| asynchronously. If no such SyncData exists locally, IsValid on
56 // the SyncData passed to |callback| will return false.
58 // This is an asynchronous local operation that may result in disk IO.
60 // Refer to sync_data.h for a description of |sync_tag|.
62 // TODO:(maniscalco): N.B. this method should really be pure virtual. An
63 // implentation is provided here just to verify that everything compiles.
64 // Update this method to be pure virtual (bug 353300).
65 virtual void GetSyncData(const ModelType& type,
66 const std::string& sync_tag,
67 const GetSyncDataCallback& callback) const {}
69 // Updates the context for |type|, triggering an optional context refresh.
70 // Default implementation does nothing. A type's context is a per-client blob
71 // that can affect all SyncData sent to/from the server, much like a cookie.
72 // TODO(zea): consider pulling the refresh logic into a separate method
73 // unrelated to datatype implementations.
74 virtual syncer::SyncError UpdateDataTypeContext(
75 ModelType type,
76 ContextRefreshStatus refresh_status,
77 const std::string& context);
80 } // namespace syncer
82 #endif // SYNC_API_SYNC_CHANGE_PROCESSOR_H_