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