| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/sessions/sync_session.h" | 5 #include "chrome/browser/sync/sessions/sync_session.h" |
| 6 #include "chrome/browser/sync/syncable/directory_manager.h" | 6 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 7 #include "chrome/browser/sync/syncable/model_type.h" | 7 #include "chrome/browser/sync/syncable/model_type.h" |
| 8 | 8 |
| 9 namespace browser_sync { | 9 namespace browser_sync { |
| 10 namespace sessions { | 10 namespace sessions { |
| 11 | 11 |
| 12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
| 13 SyncSourceInfo source, | 13 SyncSourceInfo source, |
| 14 const ModelSafeRoutingInfo& routing_info, | 14 const ModelSafeRoutingInfo& routing_info, |
| 15 const std::vector<ModelSafeWorker*>& workers) | 15 const std::vector<ModelSafeWorker*>& workers) |
| 16 : context_(context), | 16 : context_(context), |
| 17 source_(source), | 17 source_(source), |
| 18 write_transaction_(NULL), | 18 write_transaction_(NULL), |
| 19 delegate_(delegate), | 19 delegate_(delegate), |
| 20 workers_(workers), | 20 workers_(workers), |
| 21 routing_info_(routing_info) { | 21 routing_info_(routing_info) { |
| 22 status_controller_.reset(new StatusController(routing_info_)); | 22 status_controller_.reset(new StatusController(routing_info_)); |
| 23 } | 23 } |
| 24 | 24 |
| 25 SyncSession::~SyncSession() {} | 25 SyncSession::~SyncSession() {} |
| 26 | 26 |
| 27 void SyncSession::Coalesce(const SyncSession* session) { |
| 28 if (context_ != session->context() || delegate_ != session->delegate_) { |
| 29 NOTREACHED(); |
| 30 return; |
| 31 } |
| 32 |
| 33 source_ = SyncSourceInfo(session->source_.first, |
| 34 source_.second | session->source_.second); |
| 35 // TODO(tim): Update routing_info_ and workers_. |
| 36 } |
| 37 |
| 38 void SyncSession::ResetTransientState() { |
| 39 status_controller_.reset(new StatusController(routing_info_)); |
| 40 } |
| 41 |
| 27 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 42 SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
| 28 syncable::ScopedDirLookup dir(context_->directory_manager(), | 43 syncable::ScopedDirLookup dir(context_->directory_manager(), |
| 29 context_->account_name()); | 44 context_->account_name()); |
| 30 if (!dir.good()) | 45 if (!dir.good()) |
| 31 LOG(ERROR) << "Scoped dir lookup failed!"; | 46 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 32 | 47 |
| 33 bool is_share_useable = true; | 48 bool is_share_useable = true; |
| 34 syncable::ModelTypeBitSet initial_sync_ended; | 49 syncable::ModelTypeBitSet initial_sync_ended; |
| 35 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; | 50 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
| 36 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 51 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 status_controller_->syncer_status(), | 63 status_controller_->syncer_status(), |
| 49 status_controller_->error_counters(), | 64 status_controller_->error_counters(), |
| 50 status_controller_->num_server_changes_remaining(), | 65 status_controller_->num_server_changes_remaining(), |
| 51 is_share_useable, | 66 is_share_useable, |
| 52 initial_sync_ended, | 67 initial_sync_ended, |
| 53 download_progress_markers, | 68 download_progress_markers, |
| 54 HasMoreToSync(), | 69 HasMoreToSync(), |
| 55 delegate_->IsSyncingCurrentlySilenced(), | 70 delegate_->IsSyncingCurrentlySilenced(), |
| 56 status_controller_->unsynced_handles().size(), | 71 status_controller_->unsynced_handles().size(), |
| 57 status_controller_->TotalNumConflictingItems(), | 72 status_controller_->TotalNumConflictingItems(), |
| 58 status_controller_->did_commit_items()); | 73 status_controller_->did_commit_items(), |
| 74 source_); |
| 59 } | 75 } |
| 60 | 76 |
| 61 SyncSourceInfo SyncSession::TestAndSetSource() { | 77 SyncSourceInfo SyncSession::TestAndSetSource() { |
| 62 SyncSourceInfo old_source = source_; | 78 SyncSourceInfo old_source = source_; |
| 63 source_ = SyncSourceInfo( | 79 source_ = SyncSourceInfo( |
| 64 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 80 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
| 65 source_.second); | 81 source_.second); |
| 66 return old_source; | 82 return old_source; |
| 67 } | 83 } |
| 68 | 84 |
| 69 bool SyncSession::HasMoreToSync() const { | 85 bool SyncSession::HasMoreToSync() const { |
| 70 const StatusController* status = status_controller_.get(); | 86 const StatusController* status = status_controller_.get(); |
| 71 return ((status->commit_ids().size() < status->unsynced_handles().size()) && | 87 return ((status->commit_ids().size() < status->unsynced_handles().size()) && |
| 72 status->syncer_status().num_successful_commits > 0) || | 88 status->syncer_status().num_successful_commits > 0) || |
| 73 status->conflict_sets_built() || | 89 status->conflict_sets_built() || |
| 74 status->conflicts_resolved(); | 90 status->conflicts_resolved(); |
| 75 // Or, we have conflicting updates, but we're making progress on | 91 // Or, we have conflicting updates, but we're making progress on |
| 76 // resolving them... | 92 // resolving them... |
| 77 } | 93 } |
| 78 | 94 |
| 79 } // namespace sessions | 95 } // namespace sessions |
| 80 } // namespace browser_sync | 96 } // namespace browser_sync |
| OLD | NEW |