| 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. |
| 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 // Returns the number of entries included in this contribution. |
| 68 size_t GetNumEntries(); |
| 69 |
| 70 private: |
| 71 class SyncDirectoryCommitContributionTest; |
| 72 FRIEND_TEST_ALL_PREFIXES(SyncDirectoryCommitContributionTest, GatherByTypes); |
| 73 FRIEND_TEST_ALL_PREFIXES(SyncDirectoryCommitContributionTest, |
| 74 GatherAndTruncate); |
| 75 |
| 76 SyncDirectoryCommitContribution( |
| 77 const std::vector<int64>& metahandles, |
| 78 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
| 79 syncable::Directory* directory); |
| 80 |
| 81 syncable::Directory* dir_; |
| 82 const std::vector<int64> metahandles_; |
| 83 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities_; |
| 84 size_t entries_start_index_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryCommitContribution); |
| 87 }; |
| 88 |
| 89 } // namespace syncer |
| 90 |
| 91 #endif // SYNC_ENGINE_SYNC_DIRECTORY_COMMIT_CONTRIBUTION_H_ |
| OLD | NEW |