| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "sync/engine/apply_control_data_updates.h" | 13 #include "sync/engine/apply_control_data_updates.h" |
| 14 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" | 14 #include "sync/engine/apply_updates_and_resolve_conflicts_command.h" |
| 15 #include "sync/engine/build_commit_command.h" | 15 #include "sync/engine/build_commit_command.h" |
| 16 #include "sync/engine/commit.h" | 16 #include "sync/engine/commit.h" |
| 17 #include "sync/engine/conflict_resolver.h" | 17 #include "sync/engine/conflict_resolver.h" |
| 18 #include "sync/engine/download.h" | 18 #include "sync/engine/download.h" |
| 19 #include "sync/engine/net/server_connection_manager.h" | 19 #include "sync/engine/net/server_connection_manager.h" |
| 20 #include "sync/engine/process_commit_response_command.h" | 20 #include "sync/engine/process_commit_response_command.h" |
| 21 #include "sync/engine/syncer_types.h" | 21 #include "sync/engine/syncer_types.h" |
| 22 #include "sync/internal_api/public/base/cancelation_signal.h" | 22 #include "sync/internal_api/public/base/cancelation_signal.h" |
| 23 #include "sync/internal_api/public/base/unique_position.h" | 23 #include "sync/internal_api/public/base/unique_position.h" |
| 24 #include "sync/internal_api/public/util/syncer_error.h" | 24 #include "sync/internal_api/public/util/syncer_error.h" |
| 25 #include "sync/sessions/nudge_tracker.h" | 25 #include "sync/sessions/nudge_tracker.h" |
| 26 #include "sync/syncable/directory.h" |
| 26 #include "sync/syncable/mutable_entry.h" | 27 #include "sync/syncable/mutable_entry.h" |
| 27 #include "sync/syncable/syncable-inl.h" | 28 #include "sync/syncable/syncable-inl.h" |
| 28 | 29 |
| 29 using base::Time; | 30 using base::Time; |
| 30 using base::TimeDelta; | 31 using base::TimeDelta; |
| 31 using sync_pb::ClientCommand; | 32 using sync_pb::ClientCommand; |
| 32 | 33 |
| 33 namespace syncer { | 34 namespace syncer { |
| 34 | 35 |
| 35 // TODO(akalin): We may want to propagate this switch up | 36 // TODO(akalin): We may want to propagate this switch up |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 base::Bind(&BuildNormalDownloadUpdates, | 67 base::Bind(&BuildNormalDownloadUpdates, |
| 67 session, | 68 session, |
| 68 kCreateMobileBookmarksFolder, | 69 kCreateMobileBookmarksFolder, |
| 69 request_types, | 70 request_types, |
| 70 base::ConstRef(nudge_tracker)))) { | 71 base::ConstRef(nudge_tracker)))) { |
| 71 return HandleCycleEnd(session, nudge_tracker.updates_source()); | 72 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 | 75 |
| 75 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); | 76 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); |
| 76 SyncerError commit_result = BuildAndPostCommits(request_types, this, session); | 77 SyncerError commit_result = BuildAndPostCommits(request_types, session); |
| 77 session->mutable_status_controller()->set_commit_result(commit_result); | 78 session->mutable_status_controller()->set_commit_result(commit_result); |
| 78 | 79 |
| 79 return HandleCycleEnd(session, nudge_tracker.updates_source()); | 80 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool Syncer::ConfigureSyncShare( | 83 bool Syncer::ConfigureSyncShare( |
| 83 ModelTypeSet request_types, | 84 ModelTypeSet request_types, |
| 84 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 85 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 85 SyncSession* session) { | 86 SyncSession* session) { |
| 86 HandleCycleBegin(session); | 87 HandleCycleBegin(session); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 if (ExitRequested()) | 140 if (ExitRequested()) |
| 140 return false; | 141 return false; |
| 141 ApplyUpdates(session); | 142 ApplyUpdates(session); |
| 142 if (ExitRequested()) | 143 if (ExitRequested()) |
| 143 return false; | 144 return false; |
| 144 return true; | 145 return true; |
| 145 } | 146 } |
| 146 | 147 |
| 148 SyncerError Syncer::BuildAndPostCommits(ModelTypeSet requested_types, |
| 149 sessions::SyncSession* session) { |
| 150 // The ExitRequested() check is unnecessary, since we should start getting |
| 151 // errors from the ServerConnectionManager if an exist has been requested. |
| 152 // However, it doesn't hurt to check it anyway. |
| 153 while (!ExitRequested()) { |
| 154 scoped_ptr<Commit> commit( |
| 155 Commit::Init( |
| 156 requested_types, |
| 157 session->context()->max_commit_batch_size(), |
| 158 session->context()->account_name(), |
| 159 session->context()->directory()->cache_guid(), |
| 160 session->context()->commit_contributor_map(), |
| 161 session->context()->extensions_activity())); |
| 162 if (!commit) { |
| 163 break; |
| 164 } |
| 165 |
| 166 SyncerError error = commit->PostAndProcessResponse( |
| 167 session, |
| 168 session->mutable_status_controller(), |
| 169 session->context()->extensions_activity()); |
| 170 if (error != SYNCER_OK) { |
| 171 return error; |
| 172 } |
| 173 } |
| 174 |
| 175 return SYNCER_OK; |
| 176 } |
| 177 |
| 147 void Syncer::HandleCycleBegin(SyncSession* session) { | 178 void Syncer::HandleCycleBegin(SyncSession* session) { |
| 148 session->mutable_status_controller()->UpdateStartTime(); | 179 session->mutable_status_controller()->UpdateStartTime(); |
| 149 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); | 180 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); |
| 150 } | 181 } |
| 151 | 182 |
| 152 bool Syncer::HandleCycleEnd( | 183 bool Syncer::HandleCycleEnd( |
| 153 SyncSession* session, | 184 SyncSession* session, |
| 154 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 185 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 155 if (!ExitRequested()) { | 186 if (!ExitRequested()) { |
| 156 session->SendSyncCycleEndEventNotification(source); | 187 session->SendSyncCycleEndEventNotification(source); |
| 157 return true; | 188 return true; |
| 158 } else { | 189 } else { |
| 159 return false; | 190 return false; |
| 160 } | 191 } |
| 161 } | 192 } |
| 162 | 193 |
| 163 } // namespace syncer | 194 } // namespace syncer |
| OLD | NEW |