summaryrefslogtreecommitdiffstats
path: root/sync/engine/non_blocking_type_commit_contribution.h
blob: d7321308141068528a02a26280586250e20c27ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYNC_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_
#define SYNC_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_

#include <vector>

#include "base/basictypes.h"
#include "sync/engine/commit_contribution.h"
#include "sync/protocol/sync.pb.h"

namespace syncer {

class ModelTypeSyncWorkerImpl;

// A non-blocking sync type's contribution to an outgoing commit message.
//
// Helps build a commit message and process its response.  It collaborates
// closely with the ModelTypeSyncWorkerImpl.
class NonBlockingTypeCommitContribution : public CommitContribution {
 public:
  NonBlockingTypeCommitContribution(
      const sync_pb::DataTypeContext& context,
      const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
      const std::vector<int64>& sequence_numbers,
      ModelTypeSyncWorkerImpl* worker);
  virtual ~NonBlockingTypeCommitContribution();

  // Implementation of CommitContribution
  virtual void AddToCommitMessage(sync_pb::ClientToServerMessage* msg) OVERRIDE;
  virtual SyncerError ProcessCommitResponse(
      const sync_pb::ClientToServerResponse& response,
      sessions::StatusController* status) OVERRIDE;
  virtual void CleanUp() OVERRIDE;
  virtual size_t GetNumEntries() const OVERRIDE;

 private:
  // A non-owned pointer back to the object that created this contribution.
  ModelTypeSyncWorkerImpl* const worker_;

  // The type-global context information.
  const sync_pb::DataTypeContext context_;

  // The set of entities to be committed, serialized as SyncEntities.
  const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities_;

  // The sequence numbers associated with the pending commits.  These match up
  // with the entities_ vector.
  const std::vector<int64> sequence_numbers_;

  // The index in the commit message where this contribution's entities are
  // added.  Used to correlate per-item requests with per-item responses.
  size_t entries_start_index_;

  // A flag used to ensure this object's contract is respected.  Helps to check
  // that CleanUp() is called before the object is destructed.
  bool cleaned_up_;

  DISALLOW_COPY_AND_ASSIGN(NonBlockingTypeCommitContribution);
};

}  // namespace syncer

#endif  // SYNC_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_