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