Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: sync/engine/apply_updates_command.cc

Issue 11192071: sync: Merge apply updates and resolve conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry (base files were missing) Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/apply_updates_command.h ('k') | sync/engine/apply_updates_command_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "sync/engine/apply_updates_command.h"
6
7 #include "base/location.h"
8 #include "sync/engine/update_applicator.h"
9 #include "sync/sessions/sync_session.h"
10 #include "sync/syncable/directory.h"
11 #include "sync/syncable/read_transaction.h"
12 #include "sync/syncable/write_transaction.h"
13
14 namespace syncer {
15
16 using sessions::SyncSession;
17
18 ApplyUpdatesCommand::ApplyUpdatesCommand() {}
19 ApplyUpdatesCommand::~ApplyUpdatesCommand() {}
20
21 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange(
22 const sessions::SyncSession& session) const {
23 std::set<ModelSafeGroup> groups_with_unapplied_updates;
24
25 FullModelTypeSet server_types_with_unapplied_updates;
26 {
27 syncable::Directory* dir = session.context()->directory();
28 syncable::ReadTransaction trans(FROM_HERE, dir);
29 server_types_with_unapplied_updates =
30 dir->GetServerTypesWithUnappliedUpdates(&trans);
31 }
32
33 for (FullModelTypeSet::Iterator it =
34 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) {
35 groups_with_unapplied_updates.insert(
36 GetGroupForModelType(it.Get(), session.routing_info()));
37 }
38
39 return groups_with_unapplied_updates;
40 }
41
42 SyncerError ApplyUpdatesCommand::ModelChangingExecuteImpl(
43 SyncSession* session) {
44 syncable::Directory* dir = session->context()->directory();
45 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
46
47 // Compute server types with unapplied updates that fall under our
48 // group restriction.
49 const FullModelTypeSet server_types_with_unapplied_updates =
50 dir->GetServerTypesWithUnappliedUpdates(&trans);
51 FullModelTypeSet server_type_restriction;
52 for (FullModelTypeSet::Iterator it =
53 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) {
54 if (GetGroupForModelType(it.Get(), session->routing_info()) ==
55 session->status_controller().group_restriction()) {
56 server_type_restriction.Put(it.Get());
57 }
58 }
59
60 // Don't process control type updates here. They will be handled elsewhere.
61 FullModelTypeSet control_types = ToFullModelTypeSet(ControlTypes());
62 server_type_restriction.RemoveAll(control_types);
63
64 std::vector<int64> handles;
65 dir->GetUnappliedUpdateMetaHandles(
66 &trans, server_type_restriction, &handles);
67
68 UpdateApplicator applicator(
69 dir->GetCryptographer(&trans),
70 session->routing_info(),
71 session->status_controller().group_restriction());
72 applicator.AttemptApplications(&trans, handles,
73 session->mutable_status_controller());
74
75 // This might be the first time we've fully completed a sync cycle, for
76 // some subset of the currently synced datatypes.
77 const sessions::StatusController& status(session->status_controller());
78 if (status.ServerSaysNothingMoreToDownload()) {
79 for (ModelTypeSet::Iterator it =
80 status.updates_request_types().First(); it.Good(); it.Inc()) {
81 // Don't set the flag for control types. We didn't process them here.
82 if (IsControlType(it.Get()))
83 continue;
84
85 // This gets persisted to the directory's backing store.
86 dir->set_initial_sync_ended_for_type(it.Get(), true);
87 }
88 }
89
90 return SYNCER_OK;
91 }
92
93 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/apply_updates_command.h ('k') | sync/engine/apply_updates_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698