OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ | 5 #ifndef SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ |
6 #define SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ | 6 #define SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "sync/engine/syncer_command.h" | 11 #include "sync/engine/syncer_command.h" |
12 #include "sync/engine/syncproto.h" | |
13 #include "sync/syncable/entry_kernel.h" | 12 #include "sync/syncable/entry_kernel.h" |
14 | 13 |
15 namespace syncer { | 14 namespace syncer { |
16 | 15 |
17 namespace sessions { | 16 namespace sessions { |
18 class OrderedCommitSet; | 17 class OrderedCommitSet; |
19 } | 18 } |
20 | 19 |
21 namespace syncable { | 20 namespace syncable { |
22 class Entry; | 21 class Entry; |
23 } | 22 } |
24 | 23 |
25 // A class that contains the code used to serialize a set of sync items into a | 24 // 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 | 25 // protobuf commit message. This conversion process references the |
27 // syncable::Directory, which is why it must be called within the same | 26 // 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 | 27 // transaction as the GetCommitIdsCommand that fetched the set of items to be |
29 // committed. | 28 // committed. |
30 // | 29 // |
31 // See SyncerCommand documentation for more info. | 30 // See SyncerCommand documentation for more info. |
32 class BuildCommitCommand : public SyncerCommand { | 31 class BuildCommitCommand : public SyncerCommand { |
33 public: | 32 public: |
34 // The batch_commit_set parameter contains a set of references to the items | 33 // The batch_commit_set parameter contains a set of references to the items |
35 // that should be committed. | 34 // that should be committed. |
36 // | 35 // |
37 // The commit_message parameter is an output parameter which will contain the | 36 // The commit_message parameter is an output parameter which will contain the |
38 // fully initialized commit message once ExecuteImpl() has been called. | 37 // fully initialized commit message once ExecuteImpl() has been called. |
39 BuildCommitCommand(const sessions::OrderedCommitSet& batch_commit_set, | 38 BuildCommitCommand(const sessions::OrderedCommitSet& batch_commit_set, |
40 ClientToServerMessage* commit_message); | 39 sync_pb::ClientToServerMessage* commit_message); |
41 virtual ~BuildCommitCommand(); | 40 virtual ~BuildCommitCommand(); |
42 | 41 |
43 // SyncerCommand implementation. | 42 // SyncerCommand implementation. |
44 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE; | 43 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE; |
45 | 44 |
46 private: | 45 private: |
47 FRIEND_TEST_ALL_PREFIXES(BuildCommitCommandTest, InterpolatePosition); | 46 FRIEND_TEST_ALL_PREFIXES(BuildCommitCommandTest, InterpolatePosition); |
48 | 47 |
49 // Functions returning constants controlling range of values. | 48 // Functions returning constants controlling range of values. |
50 static int64 GetFirstPosition(); | 49 static int64 GetFirstPosition(); |
51 static int64 GetLastPosition(); | 50 static int64 GetLastPosition(); |
52 static int64 GetGap(); | 51 static int64 GetGap(); |
53 | 52 |
54 void AddExtensionsActivityToMessage(sessions::SyncSession* session, | 53 void AddExtensionsActivityToMessage(sessions::SyncSession* session, |
55 CommitMessage* message); | 54 sync_pb::CommitMessage* message); |
56 // Helper for computing position. Find the numeric position value | 55 // Helper for computing position. Find the numeric position value |
57 // of the closest already-synced entry. |direction| must be one of | 56 // of the closest already-synced entry. |direction| must be one of |
58 // NEXT_ID or PREV_ID; this parameter controls the search direction. | 57 // NEXT_ID or PREV_ID; this parameter controls the search direction. |
59 // For an open range (no predecessor or successor), the return | 58 // For an open range (no predecessor or successor), the return |
60 // value will be kFirstPosition or kLastPosition. | 59 // value will be kFirstPosition or kLastPosition. |
61 int64 FindAnchorPosition(syncable::IdField direction, | 60 int64 FindAnchorPosition(syncable::IdField direction, |
62 const syncable::Entry& entry); | 61 const syncable::Entry& entry); |
63 // Given two values of the type returned by FindAnchorPosition, | 62 // Given two values of the type returned by FindAnchorPosition, |
64 // compute a third value in between the two ranges. | 63 // compute a third value in between the two ranges. |
65 int64 InterpolatePosition(int64 lo, int64 hi); | 64 int64 InterpolatePosition(int64 lo, int64 hi); |
66 | 65 |
67 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommand); | 66 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommand); |
68 | 67 |
69 // Input parameter; see constructor comment. | 68 // Input parameter; see constructor comment. |
70 const sessions::OrderedCommitSet& batch_commit_set_; | 69 const sessions::OrderedCommitSet& batch_commit_set_; |
71 | 70 |
72 // Output parameter; see constructor comment. | 71 // Output parameter; see constructor comment. |
73 ClientToServerMessage* commit_message_; | 72 sync_pb::ClientToServerMessage* commit_message_; |
74 }; | 73 }; |
75 | 74 |
76 } // namespace syncer | 75 } // namespace syncer |
77 | 76 |
78 #endif // SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ | 77 #endif // SYNC_ENGINE_BUILD_COMMIT_COMMAND_H_ |
OLD | NEW |