| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 entry. | 3 // found in the LICENSE entry. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/engine/syncer.h" | 5 #include "chrome/browser/sync/engine/syncer.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" |
| 9 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 11 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| 11 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" | 12 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h" |
| 12 #include "chrome/browser/sync/engine/build_commit_command.h" | 13 #include "chrome/browser/sync/engine/build_commit_command.h" |
| 13 #include "chrome/browser/sync/engine/conflict_resolver.h" | 14 #include "chrome/browser/sync/engine/conflict_resolver.h" |
| 14 #include "chrome/browser/sync/engine/download_updates_command.h" | 15 #include "chrome/browser/sync/engine/download_updates_command.h" |
| 15 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 16 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
| 16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 17 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 17 #include "chrome/browser/sync/engine/post_commit_message_command.h" | 18 #include "chrome/browser/sync/engine/post_commit_message_command.h" |
| 18 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 19 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
| 19 #include "chrome/browser/sync/engine/process_updates_command.h" | 20 #include "chrome/browser/sync/engine/process_updates_command.h" |
| 20 #include "chrome/browser/sync/engine/resolve_conflicts_command.h" | 21 #include "chrome/browser/sync/engine/resolve_conflicts_command.h" |
| 21 #include "chrome/browser/sync/engine/syncer_end_command.h" | 22 #include "chrome/browser/sync/engine/syncer_end_command.h" |
| 22 #include "chrome/browser/sync/engine/syncer_types.h" | 23 #include "chrome/browser/sync/engine/syncer_types.h" |
| 23 #include "chrome/browser/sync/engine/syncer_util.h" | 24 #include "chrome/browser/sync/engine/syncer_util.h" |
| 24 #include "chrome/browser/sync/engine/syncproto.h" | 25 #include "chrome/browser/sync/engine/syncproto.h" |
| 25 #include "chrome/browser/sync/engine/verify_updates_command.h" | 26 #include "chrome/browser/sync/engine/verify_updates_command.h" |
| 26 #include "chrome/browser/sync/syncable/directory_manager.h" | 27 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 27 #include "chrome/browser/sync/syncable/syncable-inl.h" | 28 #include "chrome/browser/sync/syncable/syncable-inl.h" |
| 28 #include "chrome/browser/sync/syncable/syncable.h" | 29 #include "chrome/browser/sync/syncable/syncable.h" |
| 29 #include "chrome/browser/sync/util/closure.h" | 30 #include "chrome/browser/sync/util/closure.h" |
| 30 | 31 |
| 32 using base::TimeDelta; |
| 31 using sync_pb::ClientCommand; | 33 using sync_pb::ClientCommand; |
| 32 using syncable::Blob; | 34 using syncable::Blob; |
| 33 using syncable::IS_UNAPPLIED_UPDATE; | 35 using syncable::IS_UNAPPLIED_UPDATE; |
| 34 using syncable::SERVER_BOOKMARK_FAVICON; | 36 using syncable::SERVER_BOOKMARK_FAVICON; |
| 35 using syncable::SERVER_BOOKMARK_URL; | 37 using syncable::SERVER_BOOKMARK_URL; |
| 36 using syncable::SERVER_CTIME; | 38 using syncable::SERVER_CTIME; |
| 37 using syncable::SERVER_IS_BOOKMARK_OBJECT; | 39 using syncable::SERVER_IS_BOOKMARK_OBJECT; |
| 38 using syncable::SERVER_IS_DEL; | 40 using syncable::SERVER_IS_DEL; |
| 39 using syncable::SERVER_IS_DIR; | 41 using syncable::SERVER_IS_DIR; |
| 40 using syncable::SERVER_MTIME; | 42 using syncable::SERVER_MTIME; |
| 41 using syncable::SERVER_NON_UNIQUE_NAME; | 43 using syncable::SERVER_NON_UNIQUE_NAME; |
| 42 using syncable::SERVER_PARENT_ID; | 44 using syncable::SERVER_PARENT_ID; |
| 43 using syncable::SERVER_POSITION_IN_PARENT; | 45 using syncable::SERVER_POSITION_IN_PARENT; |
| 44 using syncable::SERVER_VERSION; | 46 using syncable::SERVER_VERSION; |
| 45 using syncable::SYNCER; | 47 using syncable::SYNCER; |
| 46 using syncable::ScopedDirLookup; | 48 using syncable::ScopedDirLookup; |
| 47 using syncable::WriteTransaction; | 49 using syncable::WriteTransaction; |
| 48 | 50 |
| 49 namespace browser_sync { | 51 namespace browser_sync { |
| 50 | 52 |
| 51 Syncer::Syncer( | 53 using sessions::StatusController; |
| 52 syncable::DirectoryManager* dirman, | 54 using sessions::SyncSession; |
| 53 const PathString& account_name, | 55 using sessions::ConflictProgress; |
| 54 ServerConnectionManager* connection_manager, | 56 |
| 55 ModelSafeWorker* model_safe_worker) | 57 Syncer::Syncer(sessions::SyncSessionContext* context) |
| 56 : account_name_(account_name), | 58 : early_exit_requested_(false), |
| 57 early_exit_requested_(false), | |
| 58 max_commit_batch_size_(kDefaultMaxCommitBatchSize), | 59 max_commit_batch_size_(kDefaultMaxCommitBatchSize), |
| 59 connection_manager_(connection_manager), | 60 syncer_event_channel_(new SyncerEventChannel(SyncerEvent( |
| 60 dirman_(dirman), | 61 SyncerEvent::SHUTDOWN_USE_WITH_CARE))), |
| 61 command_channel_(NULL), | 62 resolver_scoper_(context, &resolver_), |
| 62 model_safe_worker_(model_safe_worker), | 63 event_channel_scoper_(context, syncer_event_channel_.get()), |
| 64 context_(context), |
| 63 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), | 65 updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), |
| 64 notifications_enabled_(false), | |
| 65 pre_conflict_resolution_closure_(NULL) { | 66 pre_conflict_resolution_closure_(NULL) { |
| 66 SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; | |
| 67 syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); | |
| 68 shutdown_channel_.reset(new ShutdownChannel(this)); | 67 shutdown_channel_.reset(new ShutdownChannel(this)); |
| 69 | 68 |
| 70 extensions_monitor_ = new ExtensionsActivityMonitor(); | 69 ScopedDirLookup dir(context->directory_manager(), context->account_name()); |
| 71 | |
| 72 ScopedDirLookup dir(dirman_, account_name_); | |
| 73 // The directory must be good here. | 70 // The directory must be good here. |
| 74 CHECK(dir.good()); | 71 CHECK(dir.good()); |
| 75 } | 72 } |
| 76 | 73 |
| 77 Syncer::~Syncer() { | 74 void Syncer::RequestNudge(int milliseconds) { |
| 78 if (!ChromeThread::DeleteSoon(ChromeThread::UI, FROM_HERE, | 75 SyncerEvent event(SyncerEvent::REQUEST_SYNC_NUDGE); |
| 79 extensions_monitor_)) { | 76 event.nudge_delay_milliseconds = milliseconds; |
| 80 // In unittests, there may be no UI thread, so the above will fail. | 77 syncer_event_channel_->NotifyListeners(event); |
| 81 delete extensions_monitor_; | |
| 82 } | |
| 83 extensions_monitor_ = NULL; | |
| 84 } | 78 } |
| 85 | 79 |
| 86 void Syncer::RequestNudge(int milliseconds) { | 80 bool Syncer::SyncShare(sessions::SyncSession::Delegate* delegate) { |
| 87 SyncerEvent event; | 81 sessions::SyncSession session(context_, delegate); |
| 88 event.what_happened = SyncerEvent::REQUEST_SYNC_NUDGE; | 82 return SyncShare(&session); |
| 89 event.nudge_delay_milliseconds = milliseconds; | |
| 90 channel()->NotifyListeners(event); | |
| 91 } | 83 } |
| 92 | 84 |
| 93 bool Syncer::SyncShare() { | 85 bool Syncer::SyncShare(sessions::SyncSession* session) { |
| 94 SyncProcessState state(dirman_, account_name_, connection_manager_, | 86 session->status_controller()->ResetTransientState(); |
| 95 &resolver_, syncer_event_channel_.get(), | 87 session->set_source(TestAndSetUpdatesSource()); |
| 96 model_safe_worker()); | |
| 97 return SyncShare(&state); | |
| 98 } | |
| 99 | |
| 100 bool Syncer::SyncShare(SyncProcessState* process_state) { | |
| 101 SyncCycleState cycle_state; | |
| 102 SyncerSession session(&cycle_state, process_state); | |
| 103 session.set_source(TestAndSetUpdatesSource()); | |
| 104 session.set_notifications_enabled(notifications_enabled()); | |
| 105 // This isn't perfect, as we can end up bundling extensions activity | 88 // This isn't perfect, as we can end up bundling extensions activity |
| 106 // intended for the next session into the current one. We could do a | 89 // intended for the next session into the current one. We could do a |
| 107 // test-and-reset as with the source, but note that also falls short if | 90 // test-and-reset as with the source, but note that also falls short if |
| 108 // the commit request fails (due to lost connection, for example), as we will | 91 // the commit request fails (due to lost connection, for example), as we will |
| 109 // fall all the way back to the syncer thread main loop in that case, and | 92 // fall all the way back to the syncer thread main loop in that case, and |
| 110 // wind up creating a new session when a connection is established, losing | 93 // wind up creating a new session when a connection is established, losing |
| 111 // the records set here on the original attempt. This should provide us | 94 // the records set here on the original attempt. This should provide us |
| 112 // with the right data "most of the time", and we're only using this for | 95 // with the right data "most of the time", and we're only using this for |
| 113 // analysis purposes, so Law of Large Numbers FTW. | 96 // analysis purposes, so Law of Large Numbers FTW. |
| 114 extensions_monitor_->GetAndClearRecords( | 97 context_->extensions_monitor()->GetAndClearRecords( |
| 115 session.mutable_extensions_activity()); | 98 session->mutable_extensions_activity()); |
| 116 SyncShare(&session, SYNCER_BEGIN, SYNCER_END); | 99 SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
| 117 return session.HasMoreToSync(); | 100 return session->HasMoreToSync(); |
| 118 } | 101 } |
| 119 | 102 |
| 120 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step) { | 103 bool Syncer::SyncShare(SyncerStep first_step, SyncerStep last_step, |
| 121 SyncCycleState cycle_state; | 104 sessions::SyncSession::Delegate* delegate) { |
| 122 SyncProcessState state(dirman_, account_name_, connection_manager_, | 105 sessions::SyncSession session(context_, delegate); |
| 123 &resolver_, syncer_event_channel_.get(), | |
| 124 model_safe_worker()); | |
| 125 SyncerSession session(&cycle_state, &state); | |
| 126 SyncShare(&session, first_step, last_step); | 106 SyncShare(&session, first_step, last_step); |
| 127 return session.HasMoreToSync(); | 107 return session.HasMoreToSync(); |
| 128 } | 108 } |
| 129 | 109 |
| 130 void Syncer::SyncShare(SyncerSession* session) { | 110 void Syncer::SyncShare(sessions::SyncSession* session, |
| 131 SyncShare(session, SYNCER_BEGIN, SYNCER_END); | |
| 132 } | |
| 133 | |
| 134 void Syncer::SyncShare(SyncerSession* session, | |
| 135 const SyncerStep first_step, | 111 const SyncerStep first_step, |
| 136 const SyncerStep last_step) { | 112 const SyncerStep last_step) { |
| 137 SyncerStep current_step = first_step; | 113 SyncerStep current_step = first_step; |
| 138 | 114 |
| 139 // Reset silenced_until_, it is the callers responsibility to honor throttles. | |
| 140 silenced_until_ = session->silenced_until(); | |
| 141 | |
| 142 SyncerStep next_step = current_step; | 115 SyncerStep next_step = current_step; |
| 143 while (!ExitRequested()) { | 116 while (!ExitRequested()) { |
| 144 switch (current_step) { | 117 switch (current_step) { |
| 145 case SYNCER_BEGIN: | 118 case SYNCER_BEGIN: |
| 146 LOG(INFO) << "Syncer Begin"; | 119 LOG(INFO) << "Syncer Begin"; |
| 147 next_step = DOWNLOAD_UPDATES; | 120 next_step = DOWNLOAD_UPDATES; |
| 148 break; | 121 break; |
| 149 case DOWNLOAD_UPDATES: { | 122 case DOWNLOAD_UPDATES: { |
| 150 LOG(INFO) << "Downloading Updates"; | 123 LOG(INFO) << "Downloading Updates"; |
| 151 DownloadUpdatesCommand download_updates; | 124 DownloadUpdatesCommand download_updates; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 165 verify_updates.Execute(session); | 138 verify_updates.Execute(session); |
| 166 next_step = PROCESS_UPDATES; | 139 next_step = PROCESS_UPDATES; |
| 167 break; | 140 break; |
| 168 } | 141 } |
| 169 case PROCESS_UPDATES: { | 142 case PROCESS_UPDATES: { |
| 170 LOG(INFO) << "Processing Updates"; | 143 LOG(INFO) << "Processing Updates"; |
| 171 ProcessUpdatesCommand process_updates; | 144 ProcessUpdatesCommand process_updates; |
| 172 process_updates.Execute(session); | 145 process_updates.Execute(session); |
| 173 // We should download all of the updates before attempting to process | 146 // We should download all of the updates before attempting to process |
| 174 // them. | 147 // them. |
| 175 if (session->CountUpdates() == 0) { | 148 if (session->status_controller()->CountUpdates() == 0) { |
| 176 next_step = APPLY_UPDATES; | 149 next_step = APPLY_UPDATES; |
| 177 } else { | 150 } else { |
| 178 next_step = DOWNLOAD_UPDATES; | 151 next_step = DOWNLOAD_UPDATES; |
| 179 } | 152 } |
| 180 break; | 153 break; |
| 181 } | 154 } |
| 182 case APPLY_UPDATES: { | 155 case APPLY_UPDATES: { |
| 183 LOG(INFO) << "Applying Updates"; | 156 LOG(INFO) << "Applying Updates"; |
| 184 ApplyUpdatesCommand apply_updates; | 157 ApplyUpdatesCommand apply_updates; |
| 185 apply_updates.Execute(session); | 158 apply_updates.Execute(session); |
| 186 next_step = BUILD_COMMIT_REQUEST; | 159 next_step = BUILD_COMMIT_REQUEST; |
| 187 break; | 160 break; |
| 188 } | 161 } |
| 189 // These two steps are combined since they are executed within the same | 162 // These two steps are combined since they are executed within the same |
| 190 // write transaction. | 163 // write transaction. |
| 191 case BUILD_COMMIT_REQUEST: { | 164 case BUILD_COMMIT_REQUEST: { |
| 192 SyncerStatus status(session); | 165 session->status_controller()->set_syncing(true); |
| 193 status.set_syncing(true); | |
| 194 | 166 |
| 195 LOG(INFO) << "Processing Commit Request"; | 167 LOG(INFO) << "Processing Commit Request"; |
| 196 ScopedDirLookup dir(session->dirman(), session->account_name()); | 168 ScopedDirLookup dir(context_->directory_manager(), |
| 169 context_->account_name()); |
| 197 if (!dir.good()) { | 170 if (!dir.good()) { |
| 198 LOG(ERROR) << "Scoped dir lookup failed!"; | 171 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 199 return; | 172 return; |
| 200 } | 173 } |
| 201 WriteTransaction trans(dir, SYNCER, __FILE__, __LINE__); | 174 WriteTransaction trans(dir, SYNCER, __FILE__, __LINE__); |
| 202 SyncerSession::ScopedSetWriteTransaction set_trans(session, &trans); | 175 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
| 203 | 176 |
| 204 LOG(INFO) << "Getting the Commit IDs"; | 177 LOG(INFO) << "Getting the Commit IDs"; |
| 205 GetCommitIdsCommand get_commit_ids_command(max_commit_batch_size_); | 178 GetCommitIdsCommand get_commit_ids_command(max_commit_batch_size_); |
| 206 get_commit_ids_command.Execute(session); | 179 get_commit_ids_command.Execute(session); |
| 207 | 180 |
| 208 if (!session->commit_ids().empty()) { | 181 if (!session->status_controller()->commit_ids().empty()) { |
| 209 LOG(INFO) << "Building a commit message"; | 182 LOG(INFO) << "Building a commit message"; |
| 210 BuildCommitCommand build_commit_command; | 183 BuildCommitCommand build_commit_command; |
| 211 build_commit_command.Execute(session); | 184 build_commit_command.Execute(session); |
| 212 | 185 |
| 213 next_step = POST_COMMIT_MESSAGE; | 186 next_step = POST_COMMIT_MESSAGE; |
| 214 } else { | 187 } else { |
| 215 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 188 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
| 216 } | 189 } |
| 217 | 190 |
| 218 break; | 191 break; |
| 219 } | 192 } |
| 220 case POST_COMMIT_MESSAGE: { | 193 case POST_COMMIT_MESSAGE: { |
| 221 LOG(INFO) << "Posting a commit request"; | 194 LOG(INFO) << "Posting a commit request"; |
| 222 PostCommitMessageCommand post_commit_command; | 195 PostCommitMessageCommand post_commit_command; |
| 223 post_commit_command.Execute(session); | 196 post_commit_command.Execute(session); |
| 224 next_step = PROCESS_COMMIT_RESPONSE; | 197 next_step = PROCESS_COMMIT_RESPONSE; |
| 225 break; | 198 break; |
| 226 } | 199 } |
| 227 case PROCESS_COMMIT_RESPONSE: { | 200 case PROCESS_COMMIT_RESPONSE: { |
| 228 LOG(INFO) << "Processing the commit response"; | 201 LOG(INFO) << "Processing the commit response"; |
| 229 ProcessCommitResponseCommand process_response_command( | 202 ProcessCommitResponseCommand process_response_command; |
| 230 extensions_monitor_); | |
| 231 process_response_command.Execute(session); | 203 process_response_command.Execute(session); |
| 232 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; | 204 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; |
| 233 break; | 205 break; |
| 234 } | 206 } |
| 235 case BUILD_AND_PROCESS_CONFLICT_SETS: { | 207 case BUILD_AND_PROCESS_CONFLICT_SETS: { |
| 236 LOG(INFO) << "Building and Processing Conflict Sets"; | 208 LOG(INFO) << "Building and Processing Conflict Sets"; |
| 237 BuildAndProcessConflictSetsCommand build_process_conflict_sets; | 209 BuildAndProcessConflictSetsCommand build_process_conflict_sets; |
| 238 build_process_conflict_sets.Execute(session); | 210 build_process_conflict_sets.Execute(session); |
| 239 if (session->conflict_sets_built()) | 211 if (session->status_controller()->conflict_sets_built()) |
| 240 next_step = SYNCER_END; | 212 next_step = SYNCER_END; |
| 241 else | 213 else |
| 242 next_step = RESOLVE_CONFLICTS; | 214 next_step = RESOLVE_CONFLICTS; |
| 243 break; | 215 break; |
| 244 } | 216 } |
| 245 case RESOLVE_CONFLICTS: { | 217 case RESOLVE_CONFLICTS: { |
| 246 LOG(INFO) << "Resolving Conflicts"; | 218 LOG(INFO) << "Resolving Conflicts"; |
| 247 | 219 |
| 248 // Trigger the pre_conflict_resolution_closure_, which is a testing | 220 // Trigger the pre_conflict_resolution_closure_, which is a testing |
| 249 // hook for the unit tests, if it is non-NULL. | 221 // hook for the unit tests, if it is non-NULL. |
| 250 if (pre_conflict_resolution_closure_) { | 222 if (pre_conflict_resolution_closure_) { |
| 251 pre_conflict_resolution_closure_->Run(); | 223 pre_conflict_resolution_closure_->Run(); |
| 252 } | 224 } |
| 253 | 225 |
| 254 ResolveConflictsCommand resolve_conflicts_command; | 226 ResolveConflictsCommand resolve_conflicts_command; |
| 255 resolve_conflicts_command.Execute(session); | 227 resolve_conflicts_command.Execute(session); |
| 256 if (session->HasConflictingUpdates()) | 228 StatusController* status = session->status_controller(); |
| 229 if (status->update_progress().HasConflictingUpdates()) |
| 257 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; | 230 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; |
| 258 else | 231 else |
| 259 next_step = SYNCER_END; | 232 next_step = SYNCER_END; |
| 260 break; | 233 break; |
| 261 } | 234 } |
| 262 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { | 235 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { |
| 236 StatusController* status = session->status_controller(); |
| 237 const ConflictProgress* progress = status->conflict_progress(); |
| 263 LOG(INFO) << "Applying updates to resolve conflicts"; | 238 LOG(INFO) << "Applying updates to resolve conflicts"; |
| 264 ApplyUpdatesCommand apply_updates; | 239 ApplyUpdatesCommand apply_updates; |
| 265 int num_conflicting_updates = session->conflicting_update_count(); | 240 int num_conflicting_updates = progress->ConflictingItemsSize(); |
| 266 apply_updates.Execute(session); | 241 apply_updates.Execute(session); |
| 267 int post_facto_conflicting_updates = | 242 int post_facto_conflicting_updates = progress->ConflictingItemsSize(); |
| 268 session->conflicting_update_count(); | 243 status->set_conflicts_resolved(status->conflicts_resolved() || |
| 269 session->set_conflicts_resolved(session->conflicts_resolved() || | |
| 270 num_conflicting_updates > post_facto_conflicting_updates); | 244 num_conflicting_updates > post_facto_conflicting_updates); |
| 271 if (session->conflicts_resolved()) | 245 if (status->conflicts_resolved()) |
| 272 next_step = RESOLVE_CONFLICTS; | 246 next_step = RESOLVE_CONFLICTS; |
| 273 else | 247 else |
| 274 next_step = SYNCER_END; | 248 next_step = SYNCER_END; |
| 275 break; | 249 break; |
| 276 } | 250 } |
| 277 case SYNCER_END: { | 251 case SYNCER_END: { |
| 278 LOG(INFO) << "Syncer End"; | 252 LOG(INFO) << "Syncer End"; |
| 279 SyncerEndCommand syncer_end_command; | 253 SyncerEndCommand syncer_end_command; |
| 280 // This will set "syncing" to false, and send out a notification. | 254 // This will set "syncing" to false, and send out a notification. |
| 281 syncer_end_command.Execute(session); | 255 syncer_end_command.Execute(session); |
| 282 goto post_while; | 256 goto post_while; |
| 283 } | 257 } |
| 284 default: | 258 default: |
| 285 LOG(ERROR) << "Unknown command: " << current_step; | 259 LOG(ERROR) << "Unknown command: " << current_step; |
| 286 } | 260 } |
| 287 if (last_step == current_step) | 261 if (last_step == current_step) |
| 288 break; | 262 break; |
| 289 current_step = next_step; | 263 current_step = next_step; |
| 290 } | 264 } |
| 291 post_while: | 265 post_while: |
| 292 // Copy any lingering useful state out of the session. | |
| 293 silenced_until_ = session->silenced_until(); | |
| 294 return; | 266 return; |
| 295 } | 267 } |
| 296 | 268 |
| 297 void Syncer::ProcessClientCommand(SyncerSession* session) { | 269 void Syncer::ProcessClientCommand(sessions::SyncSession* session) { |
| 298 if (!session->update_response().has_client_command()) | 270 const ClientToServerResponse& response = |
| 271 session->status_controller()->updates_response(); |
| 272 if (!response.has_client_command()) |
| 299 return; | 273 return; |
| 300 const ClientCommand command = session->update_response().client_command(); | 274 const ClientCommand& command = response.client_command(); |
| 301 if (command_channel_) | |
| 302 command_channel_->NotifyListeners(&command); | |
| 303 | 275 |
| 304 // The server limits the number of items a client can commit in one batch. | 276 // The server limits the number of items a client can commit in one batch. |
| 305 if (command.has_max_commit_batch_size()) | 277 if (command.has_max_commit_batch_size()) |
| 306 max_commit_batch_size_ = command.max_commit_batch_size(); | 278 max_commit_batch_size_ = command.max_commit_batch_size(); |
| 279 if (command.has_set_sync_long_poll_interval()) { |
| 280 session->delegate()->OnReceivedLongPollIntervalUpdate( |
| 281 TimeDelta::FromSeconds(command.set_sync_long_poll_interval())); |
| 282 } |
| 283 if (command.has_set_sync_poll_interval()) { |
| 284 session->delegate()->OnReceivedShortPollIntervalUpdate( |
| 285 TimeDelta::FromSeconds(command.set_sync_poll_interval())); |
| 286 } |
| 307 } | 287 } |
| 308 | 288 |
| 309 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { | 289 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { |
| 310 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); | 290 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); |
| 311 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); | 291 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); |
| 312 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); | 292 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); |
| 313 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); | 293 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); |
| 314 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); | 294 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); |
| 315 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); | 295 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); |
| 316 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); | 296 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 346 entry.id_string().c_str(), | 326 entry.id_string().c_str(), |
| 347 entry.parent_id_string().c_str(), | 327 entry.parent_id_string().c_str(), |
| 348 entry.version(), | 328 entry.version(), |
| 349 entry.mtime(), ServerTimeToClientTime(entry.mtime()), | 329 entry.mtime(), ServerTimeToClientTime(entry.mtime()), |
| 350 entry.ctime(), ServerTimeToClientTime(entry.ctime()), | 330 entry.ctime(), ServerTimeToClientTime(entry.ctime()), |
| 351 entry.name().c_str(), entry.sync_timestamp(), | 331 entry.name().c_str(), entry.sync_timestamp(), |
| 352 entry.deleted() ? "deleted, ":""); | 332 entry.deleted() ? "deleted, ":""); |
| 353 } | 333 } |
| 354 | 334 |
| 355 } // namespace browser_sync | 335 } // namespace browser_sync |
| OLD | NEW |