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_ENGINE_BUILD_COMMIT_COMMAND_H_
6 #define SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "sync/base/sync_export.h"
12 #include "sync/engine/syncer_command.h"
13 #include "sync/syncable/entry_kernel.h"
18 class OrderedCommitSet
;
25 // A class that contains the code used to serialize a set of sync items into a
26 // protobuf commit message. This conversion process references the
27 // syncable::Directory, which is why it must be called within the same
28 // transaction as the GetCommitIdsCommand that fetched the set of items to be
31 // See SyncerCommand documentation for more info.
32 class SYNC_EXPORT_PRIVATE BuildCommitCommand
: public SyncerCommand
{
34 // The batch_commit_set parameter contains a set of references to the items
35 // that should be committed.
37 // The commit_message parameter is an output parameter which will contain the
38 // fully initialized commit message once ExecuteImpl() has been called.
39 BuildCommitCommand(const sessions::OrderedCommitSet
& batch_commit_set
,
40 sync_pb::ClientToServerMessage
* commit_message
);
41 virtual ~BuildCommitCommand();
43 // SyncerCommand implementation.
44 virtual SyncerError
ExecuteImpl(sessions::SyncSession
* session
) OVERRIDE
;
47 FRIEND_TEST_ALL_PREFIXES(BuildCommitCommandTest
, InterpolatePosition
);
49 // Functions returning constants controlling range of values.
50 static int64
GetFirstPosition();
51 static int64
GetLastPosition();
52 static int64
GetGap();
54 void AddExtensionsActivityToMessage(sessions::SyncSession
* session
,
55 sync_pb::CommitMessage
* message
);
56 // Helper for computing position. Find the numeric position value
57 // of the closest already-synced entry. |direction| must be one of
58 // NEXT_ID or PREV_ID; this parameter controls the search direction.
59 // For an open range (no predecessor or successor), the return
60 // value will be kFirstPosition or kLastPosition.
61 int64
FindAnchorPosition(syncable::IdField direction
,
62 const syncable::Entry
& entry
);
63 // Given two values of the type returned by FindAnchorPosition,
64 // compute a third value in between the two ranges.
65 int64
InterpolatePosition(int64 lo
, int64 hi
);
67 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommand
);
69 // Input parameter; see constructor comment.
70 const sessions::OrderedCommitSet
& batch_commit_set_
;
72 // Output parameter; see constructor comment.
73 sync_pb::ClientToServerMessage
* commit_message_
;
78 #endif // SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_