1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef SYNC_ENGINE_UPDATE_HANDLER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define SYNC_ENGINE_UPDATE_HANDLER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <vector>
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "sync/base/sync_export.h"
11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "sync/internal_api/public/util/syncer_error.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace sync_pb {
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass DataTypeContext;
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DataTypeProgressMarker;
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SyncEntity;
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList;
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace syncer {
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace sessions {
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class StatusController;
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ModelSafeWorker;
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This class represents an entity that can request, receive, and apply updates
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// from the sync server.
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SYNC_EXPORT_PRIVATE UpdateHandler {
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  UpdateHandler();
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~UpdateHandler() = 0;
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Fills the given parameter with the stored progress marker for this type.
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void GetDownloadProgress(
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      sync_pb::DataTypeProgressMarker* progress_marker) const = 0;
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Fills |context| with the per-client datatype context, if one exists. Clears
41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // |context| otherwise.
42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void GetDataTypeContext(sync_pb::DataTypeContext* context) const = 0;
43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Processes the contents of a GetUpdates response message.
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  //
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Should be invoked with the progress marker and set of SyncEntities from a
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // single GetUpdates response message.  The progress marker's type must match
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // this update handler's type, and the set of SyncEntities must include all
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // entities of this type found in the response message.
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  //
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // In this context, "applicable_updates" means the set of updates belonging to
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // this type.
53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  //
54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // Returns SYNCER_OK if the all data was processed successfully, a syncer
55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  // error otherwise.
56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  virtual SyncerError ProcessGetUpdatesResponse(
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const sync_pb::DataTypeProgressMarker& progress_marker,
58c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      const sync_pb::DataTypeContext& mutated_context,
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const SyncEntityList& applicable_updates,
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      sessions::StatusController* status) = 0;
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Called at the end of a non-configure GetUpdates loop to apply any unapplied
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // updates.
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void ApplyUpdates(sessions::StatusController* status) = 0;
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Called at the end of a configure GetUpdates loop to perform any required
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // post-initial-download update application.
68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void PassiveApplyUpdates(sessions::StatusController* status) = 0;
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace syncer
72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // SYNC_ENGINE_UPDATE_HANDLER_H_
74