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

Side by Side Diff: sync/engine/sync_scheduler_impl.cc

Issue 10825439: sync: remove buggy freshness condition in SyncSchedulerImpl add defensive DCHECKs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: init Created 8 years, 4 months 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) 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/sync_scheduler_impl.h" 5 #include "sync/engine/sync_scheduler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 DCHECK(!session_context_->account_name().empty()); 269 DCHECK(!session_context_->account_name().empty());
270 DCHECK(syncer_.get()); 270 DCHECK(syncer_.get());
271 Mode old_mode = mode_; 271 Mode old_mode = mode_;
272 mode_ = mode; 272 mode_ = mode;
273 AdjustPolling(NULL); // Will kick start poll timer if needed. 273 AdjustPolling(NULL); // Will kick start poll timer if needed.
274 274
275 if (old_mode != mode_) { 275 if (old_mode != mode_) {
276 // We just changed our mode. See if there are any pending jobs that we could 276 // We just changed our mode. See if there are any pending jobs that we could
277 // execute in the new mode. 277 // execute in the new mode.
278 if (mode_ == NORMAL_MODE) {
279 // It is illegal to switch to NORMAL_MODE if a previous CONFIGURATION job
280 // has not yet completed.
281 DCHECK(!wait_interval_.get() ||
282 !wait_interval_->pending_configure_job.get());
283 }
284
278 DoPendingJobIfPossible(false); 285 DoPendingJobIfPossible(false);
279 } 286 }
280 } 287 }
281 288
282 void SyncSchedulerImpl::SendInitialSnapshot() { 289 void SyncSchedulerImpl::SendInitialSnapshot() {
283 DCHECK_EQ(MessageLoop::current(), sync_loop_); 290 DCHECK_EQ(MessageLoop::current(), sync_loop_);
284 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, 291 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this,
285 SyncSourceInfo(), ModelSafeRoutingInfo(), 292 SyncSourceInfo(), ModelSafeRoutingInfo(),
286 std::vector<ModelSafeWorker*>())); 293 std::vector<ModelSafeWorker*>()));
287 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); 294 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 return CONTINUE; 451 return CONTINUE;
445 else 452 else
446 return DROP; 453 return DROP;
447 } 454 }
448 455
449 // We are in normal mode. 456 // We are in normal mode.
450 DCHECK_EQ(mode_, NORMAL_MODE); 457 DCHECK_EQ(mode_, NORMAL_MODE);
451 DCHECK_NE(job.purpose, SyncSessionJob::CONFIGURATION); 458 DCHECK_NE(job.purpose, SyncSessionJob::CONFIGURATION);
452 459
453 // Freshness condition 460 // Freshness condition
454 if (job.scheduled_start < last_sync_session_end_time_) { 461 if (job.scheduled_start < last_nudge_or_poll_end_time_) {
455 SDVLOG(2) << "Dropping job because of freshness"; 462 SDVLOG(2) << "Dropping job because of freshness";
456 return DROP; 463 return DROP;
457 } 464 }
458 465
459 if (!session_context_->connection_manager()->HasInvalidAuthToken()) 466 if (!session_context_->connection_manager()->HasInvalidAuthToken())
460 return CONTINUE; 467 return CONTINUE;
461 468
462 SDVLOG(2) << "No valid auth token. Using that to decide on job."; 469 SDVLOG(2) << "No valid auth token. Using that to decide on job.";
463 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP; 470 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP;
464 } 471 }
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 773 }
767 SDVLOG(2) << "Done SyncShare looping."; 774 SDVLOG(2) << "Done SyncShare looping.";
768 775
769 FinishSyncSessionJob(job); 776 FinishSyncSessionJob(job);
770 } 777 }
771 778
772 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { 779 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) {
773 DCHECK_EQ(MessageLoop::current(), sync_loop_); 780 DCHECK_EQ(MessageLoop::current(), sync_loop_);
774 // Update timing information for how often datatypes are triggering nudges. 781 // Update timing information for how often datatypes are triggering nudges.
775 base::TimeTicks now = TimeTicks::Now(); 782 base::TimeTicks now = TimeTicks::Now();
776 if (!last_sync_session_end_time_.is_null()) { 783 if (!last_nudge_or_poll_end_time_.is_null()) {
784 // TODO(tim): We should probably track NUDGE time separately to avoid
785 // skewing the histogram? Does it make sense to only compare against
786 // successful sessions?
777 ModelTypePayloadMap::const_iterator iter; 787 ModelTypePayloadMap::const_iterator iter;
788 DCHECK_EQ(job.purpose == SyncSessionJob::POLL,
789 job.session->source().types.empty());
778 for (iter = job.session->source().types.begin(); 790 for (iter = job.session->source().types.begin();
779 iter != job.session->source().types.end(); 791 iter != job.session->source().types.end();
780 ++iter) { 792 ++iter) {
781 #define PER_DATA_TYPE_MACRO(type_str) \ 793 #define PER_DATA_TYPE_MACRO(type_str) \
782 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ 794 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \
783 now - last_sync_session_end_time_); 795 now - last_nudge_or_poll_end_time_);
784 SYNC_DATA_TYPE_HISTOGRAM(iter->first); 796 SYNC_DATA_TYPE_HISTOGRAM(iter->first);
785 #undef PER_DATA_TYPE_MACRO 797 #undef PER_DATA_TYPE_MACRO
786 } 798 }
787 } 799 }
788 last_sync_session_end_time_ = now; 800
801 // TODO(tim): Consolidate Succeeded() checks by breaking this Finish job
802 // flow into successful / unsuccessful handler methods.
803 if (job.session->Succeeded() && (job.purpose == SyncSessionJob::NUDGE ||
804 job.purpose == SyncSessionJob::POLL)) {
805 last_nudge_or_poll_end_time_ = now;
806 }
789 807
790 // Now update the status of the connection from SCM. We need this to decide 808 // Now update the status of the connection from SCM. We need this to decide
791 // whether we need to save/run future jobs. The notifications from SCM are not 809 // whether we need to save/run future jobs. The notifications from SCM are not
792 // reliable. 810 // reliable.
793 // 811 //
794 // TODO(rlarocque): crbug.com/110954 812 // TODO(rlarocque): crbug.com/110954
795 // We should get rid of the notifications and it is probably not needed to 813 // We should get rid of the notifications and it is probably not needed to
796 // maintain this status variable in 2 places. We should query it directly from 814 // maintain this status variable in 2 places. We should query it directly from
797 // SCM when needed. 815 // SCM when needed.
798 ServerConnectionManager* scm = session_context_->connection_manager(); 816 ServerConnectionManager* scm = session_context_->connection_manager();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 985
968 void SyncSchedulerImpl::DoPendingJobIfPossible(bool is_canary_job) { 986 void SyncSchedulerImpl::DoPendingJobIfPossible(bool is_canary_job) {
969 DCHECK_EQ(MessageLoop::current(), sync_loop_); 987 DCHECK_EQ(MessageLoop::current(), sync_loop_);
970 SyncSessionJob* job_to_execute = NULL; 988 SyncSessionJob* job_to_execute = NULL;
971 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() 989 if (mode_ == CONFIGURATION_MODE && wait_interval_.get()
972 && wait_interval_->pending_configure_job.get()) { 990 && wait_interval_->pending_configure_job.get()) {
973 SDVLOG(2) << "Found pending configure job"; 991 SDVLOG(2) << "Found pending configure job";
974 job_to_execute = wait_interval_->pending_configure_job.get(); 992 job_to_execute = wait_interval_->pending_configure_job.get();
975 } else if (mode_ == NORMAL_MODE && pending_nudge_.get()) { 993 } else if (mode_ == NORMAL_MODE && pending_nudge_.get()) {
976 SDVLOG(2) << "Found pending nudge job"; 994 SDVLOG(2) << "Found pending nudge job";
977 // Pending jobs mostly have time from the past. Reset it so this job
978 // will get executed.
979 if (pending_nudge_->scheduled_start < TimeTicks::Now())
980 pending_nudge_->scheduled_start = TimeTicks::Now();
981 995
982 scoped_ptr<SyncSession> session(CreateSyncSession( 996 scoped_ptr<SyncSession> session(CreateSyncSession(
983 pending_nudge_->session->source())); 997 pending_nudge_->session->source()));
984 998
985 // Also the routing info might have been changed since we cached the 999 // Also the routing info might have been changed since we cached the
986 // pending nudge. Update it by coalescing to the latest. 1000 // pending nudge. Update it by coalescing to the latest.
987 pending_nudge_->session->Coalesce(*(session.get())); 1001 pending_nudge_->session->Coalesce(*(session.get()));
988 // The pending nudge would be cleared in the DoSyncSessionJob function. 1002 // The pending nudge would be cleared in the DoSyncSessionJob function.
989 job_to_execute = pending_nudge_.get(); 1003 job_to_execute = pending_nudge_.get();
990 } 1004 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1133
1120 #undef SDVLOG_LOC 1134 #undef SDVLOG_LOC
1121 1135
1122 #undef SDVLOG 1136 #undef SDVLOG
1123 1137
1124 #undef SLOG 1138 #undef SLOG
1125 1139
1126 #undef ENUM_CASE 1140 #undef ENUM_CASE
1127 1141
1128 } // namespace syncer 1142 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698