diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 20:31:18 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 20:31:18 +0000 |
commit | eeac662cd531cfd3482e9784107d93b061909981 (patch) | |
tree | 854a69a2075562548ea7fd57543db03436ce416d /sync/sessions/sync_session.cc | |
parent | 7ac0b482eb36cd32cc0cff38e3af78f5932bb3f2 (diff) | |
download | chromium_src-eeac662cd531cfd3482e9784107d93b061909981.zip chromium_src-eeac662cd531cfd3482e9784107d93b061909981.tar.gz chromium_src-eeac662cd531cfd3482e9784107d93b061909981.tar.bz2 |
sync: reland scheduler ownership refactoring, now with less crash
Prevent abandoned jobs from entering DoCanaryJob by stopping the timer
in TakePendingJobForCurrentMode.
Original review at https://codereview.chromium.org/10917234/
BUG=158313
Review URL: https://chromiumcodereview.appspot.com/11341030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions/sync_session.cc')
-rw-r--r-- | sync/sessions/sync_session.cc | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/sync/sessions/sync_session.cc b/sync/sessions/sync_session.cc index 5a2b572..9be78d8 100644 --- a/sync/sessions/sync_session.cc +++ b/sync/sessions/sync_session.cc @@ -77,8 +77,7 @@ SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, delegate_(delegate), workers_(workers), routing_info_(routing_info), - enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)), - finished_(false) { + enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)) { status_controller_.reset(new StatusController(routing_info_)); std::sort(workers_.begin(), workers_.end()); } @@ -115,30 +114,31 @@ void SyncSession::Coalesce(const SyncSession& session) { enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); } -void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { +void SyncSession::RebaseRoutingInfoWithLatest( + const ModelSafeRoutingInfo& routing_info, + const std::vector<ModelSafeWorker*>& workers) { ModelSafeRoutingInfo temp_routing_info; - // Take the intersecion and also set the routing info(it->second) from the + // Take the intersection and also set the routing info(it->second) from the // passed in session. for (ModelSafeRoutingInfo::const_iterator it = - session.routing_info_.begin(); it != session.routing_info_.end(); + routing_info.begin(); it != routing_info.end(); ++it) { if (routing_info_.find(it->first) != routing_info_.end()) { temp_routing_info[it->first] = it->second; } } - - // Now swap it. routing_info_.swap(temp_routing_info); - // Now update the payload map. - PurgeStaleStates(&source_.types, session.routing_info_); + PurgeStaleStates(&source_.types, routing_info); // Now update the workers. std::vector<ModelSafeWorker*> temp; + std::vector<ModelSafeWorker*> sorted_workers = workers; + std::sort(sorted_workers.begin(), sorted_workers.end()); std::set_intersection(workers_.begin(), workers_.end(), - session.workers_.begin(), session.workers_.end(), - std::back_inserter(temp)); + sorted_workers.begin(), sorted_workers.end(), + std::back_inserter(temp)); workers_.swap(temp); // Now update enabled groups. @@ -146,7 +146,6 @@ void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { } void SyncSession::PrepareForAnotherSyncCycle() { - finished_ = false; source_.updates_source = sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; status_controller_.reset(new StatusController(routing_info_)); @@ -183,8 +182,7 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { source_, context_->notifications_enabled(), dir->GetEntriesCount(), - status_controller_->sync_start_time(), - !Succeeded()); + status_controller_->sync_start_time()); } void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { @@ -219,35 +217,11 @@ std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const { return enabled_groups_with_conflicts; } -namespace { - -// Returns false iff one of the command results had an error. -bool HadErrors(const ModelNeutralState& state) { - const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); - const bool download_updates_error = - SyncerErrorIsError(state.last_download_updates_result); - const bool commit_error = SyncerErrorIsError(state.commit_result); - return get_key_error || download_updates_error || commit_error; -} -} // namespace - -bool SyncSession::Succeeded() const { - return finished_ && !HadErrors(status_controller_->model_neutral_state()); -} - -bool SyncSession::SuccessfullyReachedServer() const { +bool SyncSession::DidReachServer() const { const ModelNeutralState& state = status_controller_->model_neutral_state(); - bool reached_server = state.last_get_key_result == SYNCER_OK || - state.last_download_updates_result == SYNCER_OK; - // It's possible that we reached the server on one attempt, then had an error - // on the next (or didn't perform some of the server-communicating commands). - // We want to verify that, for all commands attempted, we successfully spoke - // with the server. Therefore, we verify no errors and at least one SYNCER_OK. - return reached_server && !HadErrors(state); -} - -void SyncSession::SetFinished() { - finished_ = true; + return state.last_get_key_result >= FIRST_SERVER_RETURN_VALUE || + state.last_download_updates_result >= FIRST_SERVER_RETURN_VALUE || + state.commit_result >= FIRST_SERVER_RETURN_VALUE; } } // namespace sessions |