More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / engine / build_commit_command.h
blobc1712a615c558b8ed5c083fee93fce2ad1ea851d
1 // Copyright (c) 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/engine/syncer_command.h"
12 #include "sync/syncable/entry_kernel.h"
14 namespace syncer {
16 namespace sessions {
17 class OrderedCommitSet;
20 namespace syncable {
21 class Entry;
24 // A class that contains the code used to serialize a set of sync items into a
25 // protobuf commit message. This conversion process references the
26 // syncable::Directory, which is why it must be called within the same
27 // transaction as the GetCommitIdsCommand that fetched the set of items to be
28 // committed.
30 // See SyncerCommand documentation for more info.
31 class BuildCommitCommand : public SyncerCommand {
32 public:
33 // The batch_commit_set parameter contains a set of references to the items
34 // that should be committed.
36 // The commit_message parameter is an output parameter which will contain the
37 // fully initialized commit message once ExecuteImpl() has been called.
38 BuildCommitCommand(const sessions::OrderedCommitSet& batch_commit_set,
39 sync_pb::ClientToServerMessage* commit_message);
40 virtual ~BuildCommitCommand();
42 // SyncerCommand implementation.
43 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE;
45 private:
46 FRIEND_TEST_ALL_PREFIXES(BuildCommitCommandTest, InterpolatePosition);
48 // Functions returning constants controlling range of values.
49 static int64 GetFirstPosition();
50 static int64 GetLastPosition();
51 static int64 GetGap();
53 void AddExtensionsActivityToMessage(sessions::SyncSession* session,
54 sync_pb::CommitMessage* message);
55 // Helper for computing position. Find the numeric position value
56 // of the closest already-synced entry. |direction| must be one of
57 // NEXT_ID or PREV_ID; this parameter controls the search direction.
58 // For an open range (no predecessor or successor), the return
59 // value will be kFirstPosition or kLastPosition.
60 int64 FindAnchorPosition(syncable::IdField direction,
61 const syncable::Entry& entry);
62 // Given two values of the type returned by FindAnchorPosition,
63 // compute a third value in between the two ranges.
64 int64 InterpolatePosition(int64 lo, int64 hi);
66 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommand);
68 // Input parameter; see constructor comment.
69 const sessions::OrderedCommitSet& batch_commit_set_;
71 // Output parameter; see constructor comment.
72 sync_pb::ClientToServerMessage* commit_message_;
75 } // namespace syncer
77 #endif // SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_