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