sync_session.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/sync/sessions/sync_session.h" 6#include "chrome/browser/sync/syncable/directory_manager.h" 7#include "chrome/browser/sync/syncable/model_type.h" 8 9namespace browser_sync { 10namespace sessions { 11 12SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate) 13 : context_(context), 14 source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), 15 write_transaction_(NULL), 16 delegate_(delegate) { 17 18 context_->registrar()->GetWorkers( 19 const_cast<std::vector<ModelSafeWorker*>*>(&workers_)); 20 context_->registrar()->GetModelSafeRoutingInfo( 21 const_cast<ModelSafeRoutingInfo*>(&routing_info_)); 22 status_controller_.reset(new StatusController(routing_info_)); 23} 24 25SyncSessionSnapshot SyncSession::TakeSnapshot() const { 26 syncable::ScopedDirLookup dir(context_->directory_manager(), 27 context_->account_name()); 28 if (!dir.good()) 29 LOG(ERROR) << "Scoped dir lookup failed!"; 30 31 bool is_share_useable = true; 32 syncable::ModelTypeBitSet initial_sync_ended; 33 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { 34 syncable::ModelType type(syncable::ModelTypeFromInt(i)); 35 if (routing_info_.count(type) != 0) { 36 if (dir->initial_sync_ended_for_type(type)) 37 initial_sync_ended.set(type); 38 else 39 is_share_useable = false; 40 } 41 } 42 43 return SyncSessionSnapshot( 44 status_controller_->syncer_status(), 45 status_controller_->error_counters(), 46 status_controller_->num_server_changes_remaining(), 47 status_controller_->ComputeMaxLocalTimestamp(), 48 is_share_useable, 49 initial_sync_ended, 50 HasMoreToSync(), 51 delegate_->IsSyncingCurrentlySilenced(), 52 status_controller_->unsynced_handles().size(), 53 status_controller_->TotalNumConflictingItems(), 54 status_controller_->did_commit_items()); 55} 56 57sync_pb::GetUpdatesCallerInfo::GetUpdatesSource 58 SyncSession::TestAndSetSource() { 59 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource old_source = source_; 60 set_source(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION); 61 return old_source; 62} 63 64bool SyncSession::HasMoreToSync() const { 65 const StatusController* status = status_controller_.get(); 66 return ((status->commit_ids().size() < status->unsynced_handles().size()) && 67 status->syncer_status().num_successful_commits > 0) || 68 status->conflict_sets_built() || 69 status->conflicts_resolved(); 70 // Or, we have conflicting updates, but we're making progress on 71 // resolving them... 72 } 73 74} // namespace sessions 75} // namespace browser_sync 76