OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/process_commit_response_command.h" | 5 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const StatusController& status = session.status_controller(); | 74 const StatusController& status = session.status_controller(); |
75 for (size_t i = 0; i < status.commit_ids().size(); ++i) { | 75 for (size_t i = 0; i < status.commit_ids().size(); ++i) { |
76 groups_with_commits.insert( | 76 groups_with_commits.insert( |
77 GetGroupForModelType(status.GetUnrestrictedCommitModelTypeAt(i), | 77 GetGroupForModelType(status.GetUnrestrictedCommitModelTypeAt(i), |
78 session.routing_info())); | 78 session.routing_info())); |
79 } | 79 } |
80 | 80 |
81 return groups_with_commits; | 81 return groups_with_commits; |
82 } | 82 } |
83 | 83 |
84 bool ProcessCommitResponseCommand::ModelNeutralExecuteImpl( | 84 SyncerError ProcessCommitResponseCommand::ModelNeutralExecuteImpl( |
85 sessions::SyncSession* session) { | 85 sessions::SyncSession* session) { |
86 ScopedDirLookup dir(session->context()->directory_manager(), | 86 ScopedDirLookup dir(session->context()->directory_manager(), |
87 session->context()->account_name()); | 87 session->context()->account_name()); |
88 if (!dir.good()) { | 88 if (!dir.good()) { |
89 LOG(ERROR) << "Scoped dir lookup failed!"; | 89 LOG(ERROR) << "Scoped dir lookup failed!"; |
90 return false; | 90 return DIRECTORY_LOOKUP_FAILED; |
91 } | 91 } |
92 | 92 |
93 const StatusController& status = session->status_controller(); | 93 const StatusController& status = session->status_controller(); |
94 const ClientToServerResponse& response(status.commit_response()); | 94 const ClientToServerResponse& response(status.commit_response()); |
95 const vector<syncable::Id>& commit_ids(status.commit_ids()); | 95 const vector<syncable::Id>& commit_ids(status.commit_ids()); |
96 | 96 |
97 if (!response.has_commit()) { | 97 if (!response.has_commit()) { |
98 // TODO(sync): What if we didn't try to commit anything? | 98 // TODO(sync): What if we didn't try to commit anything? |
99 LOG(WARNING) << "Commit response has no commit body!"; | 99 LOG(WARNING) << "Commit response has no commit body!"; |
100 IncrementErrorCounters(session->mutable_status_controller()); | 100 IncrementErrorCounters(session->mutable_status_controller()); |
101 return false; | 101 return SERVER_RESPONSE_VALIDATION_FAILED; |
102 } | 102 } |
103 | 103 |
104 const CommitResponse& cr = response.commit(); | 104 const CommitResponse& cr = response.commit(); |
105 int commit_count = commit_ids.size(); | 105 int commit_count = commit_ids.size(); |
106 if (cr.entryresponse_size() != commit_count) { | 106 if (cr.entryresponse_size() != commit_count) { |
107 LOG(ERROR) << "Commit response has wrong number of entries! Expected:" << | 107 LOG(ERROR) << "Commit response has wrong number of entries! Expected:" << |
108 commit_count << " Got:" << cr.entryresponse_size(); | 108 commit_count << " Got:" << cr.entryresponse_size(); |
109 for (int i = 0 ; i < cr.entryresponse_size() ; i++) { | 109 for (int i = 0 ; i < cr.entryresponse_size() ; i++) { |
110 LOG(ERROR) << "Response #" << i << " Value: " << | 110 LOG(ERROR) << "Response #" << i << " Value: " << |
111 cr.entryresponse(i).response_type(); | 111 cr.entryresponse(i).response_type(); |
112 if (cr.entryresponse(i).has_error_message()) | 112 if (cr.entryresponse(i).has_error_message()) |
113 LOG(ERROR) << " " << cr.entryresponse(i).error_message(); | 113 LOG(ERROR) << " " << cr.entryresponse(i).error_message(); |
114 } | 114 } |
115 IncrementErrorCounters(session->mutable_status_controller()); | 115 IncrementErrorCounters(session->mutable_status_controller()); |
116 return false; | 116 return SERVER_RESPONSE_VALIDATION_FAILED; |
117 } | 117 } |
118 return true; | 118 return NO_ERROR; |
119 } | 119 } |
120 | 120 |
121 void ProcessCommitResponseCommand::ModelChangingExecuteImpl( | 121 SyncerError ProcessCommitResponseCommand::ModelChangingExecuteImpl( |
122 SyncSession* session) { | 122 SyncSession* session) { |
123 ProcessCommitResponse(session); | 123 SyncerError result = ProcessCommitResponse(session); |
124 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); | 124 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); |
125 if (session->status_controller().HasBookmarkCommitActivity() && | 125 if (session->status_controller().HasBookmarkCommitActivity() && |
126 session->status_controller().syncer_status() | 126 session->status_controller().syncer_status() |
127 .num_successful_bookmark_commits == 0) { | 127 .num_successful_bookmark_commits == 0) { |
128 monitor->PutRecords(session->extensions_activity()); | 128 monitor->PutRecords(session->extensions_activity()); |
129 session->mutable_extensions_activity()->clear(); | 129 session->mutable_extensions_activity()->clear(); |
130 } | 130 } |
| 131 return result; |
131 } | 132 } |
132 | 133 |
133 void ProcessCommitResponseCommand::ProcessCommitResponse( | 134 SyncerError ProcessCommitResponseCommand::ProcessCommitResponse( |
134 SyncSession* session) { | 135 SyncSession* session) { |
135 // TODO(sync): This function returns if it sees problems. We probably want | |
136 // to flag the need for an update or similar. | |
137 ScopedDirLookup dir(session->context()->directory_manager(), | 136 ScopedDirLookup dir(session->context()->directory_manager(), |
138 session->context()->account_name()); | 137 session->context()->account_name()); |
139 if (!dir.good()) { | 138 if (!dir.good()) { |
140 LOG(ERROR) << "Scoped dir lookup failed!"; | 139 LOG(ERROR) << "Scoped dir lookup failed!"; |
141 return; | 140 return DIRECTORY_LOOKUP_FAILED; |
142 } | 141 } |
143 | 142 |
144 StatusController* status = session->mutable_status_controller(); | 143 StatusController* status = session->mutable_status_controller(); |
145 const ClientToServerResponse& response(status->commit_response()); | 144 const ClientToServerResponse& response(status->commit_response()); |
146 const CommitResponse& cr = response.commit(); | 145 const CommitResponse& cr = response.commit(); |
147 const sync_pb::CommitMessage& commit_message = | 146 const sync_pb::CommitMessage& commit_message = |
148 status->commit_message().commit(); | 147 status->commit_message().commit(); |
149 | 148 |
150 // If we try to commit a parent and child together and the parent conflicts | 149 // If we try to commit a parent and child together and the parent conflicts |
151 // the child will have a bad parent causing an error. As this is not a | 150 // the child will have a bad parent causing an error. As this is not a |
(...skipping 30 matching lines...) Expand all Loading... |
182 // TODO(sync): worry about sync_rate_ rate calc? | 181 // TODO(sync): worry about sync_rate_ rate calc? |
183 ++successes; | 182 ++successes; |
184 if (status->GetCommitModelTypeAt(proj[i]) == syncable::BOOKMARKS) | 183 if (status->GetCommitModelTypeAt(proj[i]) == syncable::BOOKMARKS) |
185 status->increment_num_successful_bookmark_commits(); | 184 status->increment_num_successful_bookmark_commits(); |
186 status->increment_num_successful_commits(); | 185 status->increment_num_successful_commits(); |
187 break; | 186 break; |
188 case CommitResponse::OVER_QUOTA: | 187 case CommitResponse::OVER_QUOTA: |
189 // We handle over quota like a retry, which is same as transient. | 188 // We handle over quota like a retry, which is same as transient. |
190 case CommitResponse::RETRY: | 189 case CommitResponse::RETRY: |
191 case CommitResponse::TRANSIENT_ERROR: | 190 case CommitResponse::TRANSIENT_ERROR: |
192 // TODO(tim): Now that we have SyncSession::Delegate, we | |
193 // should plumb this directly for exponential backoff purposes rather | |
194 // than trying to infer from HasMoreToSync(). See | |
195 // SyncerThread::CalculatePollingWaitTime. | |
196 ++transient_error_commits; | 191 ++transient_error_commits; |
197 break; | 192 break; |
198 default: | 193 default: |
199 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; | 194 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; |
200 } | 195 } |
201 } | 196 } |
202 } | 197 } |
203 | 198 |
204 // TODO(sync): move status reporting elsewhere. | 199 // TODO(sync): move status reporting elsewhere. |
| 200 int commit_count = static_cast<int>(proj.size()); |
205 status->increment_num_conflicting_commits_by(conflicting_commits); | 201 status->increment_num_conflicting_commits_by(conflicting_commits); |
206 if (0 == successes) { | 202 if (0 == successes) { |
207 status->increment_num_consecutive_transient_error_commits_by( | 203 status->increment_num_consecutive_transient_error_commits_by( |
208 transient_error_commits); | 204 transient_error_commits); |
209 status->increment_num_consecutive_errors_by(transient_error_commits); | 205 status->increment_num_consecutive_errors_by(transient_error_commits); |
210 } else { | 206 } else { |
211 status->set_num_consecutive_transient_error_commits(0); | 207 status->set_num_consecutive_transient_error_commits(0); |
212 status->set_num_consecutive_errors(0); | 208 status->set_num_consecutive_errors(0); |
213 } | 209 } |
214 int commit_count = static_cast<int>(proj.size()); | |
215 if (commit_count != (conflicting_commits + error_commits + | 210 if (commit_count != (conflicting_commits + error_commits + |
216 transient_error_commits)) { | 211 transient_error_commits)) { |
217 ResetErrorCounters(status); | 212 ResetErrorCounters(status); |
218 } | 213 } |
219 SyncerUtil::MarkDeletedChildrenSynced(dir, &deleted_folders); | 214 SyncerUtil::MarkDeletedChildrenSynced(dir, &deleted_folders); |
220 | 215 |
221 return; | 216 if (commit_count == (successes + conflicting_commits)) { |
| 217 // We consider conflicting commits as a success because things will work out |
| 218 // on their own when we receive them. Flags will be set so that |
| 219 // HasMoreToSync() will cause SyncScheduler to enter another sync cycle to |
| 220 // handle this condition. |
| 221 return NO_ERROR; |
| 222 } else if (error_commits > 0) { |
| 223 return SERVER_RETURN_UNKNOWN_ERROR; |
| 224 } else if (transient_error_commits > 0) { |
| 225 return SERVER_RETURN_TRANSIENT_ERROR; |
| 226 } else { |
| 227 LOG(FATAL) << "Inconsistent counts when processing commit response"; |
| 228 return NO_ERROR; |
| 229 } |
222 } | 230 } |
223 | 231 |
224 void LogServerError(const CommitResponse_EntryResponse& res) { | 232 void LogServerError(const CommitResponse_EntryResponse& res) { |
225 if (res.has_error_message()) | 233 if (res.has_error_message()) |
226 LOG(WARNING) << " " << res.error_message(); | 234 LOG(WARNING) << " " << res.error_message(); |
227 else | 235 else |
228 LOG(WARNING) << " No detailed error message returned from server"; | 236 LOG(WARNING) << " No detailed error message returned from server"; |
229 } | 237 } |
230 | 238 |
231 CommitResponse::ResponseType | 239 CommitResponse::ResponseType |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // been recursively deleted. | 515 // been recursively deleted. |
508 // TODO(nick): Here, commit_message.deleted() would be more correct than | 516 // TODO(nick): Here, commit_message.deleted() would be more correct than |
509 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then | 517 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then |
510 // deleted during the commit of the rename. Unit test & fix. | 518 // deleted during the commit of the rename. Unit test & fix. |
511 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { | 519 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { |
512 deleted_folders->insert(local_entry->Get(ID)); | 520 deleted_folders->insert(local_entry->Get(ID)); |
513 } | 521 } |
514 } | 522 } |
515 | 523 |
516 } // namespace browser_sync | 524 } // namespace browser_sync |
OLD | NEW |