Chromium Code Reviews| 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/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/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1015 SDVLOG(2) << "Do canary job"; | 1015 SDVLOG(2) << "Do canary job"; |
| 1016 | 1016 |
| 1017 // Only set canary privileges here, when we are about to run the job. This | 1017 // Only set canary privileges here, when we are about to run the job. This |
| 1018 // avoids confusion in managing canary bits during scheduling, when you | 1018 // avoids confusion in managing canary bits during scheduling, when you |
| 1019 // consider that mode switches (e.g., to config) can "pre-empt" a NUDGE that | 1019 // consider that mode switches (e.g., to config) can "pre-empt" a NUDGE that |
| 1020 // was scheduled as canary, and send it to an "unscheduled" state. | 1020 // was scheduled as canary, and send it to an "unscheduled" state. |
| 1021 to_be_canary->GrantCanaryPrivilege(); | 1021 to_be_canary->GrantCanaryPrivilege(); |
| 1022 | 1022 |
| 1023 if (to_be_canary->purpose() == SyncSessionJob::NUDGE) { | 1023 if (to_be_canary->purpose() == SyncSessionJob::NUDGE) { |
| 1024 DCHECK_EQ(pending_nudge_->session(), to_be_canary->session()); | |
| 1024 // TODO(tim): We should be able to remove this... | 1025 // TODO(tim): We should be able to remove this... |
| 1025 scoped_ptr<SyncSession> temp = CreateSyncSession( | 1026 scoped_ptr<SyncSession> temp = CreateSyncSession( |
| 1026 to_be_canary->session()->source()).Pass(); | 1027 to_be_canary->session()->source()).Pass(); |
| 1027 // The routing info might have been changed since we cached the | 1028 // The routing info might have been changed since we cached the |
| 1028 // pending nudge. Update it by coalescing to the latest. | 1029 // pending nudge. Update it by coalescing to the latest. |
| 1029 to_be_canary->mutable_session()->Coalesce(*(temp)); | 1030 to_be_canary->mutable_session()->Coalesce(*(temp)); |
| 1030 } | 1031 } |
| 1031 DoSyncSessionJob(to_be_canary.Pass()); | 1032 DoSyncSessionJob(to_be_canary.Pass()); |
| 1032 } | 1033 } |
| 1033 | 1034 |
| 1034 scoped_ptr<SyncSessionJob> SyncSchedulerImpl::TakePendingJobForCurrentMode() { | 1035 scoped_ptr<SyncSessionJob> SyncSchedulerImpl::TakePendingJobForCurrentMode() { |
| 1035 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1036 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1036 // If we find a scheduled pending_ job, abandon the old one and return a | 1037 // If we find a scheduled pending_ job, abandon the old one and return a |
| 1037 // a clone. If unscheduled, just hand over ownership. | 1038 // a clone. If unscheduled, just hand over ownership. |
| 1038 scoped_ptr<SyncSessionJob> candidate; | 1039 scoped_ptr<SyncSessionJob> candidate; |
| 1039 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() | 1040 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() |
| 1040 && wait_interval_->pending_configure_job) { | 1041 && wait_interval_->pending_configure_job) { |
| 1041 SDVLOG(2) << "Found pending configure job"; | 1042 SDVLOG(2) << "Found pending configure job"; |
| 1042 candidate = | 1043 candidate = |
| 1043 wait_interval_->pending_configure_job->CloneAndAbandon().Pass(); | 1044 wait_interval_->pending_configure_job->CloneAndAbandon().Pass(); |
| 1044 wait_interval_->pending_configure_job = candidate.get(); | 1045 wait_interval_->pending_configure_job = candidate.get(); |
| 1045 } else if (mode_ == NORMAL_MODE && pending_nudge_) { | 1046 } else if (mode_ == NORMAL_MODE && pending_nudge_) { |
| 1046 SDVLOG(2) << "Found pending nudge job"; | 1047 SDVLOG(2) << "Found pending nudge job"; |
| 1047 candidate = pending_nudge_->CloneAndAbandon(); | 1048 candidate = pending_nudge_->CloneAndAbandon(); |
| 1048 pending_nudge_ = candidate.get(); | 1049 pending_nudge_ = candidate.get(); |
| 1049 unscheduled_nudge_storage_.reset(); | 1050 unscheduled_nudge_storage_.reset(); |
| 1050 } | 1051 } |
| 1052 // If we took a job and there's a wait interval, we took the pending canary. | |
| 1053 if (candidate && wait_interval_) | |
| 1054 wait_interval_->timer.Stop(); | |
|
rlarocque
2012/10/30 17:50:20
What if the timer fires somewhere between this lin
tim (not reviewing)
2012/10/30 17:58:29
Everything happens on the same message loop, so if
| |
| 1051 return candidate.Pass(); | 1055 return candidate.Pass(); |
| 1052 } | 1056 } |
| 1053 | 1057 |
| 1054 scoped_ptr<SyncSession> SyncSchedulerImpl::CreateSyncSession( | 1058 scoped_ptr<SyncSession> SyncSchedulerImpl::CreateSyncSession( |
| 1055 const SyncSourceInfo& source) { | 1059 const SyncSourceInfo& source) { |
| 1056 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1060 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1057 DVLOG(2) << "Creating sync session with routes " | 1061 DVLOG(2) << "Creating sync session with routes " |
| 1058 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 1062 << ModelSafeRoutingInfoToString(session_context_->routing_info()); |
| 1059 | 1063 |
| 1060 SyncSourceInfo info(source); | 1064 SyncSourceInfo info(source); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 | 1178 |
| 1175 #undef SDVLOG_LOC | 1179 #undef SDVLOG_LOC |
| 1176 | 1180 |
| 1177 #undef SDVLOG | 1181 #undef SDVLOG |
| 1178 | 1182 |
| 1179 #undef SLOG | 1183 #undef SLOG |
| 1180 | 1184 |
| 1181 #undef ENUM_CASE | 1185 #undef ENUM_CASE |
| 1182 | 1186 |
| 1183 } // namespace syncer | 1187 } // namespace syncer |
| OLD | NEW |