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 #include "sync/engine/sync_directory_commit_contribution.h" | 5 #include "sync/engine/directory_commit_contribution.h" |
6 | 6 |
7 #include "sync/engine/commit_util.h" | 7 #include "sync/engine/commit_util.h" |
8 #include "sync/engine/get_commit_ids.h" | 8 #include "sync/engine/get_commit_ids.h" |
9 #include "sync/engine/syncer_util.h" | 9 #include "sync/engine/syncer_util.h" |
10 #include "sync/syncable/model_neutral_mutable_entry.h" | 10 #include "sync/syncable/model_neutral_mutable_entry.h" |
11 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 11 #include "sync/syncable/syncable_model_neutral_write_transaction.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 using syncable::GET_BY_HANDLE; | 15 using syncable::GET_BY_HANDLE; |
16 using syncable::SYNCER; | 16 using syncable::SYNCER; |
17 | 17 |
18 SyncDirectoryCommitContribution::~SyncDirectoryCommitContribution() { | 18 DirectoryCommitContribution::~DirectoryCommitContribution() { |
19 DCHECK(!syncing_bits_set_); | 19 DCHECK(!syncing_bits_set_); |
20 } | 20 } |
21 | 21 |
22 // static. | 22 // static. |
23 SyncDirectoryCommitContribution* SyncDirectoryCommitContribution::Build( | 23 scoped_ptr<DirectoryCommitContribution> DirectoryCommitContribution::Build( |
24 syncable::Directory* dir, | 24 syncable::Directory* dir, |
25 ModelType type, | 25 ModelType type, |
26 size_t max_entries) { | 26 size_t max_entries) { |
27 std::vector<int64> metahandles; | 27 std::vector<int64> metahandles; |
28 | 28 |
29 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); | 29 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); |
30 GetCommitIdsForType(&trans, type, max_entries, &metahandles); | 30 GetCommitIdsForType(&trans, type, max_entries, &metahandles); |
31 | 31 |
32 if (metahandles.empty()) | 32 if (metahandles.empty()) |
33 return NULL; | 33 return scoped_ptr<DirectoryCommitContribution>(); |
34 | 34 |
35 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; | 35 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; |
36 for (std::vector<int64>::iterator it = metahandles.begin(); | 36 for (std::vector<int64>::iterator it = metahandles.begin(); |
37 it != metahandles.end(); ++it) { | 37 it != metahandles.end(); ++it) { |
38 sync_pb::SyncEntity* entity = entities.Add(); | 38 sync_pb::SyncEntity* entity = entities.Add(); |
39 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 39 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
40 commit_util::BuildCommitItem(entry, entity); | 40 commit_util::BuildCommitItem(entry, entity); |
41 entry.PutSyncing(true); | 41 entry.PutSyncing(true); |
42 } | 42 } |
43 | 43 |
44 return new SyncDirectoryCommitContribution(metahandles, entities, dir); | 44 return scoped_ptr<DirectoryCommitContribution>( |
| 45 new DirectoryCommitContribution(metahandles, entities, dir)); |
45 } | 46 } |
46 | 47 |
47 void SyncDirectoryCommitContribution::AddToCommitMessage( | 48 void DirectoryCommitContribution::AddToCommitMessage( |
48 sync_pb::ClientToServerMessage* msg) { | 49 sync_pb::ClientToServerMessage* msg) { |
49 DCHECK(syncing_bits_set_); | 50 DCHECK(syncing_bits_set_); |
50 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); | 51 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); |
51 entries_start_index_ = commit_message->entries_size(); | 52 entries_start_index_ = commit_message->entries_size(); |
52 std::copy(entities_.begin(), | 53 std::copy(entities_.begin(), |
53 entities_.end(), | 54 entities_.end(), |
54 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); | 55 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); |
55 } | 56 } |
56 | 57 |
57 SyncerError SyncDirectoryCommitContribution::ProcessCommitResponse( | 58 SyncerError DirectoryCommitContribution::ProcessCommitResponse( |
58 const sync_pb::ClientToServerResponse& response, | 59 const sync_pb::ClientToServerResponse& response, |
59 sessions::StatusController* status) { | 60 sessions::StatusController* status) { |
60 DCHECK(syncing_bits_set_); | 61 DCHECK(syncing_bits_set_); |
61 const sync_pb::CommitResponse& commit_response = response.commit(); | 62 const sync_pb::CommitResponse& commit_response = response.commit(); |
62 | 63 |
63 int transient_error_commits = 0; | 64 int transient_error_commits = 0; |
64 int conflicting_commits = 0; | 65 int conflicting_commits = 0; |
65 int error_commits = 0; | 66 int error_commits = 0; |
66 int successes = 0; | 67 int successes = 0; |
67 | 68 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // We don't currently have any code to support that exceptional control | 125 // We don't currently have any code to support that exceptional control |
125 // flow. Instead, we abort the current sync cycle and start a new one. The | 126 // flow. Instead, we abort the current sync cycle and start a new one. The |
126 // end result is the same. | 127 // end result is the same. |
127 return SERVER_RETURN_CONFLICT; | 128 return SERVER_RETURN_CONFLICT; |
128 } else { | 129 } else { |
129 LOG(FATAL) << "Inconsistent counts when processing commit response"; | 130 LOG(FATAL) << "Inconsistent counts when processing commit response"; |
130 return SYNCER_OK; | 131 return SYNCER_OK; |
131 } | 132 } |
132 } | 133 } |
133 | 134 |
134 void SyncDirectoryCommitContribution::CleanUp() { | 135 void DirectoryCommitContribution::CleanUp() { |
135 DCHECK(syncing_bits_set_); | 136 DCHECK(syncing_bits_set_); |
136 UnsetSyncingBits(); | 137 UnsetSyncingBits(); |
137 } | 138 } |
138 | 139 |
139 size_t SyncDirectoryCommitContribution::GetNumEntries() const { | 140 size_t DirectoryCommitContribution::GetNumEntries() const { |
140 return metahandles_.size(); | 141 return metahandles_.size(); |
141 } | 142 } |
142 | 143 |
143 SyncDirectoryCommitContribution::SyncDirectoryCommitContribution( | 144 DirectoryCommitContribution::DirectoryCommitContribution( |
144 const std::vector<int64>& metahandles, | 145 const std::vector<int64>& metahandles, |
145 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 146 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
146 syncable::Directory* dir) | 147 syncable::Directory* dir) |
147 : dir_(dir), | 148 : dir_(dir), |
148 metahandles_(metahandles), | 149 metahandles_(metahandles), |
149 entities_(entities), | 150 entities_(entities), |
150 entries_start_index_(0xDEADBEEF), | 151 entries_start_index_(0xDEADBEEF), |
151 syncing_bits_set_(true) { | 152 syncing_bits_set_(true) { |
152 } | 153 } |
153 | 154 |
154 void SyncDirectoryCommitContribution::UnsetSyncingBits() { | 155 void DirectoryCommitContribution::UnsetSyncingBits() { |
155 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 156 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
156 for (std::vector<int64>::const_iterator it = metahandles_.begin(); | 157 for (std::vector<int64>::const_iterator it = metahandles_.begin(); |
157 it != metahandles_.end(); ++it) { | 158 it != metahandles_.end(); ++it) { |
158 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 159 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
159 entry.PutSyncing(false); | 160 entry.PutSyncing(false); |
160 } | 161 } |
161 syncing_bits_set_ = false; | 162 syncing_bits_set_ = false; |
162 } | 163 } |
163 | 164 |
164 } // namespace syncer | 165 } // namespace syncer |
OLD | NEW |