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