| 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 TypePayloadMap ModelTypeBitSetToTypePayloadMap( | |
| 13 const syncable::ModelTypeBitSet& types, | |
| 14 const std::string& payload) { | |
| 15 TypePayloadMap types_with_payloads; | |
| 16 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; | |
| 17 i < types.size(); ++i) { | |
| 18 if (types[i]) { | |
| 19 types_with_payloads[syncable::ModelTypeFromInt(i)] = payload; | |
| 20 } | |
| 21 } | |
| 22 return types_with_payloads; | |
| 23 } | |
| 24 | |
| 25 TypePayloadMap RoutingInfoToTypePayloadMap(const ModelSafeRoutingInfo& routes, | |
| 26 const std::string& payload) { | |
| 27 TypePayloadMap types_with_payloads; | |
| 28 for (ModelSafeRoutingInfo::const_iterator i = routes.begin(); | |
| 29 i != routes.end(); ++i) { | |
| 30 types_with_payloads[i->first] = payload; | |
| 31 } | |
| 32 return types_with_payloads; | |
| 33 } | |
| 34 | |
| 35 void CoalescePayloads(TypePayloadMap* original, | |
| 36 const TypePayloadMap& update) { | |
| 37 for (TypePayloadMap::const_iterator i = update.begin(); | |
| 38 i != update.end(); ++i) { | |
| 39 if (original->count(i->first) == 0) { | |
| 40 // If this datatype isn't already in our map, add it with whatever payload | |
| 41 // it has. | |
| 42 (*original)[i->first] = i->second; | |
| 43 } else if (i->second.length() > 0) { | |
| 44 // If this datatype is already in our map, we only overwrite the payload | |
| 45 // if the new one is non-empty. | |
| 46 (*original)[i->first] = i->second; | |
| 47 } | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 SyncSourceInfo::SyncSourceInfo() | |
| 52 : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} | |
| 53 | |
| 54 SyncSourceInfo::SyncSourceInfo( | |
| 55 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, | |
| 56 const TypePayloadMap& t) | |
| 57 : updates_source(u), types(t) {} | |
| 58 | |
| 59 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
| 60 SyncSourceInfo source, | 13 SyncSourceInfo source, |
| 61 const ModelSafeRoutingInfo& routing_info, | 14 const ModelSafeRoutingInfo& routing_info, |
| 62 const std::vector<ModelSafeWorker*>& workers) | 15 const std::vector<ModelSafeWorker*>& workers) |
| 63 : context_(context), | 16 : context_(context), |
| 64 source_(source), | 17 source_(source), |
| 65 write_transaction_(NULL), | 18 write_transaction_(NULL), |
| 66 delegate_(delegate), | 19 delegate_(delegate), |
| 67 workers_(workers), | 20 workers_(workers), |
| 68 routing_info_(routing_info) { | 21 routing_info_(routing_info) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 status_controller_->unsynced_handles().size(), | 82 status_controller_->unsynced_handles().size(), |
| 130 status_controller_->TotalNumConflictingItems(), | 83 status_controller_->TotalNumConflictingItems(), |
| 131 status_controller_->did_commit_items(), | 84 status_controller_->did_commit_items(), |
| 132 source_); | 85 source_); |
| 133 } | 86 } |
| 134 | 87 |
| 135 SyncSourceInfo SyncSession::TestAndSetSource() { | 88 SyncSourceInfo SyncSession::TestAndSetSource() { |
| 136 SyncSourceInfo old_source = source_; | 89 SyncSourceInfo old_source = source_; |
| 137 source_ = SyncSourceInfo( | 90 source_ = SyncSourceInfo( |
| 138 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 91 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
| 139 source_.types); | 92 source_.second); |
| 140 return old_source; | 93 return old_source; |
| 141 } | 94 } |
| 142 | 95 |
| 143 bool SyncSession::HasMoreToSync() const { | 96 bool SyncSession::HasMoreToSync() const { |
| 144 const StatusController* status = status_controller_.get(); | 97 const StatusController* status = status_controller_.get(); |
| 145 return ((status->commit_ids().size() < status->unsynced_handles().size()) && | 98 return ((status->commit_ids().size() < status->unsynced_handles().size()) && |
| 146 status->syncer_status().num_successful_commits > 0) || | 99 status->syncer_status().num_successful_commits > 0) || |
| 147 status->conflict_sets_built() || | 100 status->conflict_sets_built() || |
| 148 status->conflicts_resolved(); | 101 status->conflicts_resolved(); |
| 149 // Or, we have conflicting updates, but we're making progress on | 102 // Or, we have conflicting updates, but we're making progress on |
| 150 // resolving them... | 103 // resolving them... |
| 151 } | 104 } |
| 152 | 105 |
| 153 } // namespace sessions | 106 } // namespace sessions |
| 154 } // namespace browser_sync | 107 } // namespace browser_sync |
| OLD | NEW |