OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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_SYNC_DIRECTORY_COMMIT_CONTRIBUTION_H_ | |
6 #define SYNC_ENGINE_SYNC_DIRECTORY_COMMIT_CONTRIBUTION_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/gtest_prod_util.h" | |
11 #include "sync/base/sync_export.h" | |
12 #include "sync/internal_api/public/base/model_type.h" | |
13 #include "sync/internal_api/public/util/syncer_error.h" | |
14 #include "sync/protocol/sync.pb.h" | |
15 #include "sync/sessions/status_controller.h" | |
16 | |
17 namespace syncer { | |
18 | |
19 namespace sessions { | |
20 class StatusController; | |
21 } // namespace sessions | |
22 | |
23 namespace syncable { | |
24 class Directory; | |
25 } // namespace syncable | |
26 | |
27 // This class represents a set of items belonging to a particular data type that | |
28 // have been selected from the syncable Directory and prepared for commit. | |
29 // | |
30 // This class handles the bookkeeping related to the commit of these items, | |
31 // including processing the commit response message and setting and unsetting | |
32 // the SYNCING bits. | |
33 class SYNC_EXPORT_PRIVATE SyncDirectoryCommitContribution { | |
34 public: | |
35 // This destructor may make model neutral changes to the directory. | |
Nicolas Zea
2013/10/14 21:45:35
comment no longer applies
rlarocque
2013/10/14 23:23:28
Done.
| |
36 // (It unsets its entities' SYNCING bits.) | |
37 ~SyncDirectoryCommitContribution(); | |
38 | |
39 // Build a CommitContribution from the IS_UNSYNCED items in |dir| with the | |
40 // given |type|. The contribution will include at most |max_items| entries. | |
41 // | |
42 // This function may return NULL if this type has no items ready for and | |
43 // requiring commit. This function may make model neutral changes to the | |
44 // directory. | |
45 static SyncDirectoryCommitContribution* Build( | |
46 syncable::Directory* dir, | |
47 ModelType type, | |
48 size_t max_items); | |
49 | |
50 // Serialize this contribution's entries to the given commit request |msg|. | |
51 // | |
52 // This function is not const. It will update some state in this contribution | |
53 // that will be used when processing the associated commit response. This | |
54 // function should not be called more than once. | |
55 void AddToCommitMessage(sync_pb::ClientToServerMessage* msg); | |
56 | |
57 // Updates this contribution's contents in accordance with the provided | |
58 // |response|. | |
59 // | |
60 // This function may make model-neutral changes to the directory. It is not | |
61 // valid to call this function unless AddToCommitMessage() was called earlier. | |
62 // This function should not be called more than once. | |
63 SyncerError ProcessCommitResponse( | |
64 const sync_pb::ClientToServerResponse& response, | |
65 sessions::StatusController* status); | |
66 | |
67 // Cleans up any temproary state associated with the commit. Must be called | |
68 // before destruction. | |
69 void CleanUp(); | |
70 | |
71 // Returns the number of entries included in this contribution. | |
72 size_t GetNumEntries() const; | |
73 | |
74 private: | |
75 class SyncDirectoryCommitContributionTest; | |
76 FRIEND_TEST_ALL_PREFIXES(SyncDirectoryCommitContributionTest, GatherByTypes); | |
77 FRIEND_TEST_ALL_PREFIXES(SyncDirectoryCommitContributionTest, | |
78 GatherAndTruncate); | |
79 | |
80 SyncDirectoryCommitContribution( | |
81 const std::vector<int64>& metahandles, | |
82 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | |
83 syncable::Directory* directory); | |
84 | |
85 void UnsetSyncingBits(); | |
86 | |
87 syncable::Directory* dir_; | |
88 const std::vector<int64> metahandles_; | |
89 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities_; | |
90 size_t entries_start_index_; | |
91 | |
92 // This flag is tracks whether or not the directory entries associated with | |
93 // this commit still have their SYNCING bits set. These bits will be set when | |
94 // the CommitContribution is created with Build() and unset when CleanUp() is | |
95 // called. This flag must be unset by the time our destructor is called. | |
96 bool syncing_bits_set_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryCommitContribution); | |
99 }; | |
100 | |
101 } // namespace syncer | |
102 | |
103 #endif // SYNC_ENGINE_SYNC_DIRECTORY_COMMIT_CONTRIBUTION_H_ | |
OLD | NEW |