OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/syncer.h" | 5 #include "sync/engine/syncer.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 SyncerStep current_step = first_step; | 103 SyncerStep current_step = first_step; |
104 | 104 |
105 SyncerStep next_step = current_step; | 105 SyncerStep next_step = current_step; |
106 while (!ExitRequested()) { | 106 while (!ExitRequested()) { |
107 TRACE_EVENT1("sync", "SyncerStateMachine", | 107 TRACE_EVENT1("sync", "SyncerStateMachine", |
108 "state", SyncerStepToString(current_step)); | 108 "state", SyncerStepToString(current_step)); |
109 DVLOG(1) << "Syncer step:" << SyncerStepToString(current_step); | 109 DVLOG(1) << "Syncer step:" << SyncerStepToString(current_step); |
110 | 110 |
111 switch (current_step) { | 111 switch (current_step) { |
112 case SYNCER_BEGIN: | 112 case SYNCER_BEGIN: |
113 // This isn't perfect, as we can end up bundling extensions activity | |
114 // intended for the next session into the current one. We could do a | |
115 // test-and-reset as with the source, but note that also falls short if | |
116 // the commit request fails (e.g. due to lost connection), as we will | |
117 // fall all the way back to the syncer thread main loop in that case, | |
118 // creating a new session when a connection is established, losing the | |
119 // records set here on the original attempt. This should provide us | |
120 // with the right data "most of the time", and we're only using this | |
121 // for analysis purposes, so Law of Large Numbers FTW. | |
122 session->context()->extensions_monitor()->GetAndClearRecords( | |
123 session->mutable_extensions_activity()); | |
124 session->context()->PruneUnthrottledTypes(base::TimeTicks::Now()); | 113 session->context()->PruneUnthrottledTypes(base::TimeTicks::Now()); |
125 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); | 114 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); |
126 | 115 |
127 next_step = CLEANUP_DISABLED_TYPES; | 116 next_step = CLEANUP_DISABLED_TYPES; |
128 break; | 117 break; |
129 case CLEANUP_DISABLED_TYPES: { | 118 case CLEANUP_DISABLED_TYPES: { |
130 CleanupDisabledTypesCommand cleanup; | 119 CleanupDisabledTypesCommand cleanup; |
131 cleanup.Execute(session); | 120 cleanup.Execute(session); |
132 next_step = DOWNLOAD_UPDATES; | 121 next_step = DOWNLOAD_UPDATES; |
133 break; | 122 break; |
(...skipping 25 matching lines...) Expand all Loading... | |
159 } | 148 } |
160 case PROCESS_UPDATES: { | 149 case PROCESS_UPDATES: { |
161 ProcessUpdatesCommand process_updates; | 150 ProcessUpdatesCommand process_updates; |
162 process_updates.Execute(session); | 151 process_updates.Execute(session); |
163 next_step = STORE_TIMESTAMPS; | 152 next_step = STORE_TIMESTAMPS; |
164 break; | 153 break; |
165 } | 154 } |
166 case STORE_TIMESTAMPS: { | 155 case STORE_TIMESTAMPS: { |
167 StoreTimestampsCommand store_timestamps; | 156 StoreTimestampsCommand store_timestamps; |
168 store_timestamps.Execute(session); | 157 store_timestamps.Execute(session); |
169 // We should download all of the updates before attempting to process | 158 // We download all of the updates before attempting to apply them. |
170 // them. | 159 SyncerError result = |
171 if (session->status_controller().ServerSaysNothingMoreToDownload() || | 160 session->status_controller().last_download_updates_result(); |
172 !session->status_controller().download_updates_succeeded()) { | 161 if (result == SYNCER_OK) { |
162 const ClientToServerResponse& updates_response = | |
163 session->status_controller().updates_response(); | |
tim (not reviewing)
2012/04/20 16:41:07
You're doing this just to get changes_remaining, r
rlarocque
2012/04/23 20:16:49
The next revision of this patch should avoid this
| |
164 // Loop back if we still have more to download. Otherwise exit this | |
165 // loop normally. | |
166 DCHECK(updates_response.get_updates().has_changes_remaining()); | |
167 if (updates_response.get_updates().changes_remaining() != 0) { | |
168 next_step = DOWNLOAD_UPDATES; | |
169 } else { | |
170 next_step = APPLY_UPDATES; | |
171 } | |
172 } else if (result == SERVER_RETURN_MIGRATION_DONE) { | |
173 // The MIGRATION_DONE case is special. The migration test code relies | |
tim (not reviewing)
2012/04/20 16:41:07
As far as I can tell it is actually handled natura
rlarocque
2012/04/23 20:16:49
Same as above.
| |
174 // on all sorts of strange side effects, and this is one of them. The | |
175 // effect of this special case is that we will count downloads that | |
176 // encounter migration_done errors as non-failures, while jobs that do | |
177 // attempt to commit will be counted as failures most of the time, | |
tim (not reviewing)
2012/04/20 16:41:07
I'm having a hard time groking this: "... we will
rlarocque
2012/04/23 20:16:49
This will also be simplified in the next revision.
| |
178 // because they will fail PROCESS_COMMIT_RESPONSE. In short, we're | |
179 // trying to make sure that the necessary changes for crbug.com/122033 | |
180 // do not upset the delicate balance that allows the migration tests | |
181 // to pass. | |
182 // | |
183 // We are tracking some of the effort to clean up this mess at | |
184 // crbug.com/123954. | |
173 next_step = APPLY_UPDATES; | 185 next_step = APPLY_UPDATES; |
174 } else { | 186 } else { |
175 next_step = DOWNLOAD_UPDATES; | 187 // All other errors. We should not attempt to apply updates until we |
188 // have received all of them. At this point, we have not received all | |
189 // downloads so we should not attempt to apply any of the updates that | |
190 // we have downloded successfully. | |
191 last_step = SYNCER_END; // Necessary for CONFIGURATION mode. | |
192 next_step = SYNCER_END; | |
193 DVLOG(1) << "Aborting sync cycle due to download updates failure"; | |
176 } | 194 } |
177 break; | 195 break; |
178 } | 196 } |
179 case APPLY_UPDATES: { | 197 case APPLY_UPDATES: { |
180 ApplyUpdatesCommand apply_updates; | 198 ApplyUpdatesCommand apply_updates; |
181 apply_updates.Execute(session); | 199 apply_updates.Execute(session); |
182 if (last_step == APPLY_UPDATES) { | 200 if (last_step == APPLY_UPDATES) { |
183 // We're in configuration mode, but we still need to run the | 201 // We're in configuration mode, but we still need to run the |
184 // SYNCER_END step. | 202 // SYNCER_END step. |
185 last_step = SYNCER_END; | 203 last_step = SYNCER_END; |
(...skipping 10 matching lines...) Expand all Loading... | |
196 WriteTransaction trans(FROM_HERE, SYNCER, dir); | 214 WriteTransaction trans(FROM_HERE, SYNCER, dir); |
197 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | 215 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
198 | 216 |
199 DVLOG(1) << "Getting the Commit IDs"; | 217 DVLOG(1) << "Getting the Commit IDs"; |
200 GetCommitIdsCommand get_commit_ids_command( | 218 GetCommitIdsCommand get_commit_ids_command( |
201 session->context()->max_commit_batch_size()); | 219 session->context()->max_commit_batch_size()); |
202 get_commit_ids_command.Execute(session); | 220 get_commit_ids_command.Execute(session); |
203 | 221 |
204 if (!session->status_controller().commit_ids().empty()) { | 222 if (!session->status_controller().commit_ids().empty()) { |
205 DVLOG(1) << "Building a commit message"; | 223 DVLOG(1) << "Building a commit message"; |
224 | |
225 // This isn't perfect, since the set of extensions activity may not | |
226 // correlate exactly with the items being committed. That's OK as | |
227 // long as we're looking for a rough estimate of extensions activity, | |
228 // not an precise mapping of which commits were triggered by which | |
229 // extension. | |
230 // | |
231 // We will push this list of extensions activity back into the | |
232 // ExtensionsActivityMonitor if this commit turns out to not contain | |
233 // any bookmarks, or if the commit fails. | |
234 session->context()->extensions_monitor()->GetAndClearRecords( | |
235 session->mutable_extensions_activity()); | |
236 | |
206 BuildCommitCommand build_commit_command; | 237 BuildCommitCommand build_commit_command; |
207 build_commit_command.Execute(session); | 238 build_commit_command.Execute(session); |
208 | 239 |
209 next_step = POST_COMMIT_MESSAGE; | 240 next_step = POST_COMMIT_MESSAGE; |
210 } else { | 241 } else { |
211 next_step = RESOLVE_CONFLICTS; | 242 next_step = RESOLVE_CONFLICTS; |
212 } | 243 } |
213 | 244 |
214 break; | 245 break; |
215 } | 246 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 entry->Put(SERVER_CTIME, Time()); | 367 entry->Put(SERVER_CTIME, Time()); |
337 entry->Put(SERVER_VERSION, 0); | 368 entry->Put(SERVER_VERSION, 0); |
338 entry->Put(SERVER_IS_DIR, false); | 369 entry->Put(SERVER_IS_DIR, false); |
339 entry->Put(SERVER_IS_DEL, false); | 370 entry->Put(SERVER_IS_DEL, false); |
340 entry->Put(IS_UNAPPLIED_UPDATE, false); | 371 entry->Put(IS_UNAPPLIED_UPDATE, false); |
341 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 372 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
342 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 373 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
343 } | 374 } |
344 | 375 |
345 } // namespace browser_sync | 376 } // namespace browser_sync |
OLD | NEW |