| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/engine/apply_updates_command.h" | 5 #include "sync/engine/apply_updates_command.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "sync/engine/update_applicator.h" | 8 #include "sync/engine/update_applicator.h" |
| 9 #include "sync/sessions/sync_session.h" | 9 #include "sync/sessions/sync_session.h" |
| 10 #include "sync/syncable/directory.h" | 10 #include "sync/syncable/directory.h" |
| 11 #include "sync/syncable/read_transaction.h" | 11 #include "sync/syncable/read_transaction.h" |
| 12 #include "sync/syncable/write_transaction.h" | 12 #include "sync/syncable/write_transaction.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 | 15 |
| 16 using sessions::SyncSession; | 16 using sessions::SyncSession; |
| 17 | 17 |
| 18 ApplyUpdatesCommand::ApplyUpdatesCommand() {} | 18 ApplyUpdatesCommand::ApplyUpdatesCommand() {} |
| 19 ApplyUpdatesCommand::~ApplyUpdatesCommand() {} | 19 ApplyUpdatesCommand::~ApplyUpdatesCommand() {} |
| 20 | 20 |
| 21 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange( | 21 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange( |
| 22 const sessions::SyncSession& session) const { | 22 const sessions::SyncSession& session) const { |
| 23 std::set<ModelSafeGroup> groups_with_unapplied_updates; | 23 std::set<ModelSafeGroup> groups_with_unapplied_updates; |
| 24 | 24 |
| 25 syncer::FullModelTypeSet server_types_with_unapplied_updates; | 25 FullModelTypeSet server_types_with_unapplied_updates; |
| 26 { | 26 { |
| 27 syncable::Directory* dir = session.context()->directory(); | 27 syncable::Directory* dir = session.context()->directory(); |
| 28 syncable::ReadTransaction trans(FROM_HERE, dir); | 28 syncable::ReadTransaction trans(FROM_HERE, dir); |
| 29 server_types_with_unapplied_updates = | 29 server_types_with_unapplied_updates = |
| 30 dir->GetServerTypesWithUnappliedUpdates(&trans); | 30 dir->GetServerTypesWithUnappliedUpdates(&trans); |
| 31 } | 31 } |
| 32 | 32 |
| 33 for (syncer::FullModelTypeSet::Iterator it = | 33 for (FullModelTypeSet::Iterator it = |
| 34 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { | 34 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { |
| 35 groups_with_unapplied_updates.insert( | 35 groups_with_unapplied_updates.insert( |
| 36 GetGroupForModelType(it.Get(), session.routing_info())); | 36 GetGroupForModelType(it.Get(), session.routing_info())); |
| 37 } | 37 } |
| 38 | 38 |
| 39 return groups_with_unapplied_updates; | 39 return groups_with_unapplied_updates; |
| 40 } | 40 } |
| 41 | 41 |
| 42 SyncerError ApplyUpdatesCommand::ModelChangingExecuteImpl( | 42 SyncerError ApplyUpdatesCommand::ModelChangingExecuteImpl( |
| 43 SyncSession* session) { | 43 SyncSession* session) { |
| 44 syncable::Directory* dir = session->context()->directory(); | 44 syncable::Directory* dir = session->context()->directory(); |
| 45 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); | 45 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); |
| 46 | 46 |
| 47 // Compute server types with unapplied updates that fall under our | 47 // Compute server types with unapplied updates that fall under our |
| 48 // group restriction. | 48 // group restriction. |
| 49 const syncer::FullModelTypeSet server_types_with_unapplied_updates = | 49 const FullModelTypeSet server_types_with_unapplied_updates = |
| 50 dir->GetServerTypesWithUnappliedUpdates(&trans); | 50 dir->GetServerTypesWithUnappliedUpdates(&trans); |
| 51 syncer::FullModelTypeSet server_type_restriction; | 51 FullModelTypeSet server_type_restriction; |
| 52 for (syncer::FullModelTypeSet::Iterator it = | 52 for (FullModelTypeSet::Iterator it = |
| 53 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { | 53 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { |
| 54 if (GetGroupForModelType(it.Get(), session->routing_info()) == | 54 if (GetGroupForModelType(it.Get(), session->routing_info()) == |
| 55 session->status_controller().group_restriction()) { | 55 session->status_controller().group_restriction()) { |
| 56 server_type_restriction.Put(it.Get()); | 56 server_type_restriction.Put(it.Get()); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::vector<int64> handles; | 60 std::vector<int64> handles; |
| 61 dir->GetUnappliedUpdateMetaHandles( | 61 dir->GetUnappliedUpdateMetaHandles( |
| 62 &trans, server_type_restriction, &handles); | 62 &trans, server_type_restriction, &handles); |
| 63 | 63 |
| 64 UpdateApplicator applicator( | 64 UpdateApplicator applicator( |
| 65 session->context()->resolver(), | 65 session->context()->resolver(), |
| 66 dir->GetCryptographer(&trans), | 66 dir->GetCryptographer(&trans), |
| 67 handles.begin(), handles.end(), session->routing_info(), | 67 handles.begin(), handles.end(), session->routing_info(), |
| 68 session->status_controller().group_restriction()); | 68 session->status_controller().group_restriction()); |
| 69 while (applicator.AttemptOneApplication(&trans)) {} | 69 while (applicator.AttemptOneApplication(&trans)) {} |
| 70 applicator.SaveProgressIntoSessionState( | 70 applicator.SaveProgressIntoSessionState( |
| 71 session->mutable_status_controller()->mutable_conflict_progress(), | 71 session->mutable_status_controller()->mutable_conflict_progress(), |
| 72 session->mutable_status_controller()->mutable_update_progress()); | 72 session->mutable_status_controller()->mutable_update_progress()); |
| 73 | 73 |
| 74 // This might be the first time we've fully completed a sync cycle, for | 74 // This might be the first time we've fully completed a sync cycle, for |
| 75 // some subset of the currently synced datatypes. | 75 // some subset of the currently synced datatypes. |
| 76 const sessions::StatusController& status(session->status_controller()); | 76 const sessions::StatusController& status(session->status_controller()); |
| 77 if (status.ServerSaysNothingMoreToDownload()) { | 77 if (status.ServerSaysNothingMoreToDownload()) { |
| 78 for (syncer::ModelTypeSet::Iterator it = | 78 for (ModelTypeSet::Iterator it = |
| 79 status.updates_request_types().First(); it.Good(); it.Inc()) { | 79 status.updates_request_types().First(); it.Good(); it.Inc()) { |
| 80 // This gets persisted to the directory's backing store. | 80 // This gets persisted to the directory's backing store. |
| 81 dir->set_initial_sync_ended_for_type(it.Get(), true); | 81 dir->set_initial_sync_ended_for_type(it.Get(), true); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 return SYNCER_OK; | 85 return SYNCER_OK; |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace syncer | 88 } // namespace syncer |
| OLD | NEW |