OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/internal_api/sync_rollback_manager.h" | 5 #include "sync/internal_api/sync_rollback_manager.h" |
6 | 6 |
7 #include "sync/internal_api/public/base/model_type.h" | 7 #include "sync/internal_api/public/base/model_type.h" |
8 #include "sync/internal_api/public/read_node.h" | 8 #include "sync/internal_api/public/read_node.h" |
9 #include "sync/internal_api/public/read_transaction.h" | 9 #include "sync/internal_api/public/read_transaction.h" |
10 #include "sync/internal_api/public/util/syncer_error.h" | 10 #include "sync/internal_api/public/util/syncer_error.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 CHECK(workers_.find(group) == workers_.end()); | 60 CHECK(workers_.find(group) == workers_.end()); |
61 workers_[group] = workers[i]; | 61 workers_[group] = workers[i]; |
62 } | 62 } |
63 | 63 |
64 rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes(); | 64 rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes(); |
65 rollback_ready_types_.RetainAll(BackupTypes()); | 65 rollback_ready_types_.RetainAll(BackupTypes()); |
66 } | 66 } |
67 | 67 |
68 void SyncRollbackManager::StartSyncingNormally( | 68 void SyncRollbackManager::StartSyncingNormally( |
69 const ModelSafeRoutingInfo& routing_info){ | 69 const ModelSafeRoutingInfo& routing_info){ |
| 70 if (rollback_ready_types_.Empty()) { |
| 71 NotifyRollbackDone(); |
| 72 return; |
| 73 } |
| 74 |
70 std::map<ModelType, syncable::Directory::Metahandles> to_delete; | 75 std::map<ModelType, syncable::Directory::Metahandles> to_delete; |
71 | |
72 { | 76 { |
73 WriteTransaction trans(FROM_HERE, GetUserShare()); | 77 WriteTransaction trans(FROM_HERE, GetUserShare()); |
74 syncable::Directory::Metahandles unsynced; | 78 syncable::Directory::Metahandles unsynced; |
75 GetUserShare()->directory->GetUnsyncedMetaHandles(trans.GetWrappedTrans(), | 79 GetUserShare()->directory->GetUnsyncedMetaHandles(trans.GetWrappedTrans(), |
76 &unsynced); | 80 &unsynced); |
77 for (size_t i = 0; i < unsynced.size(); ++i) { | 81 for (size_t i = 0; i < unsynced.size(); ++i) { |
78 syncable::MutableEntry e(trans.GetWrappedWriteTrans(), | 82 syncable::MutableEntry e(trans.GetWrappedWriteTrans(), |
79 syncable::GET_BY_HANDLE, unsynced[i]); | 83 syncable::GET_BY_HANDLE, unsynced[i]); |
80 if (!e.good() || e.GetIsDel() || e.GetId().ServerKnows()) | 84 if (!e.good() || e.GetIsDel() || e.GetId().ServerKnows()) |
81 continue; | 85 continue; |
(...skipping 11 matching lines...) Expand all Loading... |
93 | 97 |
94 for (std::map<ModelType, syncable::Directory::Metahandles>::iterator it = | 98 for (std::map<ModelType, syncable::Directory::Metahandles>::iterator it = |
95 to_delete.begin(); it != to_delete.end(); ++it) { | 99 to_delete.begin(); it != to_delete.end(); ++it) { |
96 ModelSafeGroup group = routing_info.find(it->first)->second; | 100 ModelSafeGroup group = routing_info.find(it->first)->second; |
97 CHECK(workers_.find(group) != workers_.end()); | 101 CHECK(workers_.find(group) != workers_.end()); |
98 workers_[group]->DoWorkAndWaitUntilDone( | 102 workers_[group]->DoWorkAndWaitUntilDone( |
99 base::Bind(&SyncRollbackManager::DeleteOnWorkerThread, | 103 base::Bind(&SyncRollbackManager::DeleteOnWorkerThread, |
100 base::Unretained(this), | 104 base::Unretained(this), |
101 it->first, it->second)); | 105 it->first, it->second)); |
102 } | 106 } |
| 107 |
| 108 NotifyRollbackDone(); |
103 } | 109 } |
104 | 110 |
105 SyncerError SyncRollbackManager::DeleteOnWorkerThread( | 111 SyncerError SyncRollbackManager::DeleteOnWorkerThread( |
106 ModelType type, std::vector<int64> handles) { | 112 ModelType type, std::vector<int64> handles) { |
107 CHECK(change_delegate_); | 113 CHECK(change_delegate_); |
108 | 114 |
109 { | 115 { |
110 ChangeRecordList deletes; | 116 ChangeRecordList deletes; |
111 WriteTransaction trans(FROM_HERE, GetUserShare()); | 117 WriteTransaction trans(FROM_HERE, GetUserShare()); |
112 for (size_t i = 0; i < handles.size(); ++i) { | 118 for (size_t i = 0; i < handles.size(); ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
123 } | 129 } |
124 | 130 |
125 change_delegate_->OnChangesApplied(type, 1, &trans, | 131 change_delegate_->OnChangesApplied(type, 1, &trans, |
126 MakeImmutable(&deletes)); | 132 MakeImmutable(&deletes)); |
127 } | 133 } |
128 | 134 |
129 change_delegate_->OnChangesComplete(type); | 135 change_delegate_->OnChangesComplete(type); |
130 return SYNCER_OK; | 136 return SYNCER_OK; |
131 } | 137 } |
132 | 138 |
| 139 void SyncRollbackManager::NotifyRollbackDone() { |
| 140 SyncProtocolError error; |
| 141 error.action = ROLLBACK_DONE; |
| 142 FOR_EACH_OBSERVER(SyncManager::Observer, *GetObservers(), |
| 143 OnActionableError(error)); |
| 144 } |
| 145 |
133 } // namespace syncer | 146 } // namespace syncer |
OLD | NEW |