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()); |
113 session->context()->PruneUnthrottledTypes(base::TimeTicks::Now()); | 124 session->context()->PruneUnthrottledTypes(base::TimeTicks::Now()); |
114 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); | 125 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); |
115 | 126 |
116 next_step = CLEANUP_DISABLED_TYPES; | 127 next_step = CLEANUP_DISABLED_TYPES; |
117 break; | 128 break; |
118 case CLEANUP_DISABLED_TYPES: { | 129 case CLEANUP_DISABLED_TYPES: { |
119 CleanupDisabledTypesCommand cleanup; | 130 CleanupDisabledTypesCommand cleanup; |
120 cleanup.Execute(session); | 131 cleanup.Execute(session); |
121 next_step = DOWNLOAD_UPDATES; | 132 next_step = DOWNLOAD_UPDATES; |
122 break; | 133 break; |
(...skipping 25 matching lines...) Expand all Loading... |
148 } | 159 } |
149 case PROCESS_UPDATES: { | 160 case PROCESS_UPDATES: { |
150 ProcessUpdatesCommand process_updates; | 161 ProcessUpdatesCommand process_updates; |
151 process_updates.Execute(session); | 162 process_updates.Execute(session); |
152 next_step = STORE_TIMESTAMPS; | 163 next_step = STORE_TIMESTAMPS; |
153 break; | 164 break; |
154 } | 165 } |
155 case STORE_TIMESTAMPS: { | 166 case STORE_TIMESTAMPS: { |
156 StoreTimestampsCommand store_timestamps; | 167 StoreTimestampsCommand store_timestamps; |
157 store_timestamps.Execute(session); | 168 store_timestamps.Execute(session); |
158 // We download all of the updates before attempting to apply them. | 169 // We should download all of the updates before attempting to process |
159 if (!session->status_controller().download_updates_succeeded()) { | 170 // them. |
160 // We may have downloaded some updates, but if the latest download | 171 if (session->status_controller().ServerSaysNothingMoreToDownload() || |
161 // attempt failed then we don't have all the updates. We'll leave | 172 !session->status_controller().download_updates_succeeded()) { |
162 // it to a retry job to pick up where we left off. | 173 next_step = APPLY_UPDATES; |
163 last_step = SYNCER_END; // Necessary for CONFIGURATION mode. | 174 } else { |
164 next_step = SYNCER_END; | |
165 DVLOG(1) << "Aborting sync cycle due to download updates failure"; | |
166 } else if (!session->status_controller() | |
167 .ServerSaysNothingMoreToDownload()) { | |
168 next_step = DOWNLOAD_UPDATES; | 175 next_step = DOWNLOAD_UPDATES; |
169 } else { | |
170 next_step = APPLY_UPDATES; | |
171 } | 176 } |
172 break; | 177 break; |
173 } | 178 } |
174 case APPLY_UPDATES: { | 179 case APPLY_UPDATES: { |
175 ApplyUpdatesCommand apply_updates; | 180 ApplyUpdatesCommand apply_updates; |
176 apply_updates.Execute(session); | 181 apply_updates.Execute(session); |
177 if (last_step == APPLY_UPDATES) { | 182 if (last_step == APPLY_UPDATES) { |
178 // We're in configuration mode, but we still need to run the | 183 // We're in configuration mode, but we still need to run the |
179 // SYNCER_END step. | 184 // SYNCER_END step. |
180 last_step = SYNCER_END; | 185 last_step = SYNCER_END; |
(...skipping 10 matching lines...) Expand all Loading... |
191 WriteTransaction trans(FROM_HERE, SYNCER, dir); | 196 WriteTransaction trans(FROM_HERE, SYNCER, dir); |
192 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | 197 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
193 | 198 |
194 DVLOG(1) << "Getting the Commit IDs"; | 199 DVLOG(1) << "Getting the Commit IDs"; |
195 GetCommitIdsCommand get_commit_ids_command( | 200 GetCommitIdsCommand get_commit_ids_command( |
196 session->context()->max_commit_batch_size()); | 201 session->context()->max_commit_batch_size()); |
197 get_commit_ids_command.Execute(session); | 202 get_commit_ids_command.Execute(session); |
198 | 203 |
199 if (!session->status_controller().commit_ids().empty()) { | 204 if (!session->status_controller().commit_ids().empty()) { |
200 DVLOG(1) << "Building a commit message"; | 205 DVLOG(1) << "Building a commit message"; |
201 | |
202 // This isn't perfect, since the set of extensions activity may not | |
203 // correlate exactly with the items being committed. That's OK as | |
204 // long as we're looking for a rough estimate of extensions activity, | |
205 // not an precise mapping of which commits were triggered by which | |
206 // extension. | |
207 // | |
208 // We will push this list of extensions activity back into the | |
209 // ExtensionsActivityMonitor if this commit turns out to not contain | |
210 // any bookmarks, or if the commit fails. | |
211 session->context()->extensions_monitor()->GetAndClearRecords( | |
212 session->mutable_extensions_activity()); | |
213 | |
214 BuildCommitCommand build_commit_command; | 206 BuildCommitCommand build_commit_command; |
215 build_commit_command.Execute(session); | 207 build_commit_command.Execute(session); |
216 | 208 |
217 next_step = POST_COMMIT_MESSAGE; | 209 next_step = POST_COMMIT_MESSAGE; |
218 } else { | 210 } else { |
219 next_step = RESOLVE_CONFLICTS; | 211 next_step = RESOLVE_CONFLICTS; |
220 } | 212 } |
221 | 213 |
222 break; | 214 break; |
223 } | 215 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 entry->Put(SERVER_CTIME, Time()); | 336 entry->Put(SERVER_CTIME, Time()); |
345 entry->Put(SERVER_VERSION, 0); | 337 entry->Put(SERVER_VERSION, 0); |
346 entry->Put(SERVER_IS_DIR, false); | 338 entry->Put(SERVER_IS_DIR, false); |
347 entry->Put(SERVER_IS_DEL, false); | 339 entry->Put(SERVER_IS_DEL, false); |
348 entry->Put(IS_UNAPPLIED_UPDATE, false); | 340 entry->Put(IS_UNAPPLIED_UPDATE, false); |
349 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 341 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
350 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 342 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
351 } | 343 } |
352 | 344 |
353 } // namespace browser_sync | 345 } // namespace browser_sync |
OLD | NEW |