| 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/syncer.h" | 5 #include "chrome/browser/sync/engine/syncer.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 namespace browser_sync { | 50 namespace browser_sync { |
| 51 | 51 |
| 52 using sessions::ScopedSessionContextConflictResolver; | 52 using sessions::ScopedSessionContextConflictResolver; |
| 53 using sessions::StatusController; | 53 using sessions::StatusController; |
| 54 using sessions::SyncSession; | 54 using sessions::SyncSession; |
| 55 using sessions::ConflictProgress; | 55 using sessions::ConflictProgress; |
| 56 | 56 |
| 57 Syncer::ScopedSyncStartStopTracker::ScopedSyncStartStopTracker( | 57 Syncer::ScopedSyncStartStopTracker::ScopedSyncStartStopTracker( |
| 58 sessions::SyncSession* session) : session_(session) { | 58 sessions::SyncSession* session) : session_(session) { |
| 59 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(true); | 59 session_->mutable_status_controller()-> |
| 60 SetSyncInProgressAndUpdateStartTime(true); |
| 60 } | 61 } |
| 61 | 62 |
| 62 Syncer::ScopedSyncStartStopTracker::~ScopedSyncStartStopTracker() { | 63 Syncer::ScopedSyncStartStopTracker::~ScopedSyncStartStopTracker() { |
| 63 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(false); | 64 session_->mutable_status_controller()-> |
| 65 SetSyncInProgressAndUpdateStartTime(false); |
| 64 } | 66 } |
| 65 | 67 |
| 66 Syncer::Syncer() | 68 Syncer::Syncer() |
| 67 : early_exit_requested_(false), | 69 : early_exit_requested_(false), |
| 68 pre_conflict_resolution_closure_(NULL) { | 70 pre_conflict_resolution_closure_(NULL) { |
| 69 } | 71 } |
| 70 | 72 |
| 71 Syncer::~Syncer() {} | 73 Syncer::~Syncer() {} |
| 72 | 74 |
| 73 bool Syncer::ExitRequested() { | 75 bool Syncer::ExitRequested() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 process_updates.Execute(session); | 149 process_updates.Execute(session); |
| 148 next_step = STORE_TIMESTAMPS; | 150 next_step = STORE_TIMESTAMPS; |
| 149 break; | 151 break; |
| 150 } | 152 } |
| 151 case STORE_TIMESTAMPS: { | 153 case STORE_TIMESTAMPS: { |
| 152 VLOG(1) << "Storing timestamps"; | 154 VLOG(1) << "Storing timestamps"; |
| 153 StoreTimestampsCommand store_timestamps; | 155 StoreTimestampsCommand store_timestamps; |
| 154 store_timestamps.Execute(session); | 156 store_timestamps.Execute(session); |
| 155 // We should download all of the updates before attempting to process | 157 // We should download all of the updates before attempting to process |
| 156 // them. | 158 // them. |
| 157 if (session->status_controller()->ServerSaysNothingMoreToDownload() || | 159 if (session->status_controller().ServerSaysNothingMoreToDownload() || |
| 158 !session->status_controller()->download_updates_succeeded()) { | 160 !session->status_controller().download_updates_succeeded()) { |
| 159 next_step = APPLY_UPDATES; | 161 next_step = APPLY_UPDATES; |
| 160 } else { | 162 } else { |
| 161 next_step = DOWNLOAD_UPDATES; | 163 next_step = DOWNLOAD_UPDATES; |
| 162 } | 164 } |
| 163 break; | 165 break; |
| 164 } | 166 } |
| 165 case APPLY_UPDATES: { | 167 case APPLY_UPDATES: { |
| 166 VLOG(1) << "Applying Updates"; | 168 VLOG(1) << "Applying Updates"; |
| 167 ApplyUpdatesCommand apply_updates; | 169 ApplyUpdatesCommand apply_updates; |
| 168 apply_updates.Execute(session); | 170 apply_updates.Execute(session); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 187 return; | 189 return; |
| 188 } | 190 } |
| 189 WriteTransaction trans(FROM_HERE, SYNCER, dir); | 191 WriteTransaction trans(FROM_HERE, SYNCER, dir); |
| 190 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | 192 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
| 191 | 193 |
| 192 VLOG(1) << "Getting the Commit IDs"; | 194 VLOG(1) << "Getting the Commit IDs"; |
| 193 GetCommitIdsCommand get_commit_ids_command( | 195 GetCommitIdsCommand get_commit_ids_command( |
| 194 session->context()->max_commit_batch_size()); | 196 session->context()->max_commit_batch_size()); |
| 195 get_commit_ids_command.Execute(session); | 197 get_commit_ids_command.Execute(session); |
| 196 | 198 |
| 197 if (!session->status_controller()->commit_ids().empty()) { | 199 if (!session->status_controller().commit_ids().empty()) { |
| 198 VLOG(1) << "Building a commit message"; | 200 VLOG(1) << "Building a commit message"; |
| 199 BuildCommitCommand build_commit_command; | 201 BuildCommitCommand build_commit_command; |
| 200 build_commit_command.Execute(session); | 202 build_commit_command.Execute(session); |
| 201 | 203 |
| 202 next_step = POST_COMMIT_MESSAGE; | 204 next_step = POST_COMMIT_MESSAGE; |
| 203 } else { | 205 } else { |
| 204 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 206 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
| 205 } | 207 } |
| 206 | 208 |
| 207 break; | 209 break; |
| 208 } | 210 } |
| 209 case POST_COMMIT_MESSAGE: { | 211 case POST_COMMIT_MESSAGE: { |
| 210 VLOG(1) << "Posting a commit request"; | 212 VLOG(1) << "Posting a commit request"; |
| 211 PostCommitMessageCommand post_commit_command; | 213 PostCommitMessageCommand post_commit_command; |
| 212 post_commit_command.Execute(session); | 214 post_commit_command.Execute(session); |
| 213 next_step = PROCESS_COMMIT_RESPONSE; | 215 next_step = PROCESS_COMMIT_RESPONSE; |
| 214 break; | 216 break; |
| 215 } | 217 } |
| 216 case PROCESS_COMMIT_RESPONSE: { | 218 case PROCESS_COMMIT_RESPONSE: { |
| 217 VLOG(1) << "Processing the commit response"; | 219 VLOG(1) << "Processing the commit response"; |
| 218 session->status_controller()->reset_num_conflicting_commits(); | 220 session->mutable_status_controller()->reset_num_conflicting_commits(); |
| 219 ProcessCommitResponseCommand process_response_command; | 221 ProcessCommitResponseCommand process_response_command; |
| 220 process_response_command.Execute(session); | 222 process_response_command.Execute(session); |
| 221 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 223 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
| 222 break; | 224 break; |
| 223 } | 225 } |
| 224 case BUILD_AND_PROCESS_CONFLICT_SETS: { | 226 case BUILD_AND_PROCESS_CONFLICT_SETS: { |
| 225 VLOG(1) << "Building and Processing Conflict Sets"; | 227 VLOG(1) << "Building and Processing Conflict Sets"; |
| 226 BuildAndProcessConflictSetsCommand build_process_conflict_sets; | 228 BuildAndProcessConflictSetsCommand build_process_conflict_sets; |
| 227 build_process_conflict_sets.Execute(session); | 229 build_process_conflict_sets.Execute(session); |
| 228 if (session->status_controller()->conflict_sets_built()) | 230 if (session->status_controller().conflict_sets_built()) |
| 229 next_step = SYNCER_END; | 231 next_step = SYNCER_END; |
| 230 else | 232 else |
| 231 next_step = RESOLVE_CONFLICTS; | 233 next_step = RESOLVE_CONFLICTS; |
| 232 break; | 234 break; |
| 233 } | 235 } |
| 234 case RESOLVE_CONFLICTS: { | 236 case RESOLVE_CONFLICTS: { |
| 235 VLOG(1) << "Resolving Conflicts"; | 237 VLOG(1) << "Resolving Conflicts"; |
| 236 | 238 |
| 237 // Trigger the pre_conflict_resolution_closure_, which is a testing | 239 // Trigger the pre_conflict_resolution_closure_, which is a testing |
| 238 // hook for the unit tests, if it is non-NULL. | 240 // hook for the unit tests, if it is non-NULL. |
| 239 if (pre_conflict_resolution_closure_) { | 241 if (pre_conflict_resolution_closure_) { |
| 240 pre_conflict_resolution_closure_->Run(); | 242 pre_conflict_resolution_closure_->Run(); |
| 241 } | 243 } |
| 242 | 244 |
| 243 StatusController* status = session->status_controller(); | 245 StatusController* status = session->mutable_status_controller(); |
| 244 status->reset_conflicts_resolved(); | 246 status->reset_conflicts_resolved(); |
| 245 ResolveConflictsCommand resolve_conflicts_command; | 247 ResolveConflictsCommand resolve_conflicts_command; |
| 246 resolve_conflicts_command.Execute(session); | 248 resolve_conflicts_command.Execute(session); |
| 247 | 249 |
| 248 // Has ConflictingUpdates includes both blocking and non-blocking | 250 // Has ConflictingUpdates includes both blocking and non-blocking |
| 249 // conflicts. If we have either, we want to attempt to reapply. | 251 // conflicts. If we have either, we want to attempt to reapply. |
| 250 if (status->HasConflictingUpdates()) | 252 if (status->HasConflictingUpdates()) |
| 251 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; | 253 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; |
| 252 else | 254 else |
| 253 next_step = SYNCER_END; | 255 next_step = SYNCER_END; |
| 254 break; | 256 break; |
| 255 } | 257 } |
| 256 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { | 258 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { |
| 257 StatusController* status = session->status_controller(); | 259 StatusController* status = session->mutable_status_controller(); |
| 258 VLOG(1) << "Applying updates to resolve conflicts"; | 260 VLOG(1) << "Applying updates to resolve conflicts"; |
| 259 ApplyUpdatesCommand apply_updates; | 261 ApplyUpdatesCommand apply_updates; |
| 260 | 262 |
| 261 // We only care to resolve conflicts again if we made progress on the | 263 // We only care to resolve conflicts again if we made progress on the |
| 262 // blocking conflicts. Whether or not we made progress on the | 264 // blocking conflicts. Whether or not we made progress on the |
| 263 // non-blocking doesn't matter. | 265 // non-blocking doesn't matter. |
| 264 int before_blocking_conflicting_updates = | 266 int before_blocking_conflicting_updates = |
| 265 status->TotalNumBlockingConflictingItems(); | 267 status->TotalNumBlockingConflictingItems(); |
| 266 apply_updates.Execute(session); | 268 apply_updates.Execute(session); |
| 267 int after_blocking_conflicting_updates = | 269 int after_blocking_conflicting_updates = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 296 << next_step << ", snapshot: " | 298 << next_step << ", snapshot: " |
| 297 << session->TakeSnapshot().ToString(); | 299 << session->TakeSnapshot().ToString(); |
| 298 if (last_step == current_step) | 300 if (last_step == current_step) |
| 299 break; | 301 break; |
| 300 current_step = next_step; | 302 current_step = next_step; |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 void Syncer::ProcessClientCommand(sessions::SyncSession* session) { | 306 void Syncer::ProcessClientCommand(sessions::SyncSession* session) { |
| 305 const ClientToServerResponse& response = | 307 const ClientToServerResponse& response = |
| 306 session->status_controller()->updates_response(); | 308 session->status_controller().updates_response(); |
| 307 if (!response.has_client_command()) | 309 if (!response.has_client_command()) |
| 308 return; | 310 return; |
| 309 const ClientCommand& command = response.client_command(); | 311 const ClientCommand& command = response.client_command(); |
| 310 | 312 |
| 311 // The server limits the number of items a client can commit in one batch. | 313 // The server limits the number of items a client can commit in one batch. |
| 312 if (command.has_max_commit_batch_size()) { | 314 if (command.has_max_commit_batch_size()) { |
| 313 session->context()->set_max_commit_batch_size( | 315 session->context()->set_max_commit_batch_size( |
| 314 command.max_commit_batch_size()); | 316 command.max_commit_batch_size()); |
| 315 } | 317 } |
| 316 if (command.has_set_sync_long_poll_interval()) { | 318 if (command.has_set_sync_long_poll_interval()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 entry->Put(SERVER_CTIME, Time()); | 350 entry->Put(SERVER_CTIME, Time()); |
| 349 entry->Put(SERVER_VERSION, 0); | 351 entry->Put(SERVER_VERSION, 0); |
| 350 entry->Put(SERVER_IS_DIR, false); | 352 entry->Put(SERVER_IS_DIR, false); |
| 351 entry->Put(SERVER_IS_DEL, false); | 353 entry->Put(SERVER_IS_DEL, false); |
| 352 entry->Put(IS_UNAPPLIED_UPDATE, false); | 354 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 353 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 355 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 354 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 356 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 355 } | 357 } |
| 356 | 358 |
| 357 } // namespace browser_sync | 359 } // namespace browser_sync |
| OLD | NEW |