OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/apply_updates_command.h" | 5 #include "chrome/browser/sync/engine/apply_updates_command.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "chrome/browser/sync/engine/update_applicator.h" | 8 #include "chrome/browser/sync/engine/update_applicator.h" |
9 #include "chrome/browser/sync/sessions/sync_session.h" | 9 #include "chrome/browser/sync/sessions/sync_session.h" |
10 #include "chrome/browser/sync/syncable/directory_manager.h" | 10 #include "chrome/browser/sync/syncable/directory_manager.h" |
11 #include "chrome/browser/sync/syncable/syncable.h" | 11 #include "chrome/browser/sync/syncable/syncable.h" |
12 | 12 |
13 namespace browser_sync { | 13 namespace browser_sync { |
14 | 14 |
15 using sessions::SyncSession; | 15 using sessions::SyncSession; |
16 | 16 |
17 ApplyUpdatesCommand::ApplyUpdatesCommand() {} | 17 ApplyUpdatesCommand::ApplyUpdatesCommand() {} |
18 ApplyUpdatesCommand::~ApplyUpdatesCommand() {} | 18 ApplyUpdatesCommand::~ApplyUpdatesCommand() {} |
19 | 19 |
20 bool ApplyUpdatesCommand::HasCustomGroupsToChange() const { | 20 bool ApplyUpdatesCommand::HasCustomGroupsToChange() const { |
21 return true; | 21 return true; |
22 } | 22 } |
23 | 23 |
24 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange( | 24 std::set<ModelSafeGroup> ApplyUpdatesCommand::GetGroupsToChange( |
25 const sessions::SyncSession& session) const { | 25 const sessions::SyncSession& session) const { |
26 std::set<ModelSafeGroup> groups_with_unapplied_updates; | 26 std::set<ModelSafeGroup> groups_with_unapplied_updates; |
27 | 27 |
28 syncable::ModelTypeBitSet server_types_with_unapplied_updates; | 28 syncable::FullModelEnumSet server_types_with_unapplied_updates; |
29 { | 29 { |
30 syncable::ScopedDirLookup dir(session.context()->directory_manager(), | 30 syncable::ScopedDirLookup dir(session.context()->directory_manager(), |
31 session.context()->account_name()); | 31 session.context()->account_name()); |
32 if (!dir.good()) { | 32 if (!dir.good()) { |
33 LOG(ERROR) << "Scoped dir lookup failed!"; | 33 LOG(ERROR) << "Scoped dir lookup failed!"; |
34 return groups_with_unapplied_updates; | 34 return groups_with_unapplied_updates; |
35 } | 35 } |
36 | 36 |
37 syncable::ReadTransaction trans(FROM_HERE, dir); | 37 syncable::ReadTransaction trans(FROM_HERE, dir); |
38 server_types_with_unapplied_updates = | 38 server_types_with_unapplied_updates = |
39 dir->GetServerTypesWithUnappliedUpdates(&trans); | 39 dir->GetServerTypesWithUnappliedUpdates(&trans); |
40 } | 40 } |
41 | 41 |
42 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 42 for (syncable::FullModelEnumSet::Iterator it = |
43 const syncable::ModelType type = syncable::ModelTypeFromInt(i); | 43 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { |
44 if (server_types_with_unapplied_updates.test(type)) { | 44 groups_with_unapplied_updates.insert( |
45 groups_with_unapplied_updates.insert( | 45 GetGroupForModelType(it.Get(), session.routing_info())); |
46 GetGroupForModelType(type, session.routing_info())); | |
47 } | |
48 } | 46 } |
49 | 47 |
50 return groups_with_unapplied_updates; | 48 return groups_with_unapplied_updates; |
51 } | 49 } |
52 | 50 |
53 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { | 51 void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { |
54 syncable::ScopedDirLookup dir(session->context()->directory_manager(), | 52 syncable::ScopedDirLookup dir(session->context()->directory_manager(), |
55 session->context()->account_name()); | 53 session->context()->account_name()); |
56 if (!dir.good()) { | 54 if (!dir.good()) { |
57 LOG(ERROR) << "Scoped dir lookup failed!"; | 55 LOG(ERROR) << "Scoped dir lookup failed!"; |
58 return; | 56 return; |
59 } | 57 } |
60 | 58 |
61 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); | 59 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); |
62 | 60 |
63 // Compute server types with unapplied updates that fall under our | 61 // Compute server types with unapplied updates that fall under our |
64 // group restriction. | 62 // group restriction. |
65 const syncable::ModelTypeBitSet server_types_with_unapplied_updates = | 63 const syncable::FullModelEnumSet server_types_with_unapplied_updates = |
66 dir->GetServerTypesWithUnappliedUpdates(&trans); | 64 dir->GetServerTypesWithUnappliedUpdates(&trans); |
67 syncable::ModelTypeBitSet server_type_restriction; | 65 syncable::FullModelEnumSet server_type_restriction; |
68 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 66 for (syncable::FullModelEnumSet::Iterator it = |
69 const syncable::ModelType server_type = syncable::ModelTypeFromInt(i); | 67 server_types_with_unapplied_updates.First(); it.Good(); it.Inc()) { |
70 if (server_types_with_unapplied_updates.test(server_type)) { | 68 if (GetGroupForModelType(it.Get(), session->routing_info()) == |
71 if (GetGroupForModelType(server_type, session->routing_info()) == | 69 session->status_controller().group_restriction()) { |
72 session->status_controller().group_restriction()) { | 70 server_type_restriction.Put(it.Get()); |
73 server_type_restriction.set(server_type); | |
74 } | |
75 } | 71 } |
76 } | 72 } |
77 | 73 |
78 syncable::Directory::UnappliedUpdateMetaHandles handles; | 74 syncable::Directory::UnappliedUpdateMetaHandles handles; |
79 dir->GetUnappliedUpdateMetaHandles( | 75 dir->GetUnappliedUpdateMetaHandles( |
80 &trans, server_type_restriction, &handles); | 76 &trans, server_type_restriction, &handles); |
81 | 77 |
82 UpdateApplicator applicator( | 78 UpdateApplicator applicator( |
83 session->context()->resolver(), | 79 session->context()->resolver(), |
84 session->context()->directory_manager()->GetCryptographer(&trans), | 80 session->context()->directory_manager()->GetCryptographer(&trans), |
(...skipping 10 matching lines...) Expand all Loading... |
95 if (status.ServerSaysNothingMoreToDownload()) { | 91 if (status.ServerSaysNothingMoreToDownload()) { |
96 for (syncable::ModelEnumSet::Iterator it = | 92 for (syncable::ModelEnumSet::Iterator it = |
97 status.updates_request_types().First(); it.Good(); it.Inc()) { | 93 status.updates_request_types().First(); it.Good(); it.Inc()) { |
98 // This gets persisted to the directory's backing store. | 94 // This gets persisted to the directory's backing store. |
99 dir->set_initial_sync_ended_for_type(it.Get(), true); | 95 dir->set_initial_sync_ended_for_type(it.Get(), true); |
100 } | 96 } |
101 } | 97 } |
102 } | 98 } |
103 | 99 |
104 } // namespace browser_sync | 100 } // namespace browser_sync |
OLD | NEW |