| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using syncable::SERVER_POSITION_IN_PARENT; | 47 using syncable::SERVER_POSITION_IN_PARENT; |
| 48 using syncable::SERVER_SPECIFICS; | 48 using syncable::SERVER_SPECIFICS; |
| 49 using syncable::SERVER_VERSION; | 49 using syncable::SERVER_VERSION; |
| 50 | 50 |
| 51 #define ENUM_CASE(x) case x: return #x | 51 #define ENUM_CASE(x) case x: return #x |
| 52 const char* SyncerStepToString(const SyncerStep step) | 52 const char* SyncerStepToString(const SyncerStep step) |
| 53 { | 53 { |
| 54 switch (step) { | 54 switch (step) { |
| 55 ENUM_CASE(SYNCER_BEGIN); | 55 ENUM_CASE(SYNCER_BEGIN); |
| 56 ENUM_CASE(DOWNLOAD_UPDATES); | 56 ENUM_CASE(DOWNLOAD_UPDATES); |
| 57 ENUM_CASE(PROCESS_CLIENT_COMMAND); | |
| 58 ENUM_CASE(VERIFY_UPDATES); | 57 ENUM_CASE(VERIFY_UPDATES); |
| 59 ENUM_CASE(PROCESS_UPDATES); | 58 ENUM_CASE(PROCESS_UPDATES); |
| 60 ENUM_CASE(STORE_TIMESTAMPS); | 59 ENUM_CASE(STORE_TIMESTAMPS); |
| 61 ENUM_CASE(APPLY_UPDATES); | 60 ENUM_CASE(APPLY_UPDATES); |
| 62 ENUM_CASE(COMMIT); | 61 ENUM_CASE(COMMIT); |
| 63 ENUM_CASE(RESOLVE_CONFLICTS); | 62 ENUM_CASE(RESOLVE_CONFLICTS); |
| 64 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); | 63 ENUM_CASE(APPLY_UPDATES_TO_RESOLVE_CONFLICTS); |
| 65 ENUM_CASE(SYNCER_END); | 64 ENUM_CASE(SYNCER_END); |
| 66 } | 65 } |
| 67 NOTREACHED(); | 66 NOTREACHED(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // TODO(akalin): We may want to propagate this switch up | 110 // TODO(akalin): We may want to propagate this switch up |
| 112 // eventually. | 111 // eventually. |
| 113 #if defined(OS_ANDROID) | 112 #if defined(OS_ANDROID) |
| 114 const bool kCreateMobileBookmarksFolder = true; | 113 const bool kCreateMobileBookmarksFolder = true; |
| 115 #else | 114 #else |
| 116 const bool kCreateMobileBookmarksFolder = false; | 115 const bool kCreateMobileBookmarksFolder = false; |
| 117 #endif | 116 #endif |
| 118 DownloadUpdatesCommand download_updates(kCreateMobileBookmarksFolder); | 117 DownloadUpdatesCommand download_updates(kCreateMobileBookmarksFolder); |
| 119 session->mutable_status_controller()->set_last_download_updates_result( | 118 session->mutable_status_controller()->set_last_download_updates_result( |
| 120 download_updates.Execute(session)); | 119 download_updates.Execute(session)); |
| 121 next_step = PROCESS_CLIENT_COMMAND; | |
| 122 break; | |
| 123 } | |
| 124 case PROCESS_CLIENT_COMMAND: { | |
| 125 ProcessClientCommand(session); | |
| 126 next_step = VERIFY_UPDATES; | 120 next_step = VERIFY_UPDATES; |
| 127 break; | 121 break; |
| 128 } | 122 } |
| 129 case VERIFY_UPDATES: { | 123 case VERIFY_UPDATES: { |
| 130 VerifyUpdatesCommand verify_updates; | 124 VerifyUpdatesCommand verify_updates; |
| 131 verify_updates.Execute(session); | 125 verify_updates.Execute(session); |
| 132 next_step = PROCESS_UPDATES; | 126 next_step = PROCESS_UPDATES; |
| 133 break; | 127 break; |
| 134 } | 128 } |
| 135 case PROCESS_UPDATES: { | 129 case PROCESS_UPDATES: { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 << "next step: " << SyncerStepToString(next_step) << ", " | 225 << "next step: " << SyncerStepToString(next_step) << ", " |
| 232 << "snapshot: " << session->TakeSnapshot().ToString(); | 226 << "snapshot: " << session->TakeSnapshot().ToString(); |
| 233 if (last_step == current_step) { | 227 if (last_step == current_step) { |
| 234 session->SetFinished(); | 228 session->SetFinished(); |
| 235 break; | 229 break; |
| 236 } | 230 } |
| 237 current_step = next_step; | 231 current_step = next_step; |
| 238 } | 232 } |
| 239 } | 233 } |
| 240 | 234 |
| 241 void Syncer::ProcessClientCommand(sessions::SyncSession* session) { | |
| 242 const sync_pb::ClientToServerResponse& response = | |
| 243 session->status_controller().updates_response(); | |
| 244 if (!response.has_client_command()) | |
| 245 return; | |
| 246 const ClientCommand& command = response.client_command(); | |
| 247 | |
| 248 // The server limits the number of items a client can commit in one batch. | |
| 249 if (command.has_max_commit_batch_size()) { | |
| 250 session->context()->set_max_commit_batch_size( | |
| 251 command.max_commit_batch_size()); | |
| 252 } | |
| 253 if (command.has_set_sync_long_poll_interval()) { | |
| 254 session->delegate()->OnReceivedLongPollIntervalUpdate( | |
| 255 TimeDelta::FromSeconds(command.set_sync_long_poll_interval())); | |
| 256 } | |
| 257 if (command.has_set_sync_poll_interval()) { | |
| 258 session->delegate()->OnReceivedShortPollIntervalUpdate( | |
| 259 TimeDelta::FromSeconds(command.set_sync_poll_interval())); | |
| 260 } | |
| 261 | |
| 262 if (command.has_sessions_commit_delay_seconds()) { | |
| 263 session->delegate()->OnReceivedSessionsCommitDelay( | |
| 264 TimeDelta::FromSeconds(command.sessions_commit_delay_seconds())); | |
| 265 } | |
| 266 } | |
| 267 | |
| 268 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { | 235 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest) { |
| 269 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); | 236 dest->Put(SERVER_NON_UNIQUE_NAME, src->Get(SERVER_NON_UNIQUE_NAME)); |
| 270 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); | 237 dest->Put(SERVER_PARENT_ID, src->Get(SERVER_PARENT_ID)); |
| 271 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); | 238 dest->Put(SERVER_MTIME, src->Get(SERVER_MTIME)); |
| 272 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); | 239 dest->Put(SERVER_CTIME, src->Get(SERVER_CTIME)); |
| 273 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); | 240 dest->Put(SERVER_VERSION, src->Get(SERVER_VERSION)); |
| 274 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); | 241 dest->Put(SERVER_IS_DIR, src->Get(SERVER_IS_DIR)); |
| 275 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); | 242 dest->Put(SERVER_IS_DEL, src->Get(SERVER_IS_DEL)); |
| 276 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); | 243 dest->Put(IS_UNAPPLIED_UPDATE, src->Get(IS_UNAPPLIED_UPDATE)); |
| 277 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); | 244 dest->Put(SERVER_SPECIFICS, src->Get(SERVER_SPECIFICS)); |
| 278 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); | 245 dest->Put(SERVER_POSITION_IN_PARENT, src->Get(SERVER_POSITION_IN_PARENT)); |
| 279 } | 246 } |
| 280 | 247 |
| 281 void ClearServerData(syncable::MutableEntry* entry) { | 248 void ClearServerData(syncable::MutableEntry* entry) { |
| 282 entry->Put(SERVER_NON_UNIQUE_NAME, ""); | 249 entry->Put(SERVER_NON_UNIQUE_NAME, ""); |
| 283 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); | 250 entry->Put(SERVER_PARENT_ID, syncable::GetNullId()); |
| 284 entry->Put(SERVER_MTIME, Time()); | 251 entry->Put(SERVER_MTIME, Time()); |
| 285 entry->Put(SERVER_CTIME, Time()); | 252 entry->Put(SERVER_CTIME, Time()); |
| 286 entry->Put(SERVER_VERSION, 0); | 253 entry->Put(SERVER_VERSION, 0); |
| 287 entry->Put(SERVER_IS_DIR, false); | 254 entry->Put(SERVER_IS_DIR, false); |
| 288 entry->Put(SERVER_IS_DEL, false); | 255 entry->Put(SERVER_IS_DEL, false); |
| 289 entry->Put(IS_UNAPPLIED_UPDATE, false); | 256 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 290 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); | 257 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); |
| 291 entry->Put(SERVER_POSITION_IN_PARENT, 0); | 258 entry->Put(SERVER_POSITION_IN_PARENT, 0); |
| 292 } | 259 } |
| 293 | 260 |
| 294 } // namespace syncer | 261 } // namespace syncer |
| OLD | NEW |