| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool Syncer::NormalSyncShare(ModelTypeSet request_types, | 56 bool Syncer::NormalSyncShare(ModelTypeSet request_types, |
| 57 const NudgeTracker& nudge_tracker, | 57 const NudgeTracker& nudge_tracker, |
| 58 SyncSession* session) { | 58 SyncSession* session) { |
| 59 HandleCycleBegin(session); | 59 HandleCycleBegin(session); |
| 60 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); | 60 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); |
| 61 if (nudge_tracker.IsGetUpdatesRequired() || | 61 if (nudge_tracker.IsGetUpdatesRequired() || |
| 62 session->context()->ShouldFetchUpdatesBeforeCommit()) { | 62 session->context()->ShouldFetchUpdatesBeforeCommit()) { |
| 63 if (!DownloadAndApplyUpdates( | 63 if (!DownloadAndApplyUpdates( |
| 64 request_types, |
| 64 session, | 65 session, |
| 65 base::Bind(&BuildNormalDownloadUpdates, | 66 base::Bind(&BuildNormalDownloadUpdates, |
| 66 session, | 67 session, |
| 67 kCreateMobileBookmarksFolder, | 68 kCreateMobileBookmarksFolder, |
| 68 request_types, | 69 request_types, |
| 69 base::ConstRef(nudge_tracker)))) { | 70 base::ConstRef(nudge_tracker)))) { |
| 70 return HandleCycleEnd(session, nudge_tracker.updates_source()); | 71 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); | 75 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); |
| 75 SyncerError commit_result = BuildAndPostCommits(request_types, session); | 76 SyncerError commit_result = BuildAndPostCommits(request_types, session); |
| 76 session->mutable_status_controller()->set_commit_result(commit_result); | 77 session->mutable_status_controller()->set_commit_result(commit_result); |
| 77 | 78 |
| 78 return HandleCycleEnd(session, nudge_tracker.updates_source()); | 79 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 79 } | 80 } |
| 80 | 81 |
| 81 bool Syncer::ConfigureSyncShare( | 82 bool Syncer::ConfigureSyncShare( |
| 82 ModelTypeSet request_types, | 83 ModelTypeSet request_types, |
| 83 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 84 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 84 SyncSession* session) { | 85 SyncSession* session) { |
| 85 HandleCycleBegin(session); | 86 HandleCycleBegin(session); |
| 86 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); | 87 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); |
| 87 DownloadAndApplyUpdates( | 88 DownloadAndApplyUpdates( |
| 89 request_types, |
| 88 session, | 90 session, |
| 89 base::Bind(&BuildDownloadUpdatesForConfigure, | 91 base::Bind(&BuildDownloadUpdatesForConfigure, |
| 90 session, | 92 session, |
| 91 kCreateMobileBookmarksFolder, | 93 kCreateMobileBookmarksFolder, |
| 92 source, | 94 source, |
| 93 request_types)); | 95 request_types)); |
| 94 return HandleCycleEnd(session, source); | 96 return HandleCycleEnd(session, source); |
| 95 } | 97 } |
| 96 | 98 |
| 97 bool Syncer::PollSyncShare(ModelTypeSet request_types, | 99 bool Syncer::PollSyncShare(ModelTypeSet request_types, |
| 98 SyncSession* session) { | 100 SyncSession* session) { |
| 99 HandleCycleBegin(session); | 101 HandleCycleBegin(session); |
| 100 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); | 102 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); |
| 101 DownloadAndApplyUpdates( | 103 DownloadAndApplyUpdates( |
| 104 request_types, |
| 102 session, | 105 session, |
| 103 base::Bind(&BuildDownloadUpdatesForPoll, | 106 base::Bind(&BuildDownloadUpdatesForPoll, |
| 104 session, | 107 session, |
| 105 kCreateMobileBookmarksFolder, | 108 kCreateMobileBookmarksFolder, |
| 106 request_types)); | 109 request_types)); |
| 107 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC); | 110 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void Syncer::ApplyUpdates(SyncSession* session) { | 113 void Syncer::ApplyUpdates(SyncSession* session) { |
| 111 TRACE_EVENT0("sync", "ApplyUpdates"); | 114 TRACE_EVENT0("sync", "ApplyUpdates"); |
| 112 | 115 |
| 113 ApplyControlDataUpdates(session); | 116 ApplyControlDataUpdates(session); |
| 114 | 117 |
| 115 ApplyUpdatesAndResolveConflictsCommand apply_updates; | 118 ApplyUpdatesAndResolveConflictsCommand apply_updates; |
| 116 apply_updates.Execute(session); | 119 apply_updates.Execute(session); |
| 117 | 120 |
| 118 session->context()->set_hierarchy_conflict_detected( | 121 session->context()->set_hierarchy_conflict_detected( |
| 119 session->status_controller().num_hierarchy_conflicts() > 0); | 122 session->status_controller().num_hierarchy_conflicts() > 0); |
| 120 | 123 |
| 121 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED); | 124 session->SendEventNotification(SyncEngineEvent::STATUS_CHANGED); |
| 122 } | 125 } |
| 123 | 126 |
| 124 bool Syncer::DownloadAndApplyUpdates( | 127 bool Syncer::DownloadAndApplyUpdates( |
| 128 ModelTypeSet request_types, |
| 125 SyncSession* session, | 129 SyncSession* session, |
| 126 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn) { | 130 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn) { |
| 127 while (!session->status_controller().ServerSaysNothingMoreToDownload()) { | 131 while (!session->status_controller().ServerSaysNothingMoreToDownload()) { |
| 128 TRACE_EVENT0("sync", "DownloadUpdates"); | 132 TRACE_EVENT0("sync", "DownloadUpdates"); |
| 129 sync_pb::ClientToServerMessage msg; | 133 sync_pb::ClientToServerMessage msg; |
| 130 build_fn.Run(&msg); | 134 build_fn.Run(&msg); |
| 131 SyncerError download_result = ExecuteDownloadUpdates(session, &msg); | 135 SyncerError download_result = |
| 136 ExecuteDownloadUpdates(request_types, session, &msg); |
| 132 session->mutable_status_controller()->set_last_download_updates_result( | 137 session->mutable_status_controller()->set_last_download_updates_result( |
| 133 download_result); | 138 download_result); |
| 134 if (download_result != SYNCER_OK) { | 139 if (download_result != SYNCER_OK) { |
| 135 return false; | 140 return false; |
| 136 } | 141 } |
| 137 } | 142 } |
| 138 if (ExitRequested()) | 143 if (ExitRequested()) |
| 139 return false; | 144 return false; |
| 140 ApplyUpdates(session); | 145 ApplyUpdates(session); |
| 141 if (ExitRequested()) | 146 if (ExitRequested()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 189 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 185 if (!ExitRequested()) { | 190 if (!ExitRequested()) { |
| 186 session->SendSyncCycleEndEventNotification(source); | 191 session->SendSyncCycleEndEventNotification(source); |
| 187 return true; | 192 return true; |
| 188 } else { | 193 } else { |
| 189 return false; | 194 return false; |
| 190 } | 195 } |
| 191 } | 196 } |
| 192 | 197 |
| 193 } // namespace syncer | 198 } // namespace syncer |
| OLD | NEW |