| 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 |
| 36 std::vector<ModelSafeWorker*> temp; |
| 37 std::set_union(workers_.begin(), workers_.end(), |
| 38 session.workers_.begin(), session.workers_.end(), |
| 39 std::back_inserter(temp)); |
| 40 workers_.swap(temp); |
| 41 |
| 42 ModelSafeRoutingInfo temp_r; |
| 43 std::set_union(routing_info_.begin(), routing_info_.end(), |
| 44 session.routing_info_.begin(), session.routing_info_.end(), |
| 45 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin())); |
| 46 routing_info_.swap(temp_r); |
| 47 } |
| 48 |
| 49 void SyncSession::ResetTransientState() { |
| 50 status_controller_.reset(new StatusController(routing_info_)); |
| 51 } |
| 52 |
| 27 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 53 SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
| 28 syncable::ScopedDirLookup dir(context_->directory_manager(), | 54 syncable::ScopedDirLookup dir(context_->directory_manager(), |
| 29 context_->account_name()); | 55 context_->account_name()); |
| 30 if (!dir.good()) | 56 if (!dir.good()) |
| 31 LOG(ERROR) << "Scoped dir lookup failed!"; | 57 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 32 | 58 |
| 33 bool is_share_useable = true; | 59 bool is_share_useable = true; |
| 34 syncable::ModelTypeBitSet initial_sync_ended; | 60 syncable::ModelTypeBitSet initial_sync_ended; |
| 35 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; | 61 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
| 36 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 62 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 status_controller_->syncer_status(), | 74 status_controller_->syncer_status(), |
| 49 status_controller_->error_counters(), | 75 status_controller_->error_counters(), |
| 50 status_controller_->num_server_changes_remaining(), | 76 status_controller_->num_server_changes_remaining(), |
| 51 is_share_useable, | 77 is_share_useable, |
| 52 initial_sync_ended, | 78 initial_sync_ended, |
| 53 download_progress_markers, | 79 download_progress_markers, |
| 54 HasMoreToSync(), | 80 HasMoreToSync(), |
| 55 delegate_->IsSyncingCurrentlySilenced(), | 81 delegate_->IsSyncingCurrentlySilenced(), |
| 56 status_controller_->unsynced_handles().size(), | 82 status_controller_->unsynced_handles().size(), |
| 57 status_controller_->TotalNumConflictingItems(), | 83 status_controller_->TotalNumConflictingItems(), |
| 58 status_controller_->did_commit_items()); | 84 status_controller_->did_commit_items(), |
| 85 source_); |
| 59 } | 86 } |
| 60 | 87 |
| 61 SyncSourceInfo SyncSession::TestAndSetSource() { | 88 SyncSourceInfo SyncSession::TestAndSetSource() { |
| 62 SyncSourceInfo old_source = source_; | 89 SyncSourceInfo old_source = source_; |
| 63 source_ = SyncSourceInfo( | 90 source_ = SyncSourceInfo( |
| 64 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 91 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
| 65 source_.second); | 92 source_.second); |
| 66 return old_source; | 93 return old_source; |
| 67 } | 94 } |
| 68 | 95 |
| 69 bool SyncSession::HasMoreToSync() const { | 96 bool SyncSession::HasMoreToSync() const { |
| 70 const StatusController* status = status_controller_.get(); | 97 const StatusController* status = status_controller_.get(); |
| 71 return ((status->commit_ids().size() < status->unsynced_handles().size()) && | 98 return ((status->commit_ids().size() < status->unsynced_handles().size()) && |
| 72 status->syncer_status().num_successful_commits > 0) || | 99 status->syncer_status().num_successful_commits > 0) || |
| 73 status->conflict_sets_built() || | 100 status->conflict_sets_built() || |
| 74 status->conflicts_resolved(); | 101 status->conflicts_resolved(); |
| 75 // Or, we have conflicting updates, but we're making progress on | 102 // Or, we have conflicting updates, but we're making progress on |
| 76 // resolving them... | 103 // resolving them... |
| 77 } | 104 } |
| 78 | 105 |
| 79 } // namespace sessions | 106 } // namespace sessions |
| 80 } // namespace browser_sync | 107 } // namespace browser_sync |
| OLD | NEW |