1// Copyright 2014 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_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_ 6#define SYNC_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "sync/engine/commit_contribution.h" 12#include "sync/protocol/sync.pb.h" 13 14namespace syncer { 15 16class ModelTypeSyncWorkerImpl; 17 18// A non-blocking sync type's contribution to an outgoing commit message. 19// 20// Helps build a commit message and process its response. It collaborates 21// closely with the ModelTypeSyncWorkerImpl. 22class NonBlockingTypeCommitContribution : public CommitContribution { 23 public: 24 NonBlockingTypeCommitContribution( 25 const sync_pb::DataTypeContext& context, 26 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, 27 const std::vector<int64>& sequence_numbers, 28 ModelTypeSyncWorkerImpl* worker); 29 virtual ~NonBlockingTypeCommitContribution(); 30 31 // Implementation of CommitContribution 32 virtual void AddToCommitMessage(sync_pb::ClientToServerMessage* msg) OVERRIDE; 33 virtual SyncerError ProcessCommitResponse( 34 const sync_pb::ClientToServerResponse& response, 35 sessions::StatusController* status) OVERRIDE; 36 virtual void CleanUp() OVERRIDE; 37 virtual size_t GetNumEntries() const OVERRIDE; 38 39 private: 40 // A non-owned pointer back to the object that created this contribution. 41 ModelTypeSyncWorkerImpl* const worker_; 42 43 // The type-global context information. 44 const sync_pb::DataTypeContext context_; 45 46 // The set of entities to be committed, serialized as SyncEntities. 47 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities_; 48 49 // The sequence numbers associated with the pending commits. These match up 50 // with the entities_ vector. 51 const std::vector<int64> sequence_numbers_; 52 53 // The index in the commit message where this contribution's entities are 54 // added. Used to correlate per-item requests with per-item responses. 55 size_t entries_start_index_; 56 57 // A flag used to ensure this object's contract is respected. Helps to check 58 // that CleanUp() is called before the object is destructed. 59 bool cleaned_up_; 60 61 DISALLOW_COPY_AND_ASSIGN(NonBlockingTypeCommitContribution); 62}; 63 64} // namespace syncer 65 66#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_COMMIT_CONTRIBUTION_H_ 67