Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/sync/engine/syncer.cc

Issue 8638001: [Sync] Made some sync session member functions const (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix latent bug in StatusController Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer.h" 5 #include "chrome/browser/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ENUM_CASE(CLEAR_PRIVATE_DATA); 77 ENUM_CASE(CLEAR_PRIVATE_DATA);
78 ENUM_CASE(SYNCER_END); 78 ENUM_CASE(SYNCER_END);
79 } 79 }
80 NOTREACHED(); 80 NOTREACHED();
81 return ""; 81 return "";
82 } 82 }
83 #undef ENUM_CASE 83 #undef ENUM_CASE
84 84
85 Syncer::ScopedSyncStartStopTracker::ScopedSyncStartStopTracker( 85 Syncer::ScopedSyncStartStopTracker::ScopedSyncStartStopTracker(
86 sessions::SyncSession* session) : session_(session) { 86 sessions::SyncSession* session) : session_(session) {
87 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(true); 87 session_->mutable_status_controller()->
88 SetSyncInProgressAndUpdateStartTime(true);
88 } 89 }
89 90
90 Syncer::ScopedSyncStartStopTracker::~ScopedSyncStartStopTracker() { 91 Syncer::ScopedSyncStartStopTracker::~ScopedSyncStartStopTracker() {
91 session_->status_controller()->SetSyncInProgressAndUpdateStartTime(false); 92 session_->mutable_status_controller()->
93 SetSyncInProgressAndUpdateStartTime(false);
92 } 94 }
93 95
94 Syncer::Syncer() 96 Syncer::Syncer()
95 : early_exit_requested_(false), 97 : early_exit_requested_(false),
96 pre_conflict_resolution_closure_(NULL) { 98 pre_conflict_resolution_closure_(NULL) {
97 } 99 }
98 100
99 Syncer::~Syncer() {} 101 Syncer::~Syncer() {}
100 102
101 bool Syncer::ExitRequested() { 103 bool Syncer::ExitRequested() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ProcessUpdatesCommand process_updates; 174 ProcessUpdatesCommand process_updates;
173 process_updates.Execute(session); 175 process_updates.Execute(session);
174 next_step = STORE_TIMESTAMPS; 176 next_step = STORE_TIMESTAMPS;
175 break; 177 break;
176 } 178 }
177 case STORE_TIMESTAMPS: { 179 case STORE_TIMESTAMPS: {
178 StoreTimestampsCommand store_timestamps; 180 StoreTimestampsCommand store_timestamps;
179 store_timestamps.Execute(session); 181 store_timestamps.Execute(session);
180 // We should download all of the updates before attempting to process 182 // We should download all of the updates before attempting to process
181 // them. 183 // them.
182 if (session->status_controller()->ServerSaysNothingMoreToDownload() || 184 if (session->status_controller().ServerSaysNothingMoreToDownload() ||
183 !session->status_controller()->download_updates_succeeded()) { 185 !session->status_controller().download_updates_succeeded()) {
184 next_step = APPLY_UPDATES; 186 next_step = APPLY_UPDATES;
185 } else { 187 } else {
186 next_step = DOWNLOAD_UPDATES; 188 next_step = DOWNLOAD_UPDATES;
187 } 189 }
188 break; 190 break;
189 } 191 }
190 case APPLY_UPDATES: { 192 case APPLY_UPDATES: {
191 ApplyUpdatesCommand apply_updates; 193 ApplyUpdatesCommand apply_updates;
192 apply_updates.Execute(session); 194 apply_updates.Execute(session);
193 if (last_step == APPLY_UPDATES) { 195 if (last_step == APPLY_UPDATES) {
(...skipping 16 matching lines...) Expand all
210 return; 212 return;
211 } 213 }
212 WriteTransaction trans(FROM_HERE, SYNCER, dir); 214 WriteTransaction trans(FROM_HERE, SYNCER, dir);
213 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); 215 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
214 216
215 VLOG(1) << "Getting the Commit IDs"; 217 VLOG(1) << "Getting the Commit IDs";
216 GetCommitIdsCommand get_commit_ids_command( 218 GetCommitIdsCommand get_commit_ids_command(
217 session->context()->max_commit_batch_size()); 219 session->context()->max_commit_batch_size());
218 get_commit_ids_command.Execute(session); 220 get_commit_ids_command.Execute(session);
219 221
220 if (!session->status_controller()->commit_ids().empty()) { 222 if (!session->status_controller().commit_ids().empty()) {
221 VLOG(1) << "Building a commit message"; 223 VLOG(1) << "Building a commit message";
222 BuildCommitCommand build_commit_command; 224 BuildCommitCommand build_commit_command;
223 build_commit_command.Execute(session); 225 build_commit_command.Execute(session);
224 226
225 next_step = POST_COMMIT_MESSAGE; 227 next_step = POST_COMMIT_MESSAGE;
226 } else { 228 } else {
227 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; 229 next_step = BUILD_AND_PROCESS_CONFLICT_SETS;
228 } 230 }
229 231
230 break; 232 break;
231 } 233 }
232 case POST_COMMIT_MESSAGE: { 234 case POST_COMMIT_MESSAGE: {
233 PostCommitMessageCommand post_commit_command; 235 PostCommitMessageCommand post_commit_command;
234 post_commit_command.Execute(session); 236 post_commit_command.Execute(session);
235 next_step = PROCESS_COMMIT_RESPONSE; 237 next_step = PROCESS_COMMIT_RESPONSE;
236 break; 238 break;
237 } 239 }
238 case PROCESS_COMMIT_RESPONSE: { 240 case PROCESS_COMMIT_RESPONSE: {
239 session->status_controller()->reset_num_conflicting_commits(); 241 session->mutable_status_controller()->reset_num_conflicting_commits();
240 ProcessCommitResponseCommand process_response_command; 242 ProcessCommitResponseCommand process_response_command;
241 process_response_command.Execute(session); 243 process_response_command.Execute(session);
242 next_step = BUILD_AND_PROCESS_CONFLICT_SETS; 244 next_step = BUILD_AND_PROCESS_CONFLICT_SETS;
243 break; 245 break;
244 } 246 }
245 case BUILD_AND_PROCESS_CONFLICT_SETS: { 247 case BUILD_AND_PROCESS_CONFLICT_SETS: {
246 BuildAndProcessConflictSetsCommand build_process_conflict_sets; 248 BuildAndProcessConflictSetsCommand build_process_conflict_sets;
247 build_process_conflict_sets.Execute(session); 249 build_process_conflict_sets.Execute(session);
248 if (session->status_controller()->conflict_sets_built()) 250 if (session->status_controller().conflict_sets_built())
249 next_step = SYNCER_END; 251 next_step = SYNCER_END;
250 else 252 else
251 next_step = RESOLVE_CONFLICTS; 253 next_step = RESOLVE_CONFLICTS;
252 break; 254 break;
253 } 255 }
254 case RESOLVE_CONFLICTS: { 256 case RESOLVE_CONFLICTS: {
255 257
256 // Trigger the pre_conflict_resolution_closure_, which is a testing 258 // Trigger the pre_conflict_resolution_closure_, which is a testing
257 // hook for the unit tests, if it is non-NULL. 259 // hook for the unit tests, if it is non-NULL.
258 if (pre_conflict_resolution_closure_) { 260 if (pre_conflict_resolution_closure_) {
259 pre_conflict_resolution_closure_->Run(); 261 pre_conflict_resolution_closure_->Run();
260 } 262 }
261 263
262 StatusController* status = session->status_controller(); 264 StatusController* status = session->mutable_status_controller();
263 status->reset_conflicts_resolved(); 265 status->reset_conflicts_resolved();
264 ResolveConflictsCommand resolve_conflicts_command; 266 ResolveConflictsCommand resolve_conflicts_command;
265 resolve_conflicts_command.Execute(session); 267 resolve_conflicts_command.Execute(session);
266 268
267 // Has ConflictingUpdates includes both blocking and non-blocking 269 // Has ConflictingUpdates includes both blocking and non-blocking
268 // conflicts. If we have either, we want to attempt to reapply. 270 // conflicts. If we have either, we want to attempt to reapply.
269 if (status->HasConflictingUpdates()) 271 if (status->HasConflictingUpdates())
270 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS; 272 next_step = APPLY_UPDATES_TO_RESOLVE_CONFLICTS;
271 else 273 else
272 next_step = SYNCER_END; 274 next_step = SYNCER_END;
273 break; 275 break;
274 } 276 }
275 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: { 277 case APPLY_UPDATES_TO_RESOLVE_CONFLICTS: {
276 StatusController* status = session->status_controller(); 278 StatusController* status = session->mutable_status_controller();
277 VLOG(1) << "Applying updates to resolve conflicts"; 279 VLOG(1) << "Applying updates to resolve conflicts";
278 ApplyUpdatesCommand apply_updates; 280 ApplyUpdatesCommand apply_updates;
279 281
280 // We only care to resolve conflicts again if we made progress on the 282 // We only care to resolve conflicts again if we made progress on the
281 // blocking conflicts. Whether or not we made progress on the 283 // blocking conflicts. Whether or not we made progress on the
282 // non-blocking doesn't matter. 284 // non-blocking doesn't matter.
283 int before_blocking_conflicting_updates = 285 int before_blocking_conflicting_updates =
284 status->TotalNumBlockingConflictingItems(); 286 status->TotalNumBlockingConflictingItems();
285 apply_updates.Execute(session); 287 apply_updates.Execute(session);
286 int after_blocking_conflicting_updates = 288 int after_blocking_conflicting_updates =
(...skipping 26 matching lines...) Expand all
313 << "next step: " << SyncerStepToString(next_step) << ", " 315 << "next step: " << SyncerStepToString(next_step) << ", "
314 << "snapshot: " << session->TakeSnapshot().ToString(); 316 << "snapshot: " << session->TakeSnapshot().ToString();
315 if (last_step == current_step) 317 if (last_step == current_step)
316 break; 318 break;
317 current_step = next_step; 319 current_step = next_step;
318 } 320 }
319 } 321 }
320 322
321 void Syncer::ProcessClientCommand(sessions::SyncSession* session) { 323 void Syncer::ProcessClientCommand(sessions::SyncSession* session) {
322 const ClientToServerResponse& response = 324 const ClientToServerResponse& response =
323 session->status_controller()->updates_response(); 325 session->status_controller().updates_response();
324 if (!response.has_client_command()) 326 if (!response.has_client_command())
325 return; 327 return;
326 const ClientCommand& command = response.client_command(); 328 const ClientCommand& command = response.client_command();
327 329
328 // The server limits the number of items a client can commit in one batch. 330 // The server limits the number of items a client can commit in one batch.
329 if (command.has_max_commit_batch_size()) { 331 if (command.has_max_commit_batch_size()) {
330 session->context()->set_max_commit_batch_size( 332 session->context()->set_max_commit_batch_size(
331 command.max_commit_batch_size()); 333 command.max_commit_batch_size());
332 } 334 }
333 if (command.has_set_sync_long_poll_interval()) { 335 if (command.has_set_sync_long_poll_interval()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 entry->Put(SERVER_CTIME, Time()); 367 entry->Put(SERVER_CTIME, Time());
366 entry->Put(SERVER_VERSION, 0); 368 entry->Put(SERVER_VERSION, 0);
367 entry->Put(SERVER_IS_DIR, false); 369 entry->Put(SERVER_IS_DIR, false);
368 entry->Put(SERVER_IS_DEL, false); 370 entry->Put(SERVER_IS_DEL, false);
369 entry->Put(IS_UNAPPLIED_UPDATE, false); 371 entry->Put(IS_UNAPPLIED_UPDATE, false);
370 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance()); 372 entry->Put(SERVER_SPECIFICS, sync_pb::EntitySpecifics::default_instance());
371 entry->Put(SERVER_POSITION_IN_PARENT, 0); 373 entry->Put(SERVER_POSITION_IN_PARENT, 0);
372 } 374 }
373 375
374 } // namespace browser_sync 376 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | chrome/browser/sync/engine/syncer_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698