| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); | 66 VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types); |
| 67 if (nudge_tracker.IsGetUpdatesRequired() || | 67 if (nudge_tracker.IsGetUpdatesRequired() || |
| 68 session->context()->ShouldFetchUpdatesBeforeCommit()) { | 68 session->context()->ShouldFetchUpdatesBeforeCommit()) { |
| 69 if (!DownloadAndApplyUpdates( | 69 if (!DownloadAndApplyUpdates( |
| 70 session, | 70 session, |
| 71 base::Bind(&NormalDownloadUpdates, | 71 base::Bind(&NormalDownloadUpdates, |
| 72 session, | 72 session, |
| 73 kCreateMobileBookmarksFolder, | 73 kCreateMobileBookmarksFolder, |
| 74 request_types, | 74 request_types, |
| 75 base::ConstRef(nudge_tracker)))) { | 75 base::ConstRef(nudge_tracker)))) { |
| 76 return HandleCycleEnd(session); | 76 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); | 80 VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types); |
| 81 SyncerError commit_result = BuildAndPostCommits(request_types, this, session); | 81 SyncerError commit_result = BuildAndPostCommits(request_types, this, session); |
| 82 session->mutable_status_controller()->set_commit_result(commit_result); | 82 session->mutable_status_controller()->set_commit_result(commit_result); |
| 83 | 83 |
| 84 return HandleCycleEnd(session); | 84 return HandleCycleEnd(session, nudge_tracker.updates_source()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool Syncer::ConfigureSyncShare(ModelTypeSet request_types, | 87 bool Syncer::ConfigureSyncShare( |
| 88 SyncSession* session) { | 88 ModelTypeSet request_types, |
| 89 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 90 SyncSession* session) { |
| 89 HandleCycleBegin(session); | 91 HandleCycleBegin(session); |
| 90 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); | 92 VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types); |
| 91 DownloadAndApplyUpdates( | 93 DownloadAndApplyUpdates( |
| 92 session, | 94 session, |
| 93 base::Bind(&DownloadUpdatesForConfigure, | 95 base::Bind(&DownloadUpdatesForConfigure, |
| 94 session, | 96 session, |
| 95 kCreateMobileBookmarksFolder, | 97 kCreateMobileBookmarksFolder, |
| 96 session->source(), | 98 source, |
| 97 request_types)); | 99 request_types)); |
| 98 return HandleCycleEnd(session); | 100 return HandleCycleEnd(session, source); |
| 99 } | 101 } |
| 100 | 102 |
| 101 bool Syncer::PollSyncShare(ModelTypeSet request_types, | 103 bool Syncer::PollSyncShare(ModelTypeSet request_types, |
| 102 SyncSession* session) { | 104 SyncSession* session) { |
| 103 HandleCycleBegin(session); | 105 HandleCycleBegin(session); |
| 104 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); | 106 VLOG(1) << "Polling types " << ModelTypeSetToString(request_types); |
| 105 DownloadAndApplyUpdates( | 107 DownloadAndApplyUpdates( |
| 106 session, | 108 session, |
| 107 base::Bind(&DownloadUpdatesForPoll, | 109 base::Bind(&DownloadUpdatesForPoll, |
| 108 session, | 110 session, |
| 109 kCreateMobileBookmarksFolder, | 111 kCreateMobileBookmarksFolder, |
| 110 request_types)); | 112 request_types)); |
| 111 return HandleCycleEnd(session); | 113 return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void Syncer::ApplyUpdates(SyncSession* session) { | 116 void Syncer::ApplyUpdates(SyncSession* session) { |
| 115 TRACE_EVENT0("sync", "ApplyUpdates"); | 117 TRACE_EVENT0("sync", "ApplyUpdates"); |
| 116 | 118 |
| 117 ApplyControlDataUpdates(session); | 119 ApplyControlDataUpdates(session); |
| 118 | 120 |
| 119 ApplyUpdatesAndResolveConflictsCommand apply_updates; | 121 ApplyUpdatesAndResolveConflictsCommand apply_updates; |
| 120 apply_updates.Execute(session); | 122 apply_updates.Execute(session); |
| 121 | 123 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 142 if (ExitRequested()) | 144 if (ExitRequested()) |
| 143 return false; | 145 return false; |
| 144 return true; | 146 return true; |
| 145 } | 147 } |
| 146 | 148 |
| 147 void Syncer::HandleCycleBegin(SyncSession* session) { | 149 void Syncer::HandleCycleBegin(SyncSession* session) { |
| 148 session->mutable_status_controller()->UpdateStartTime(); | 150 session->mutable_status_controller()->UpdateStartTime(); |
| 149 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); | 151 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); |
| 150 } | 152 } |
| 151 | 153 |
| 152 bool Syncer::HandleCycleEnd(SyncSession* session) { | 154 bool Syncer::HandleCycleEnd( |
| 155 SyncSession* session, |
| 156 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 153 if (!ExitRequested()) { | 157 if (!ExitRequested()) { |
| 154 session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_ENDED); | 158 session->SendSyncCycleEndEventNotification(source); |
| 155 return true; | 159 return true; |
| 156 } else { | 160 } else { |
| 157 return false; | 161 return false; |
| 158 } | 162 } |
| 159 } | 163 } |
| 160 | 164 |
| 161 } // namespace syncer | 165 } // namespace syncer |
| OLD | NEW |