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