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/engine/model_safe_worker.h" | |
akalin
2011/01/26 01:15:17
move this to the .h file
Nicolas Zea
2011/01/26 01:41:28
Done.
| |
5 #include "chrome/browser/sync/sessions/sync_session.h" | 6 #include "chrome/browser/sync/sessions/sync_session.h" |
6 #include "chrome/browser/sync/syncable/directory_manager.h" | 7 #include "chrome/browser/sync/syncable/directory_manager.h" |
7 #include "chrome/browser/sync/syncable/model_type.h" | 8 #include "chrome/browser/sync/syncable/model_type.h" |
8 | 9 |
9 namespace browser_sync { | 10 namespace browser_sync { |
10 namespace sessions { | 11 namespace sessions { |
11 | 12 |
13 TypePayloadMap ModelTypeBitSetToTypePayloadMap( | |
14 const syncable::ModelTypeBitSet& types, | |
15 const std::string& payload) { | |
16 TypePayloadMap map; | |
17 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; | |
18 i < types.size(); | |
19 ++i) { | |
akalin
2011/01/26 01:15:17
this can go on previous line
Nicolas Zea
2011/01/26 01:41:28
Done.
| |
20 if (types[i]) { | |
21 map[syncable::ModelTypeFromInt(i)] = payload; | |
22 } | |
23 } | |
24 return map; | |
25 } | |
26 | |
27 TypePayloadMap RoutingInfoToTypePayloadMap(const ModelSafeRoutingInfo& routes, | |
28 const std::string& payload) { | |
29 TypePayloadMap map; | |
30 for (ModelSafeRoutingInfo::const_iterator i = routes.begin(); | |
31 i != routes.end(); | |
32 ++i) { | |
akalin
2011/01/26 01:15:17
so can this
Nicolas Zea
2011/01/26 01:41:28
Done.
| |
33 map[i->first] = payload; | |
34 } | |
35 return map; | |
36 } | |
37 | |
38 TypePayloadMap CoalescePayloads(const TypePayloadMap& original, | |
39 const TypePayloadMap& update) { | |
40 TypePayloadMap new_map = original; | |
41 for (TypePayloadMap::const_iterator i = update.begin(); | |
42 i != update.end(); | |
43 ++i) { | |
44 if (original.count(i->first) == 0) { | |
45 // If this datatype isn't already in our map, add it with whatever payload | |
46 // it has. | |
47 new_map[i->first] = i->second; | |
48 } else if (i->second.length() > 0) { | |
49 // If this datatype is already in our map, we only overwrite the payload | |
50 // if the new one is non-empty. | |
51 new_map[i->first] = i->second; | |
52 } | |
53 } | |
54 return new_map; | |
55 } | |
56 | |
57 SyncSourceInfo::SyncSourceInfo() | |
58 : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} | |
59 | |
60 SyncSourceInfo::SyncSourceInfo( | |
61 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, | |
62 const TypePayloadMap& t) | |
63 : updates_source(u), types(t) {} | |
64 | |
12 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 65 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
13 SyncSourceInfo source, | 66 SyncSourceInfo source, |
14 const ModelSafeRoutingInfo& routing_info, | 67 const ModelSafeRoutingInfo& routing_info, |
15 const std::vector<ModelSafeWorker*>& workers) | 68 const std::vector<ModelSafeWorker*>& workers) |
16 : context_(context), | 69 : context_(context), |
17 source_(source), | 70 source_(source), |
18 write_transaction_(NULL), | 71 write_transaction_(NULL), |
19 delegate_(delegate), | 72 delegate_(delegate), |
20 workers_(workers), | 73 workers_(workers), |
21 routing_info_(routing_info) { | 74 routing_info_(routing_info) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 delegate_->IsSyncingCurrentlySilenced(), | 108 delegate_->IsSyncingCurrentlySilenced(), |
56 status_controller_->unsynced_handles().size(), | 109 status_controller_->unsynced_handles().size(), |
57 status_controller_->TotalNumConflictingItems(), | 110 status_controller_->TotalNumConflictingItems(), |
58 status_controller_->did_commit_items()); | 111 status_controller_->did_commit_items()); |
59 } | 112 } |
60 | 113 |
61 SyncSourceInfo SyncSession::TestAndSetSource() { | 114 SyncSourceInfo SyncSession::TestAndSetSource() { |
62 SyncSourceInfo old_source = source_; | 115 SyncSourceInfo old_source = source_; |
63 source_ = SyncSourceInfo( | 116 source_ = SyncSourceInfo( |
64 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 117 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
65 source_.second); | 118 source_.types); |
66 return old_source; | 119 return old_source; |
67 } | 120 } |
68 | 121 |
69 bool SyncSession::HasMoreToSync() const { | 122 bool SyncSession::HasMoreToSync() const { |
70 const StatusController* status = status_controller_.get(); | 123 const StatusController* status = status_controller_.get(); |
71 return ((status->commit_ids().size() < status->unsynced_handles().size()) && | 124 return ((status->commit_ids().size() < status->unsynced_handles().size()) && |
72 status->syncer_status().num_successful_commits > 0) || | 125 status->syncer_status().num_successful_commits > 0) || |
73 status->conflict_sets_built() || | 126 status->conflict_sets_built() || |
74 status->conflicts_resolved(); | 127 status->conflicts_resolved(); |
75 // Or, we have conflicting updates, but we're making progress on | 128 // Or, we have conflicting updates, but we're making progress on |
76 // resolving them... | 129 // resolving them... |
77 } | 130 } |
78 | 131 |
79 } // namespace sessions | 132 } // namespace sessions |
80 } // namespace browser_sync | 133 } // namespace browser_sync |
OLD | NEW |