OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/get_commit_ids_command.h" | 5 #include "sync/engine/get_commit_ids_command.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 using std::vector; | 21 using std::vector; |
22 | 22 |
23 namespace syncer { | 23 namespace syncer { |
24 | 24 |
25 using sessions::OrderedCommitSet; | 25 using sessions::OrderedCommitSet; |
26 using sessions::SyncSession; | 26 using sessions::SyncSession; |
27 using sessions::StatusController; | 27 using sessions::StatusController; |
28 | 28 |
29 GetCommitIdsCommand::GetCommitIdsCommand( | 29 GetCommitIdsCommand::GetCommitIdsCommand( |
30 syncable::BaseTransaction* trans, | 30 syncable::BaseTransaction* trans, |
| 31 ModelTypeSet requested_types, |
31 const size_t commit_batch_size, | 32 const size_t commit_batch_size, |
32 sessions::OrderedCommitSet* commit_set) | 33 sessions::OrderedCommitSet* commit_set) |
33 : trans_(trans), | 34 : trans_(trans), |
| 35 requested_types_(requested_types), |
34 requested_commit_batch_size_(commit_batch_size), | 36 requested_commit_batch_size_(commit_batch_size), |
35 commit_set_(commit_set) { | 37 commit_set_(commit_set) { |
36 } | 38 } |
37 | 39 |
38 GetCommitIdsCommand::~GetCommitIdsCommand() {} | 40 GetCommitIdsCommand::~GetCommitIdsCommand() {} |
39 | 41 |
40 SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { | 42 SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { |
41 // Gather the full set of unsynced items and store it in the session. They | 43 // Gather the full set of unsynced items and store it in the session. They |
42 // are not in the correct order for commit. | 44 // are not in the correct order for commit. |
43 std::set<int64> ready_unsynced_set; | 45 std::set<int64> ready_unsynced_set; |
44 syncable::Directory::Metahandles all_unsynced_handles; | 46 syncable::Directory::Metahandles all_unsynced_handles; |
45 GetUnsyncedEntries(trans_, | 47 GetUnsyncedEntries(trans_, |
46 &all_unsynced_handles); | 48 &all_unsynced_handles); |
47 | 49 |
48 ModelTypeSet encrypted_types; | 50 ModelTypeSet encrypted_types; |
49 bool passphrase_missing = false; | 51 bool passphrase_missing = false; |
50 Cryptographer* cryptographer = | 52 Cryptographer* cryptographer = |
51 session->context()-> | 53 session->context()-> |
52 directory()->GetCryptographer(trans_); | 54 directory()->GetCryptographer(trans_); |
53 if (cryptographer) { | 55 if (cryptographer) { |
54 encrypted_types = session->context()->directory()->GetNigoriHandler()-> | 56 encrypted_types = session->context()->directory()->GetNigoriHandler()-> |
55 GetEncryptedTypes(trans_); | 57 GetEncryptedTypes(trans_); |
56 passphrase_missing = cryptographer->has_pending_keys(); | 58 passphrase_missing = cryptographer->has_pending_keys(); |
57 }; | 59 }; |
58 | 60 |
59 // If we're comitting, then we must be performing a nudge job and must have a | |
60 // session with a nudge tracker. | |
61 DCHECK(session->nudge_tracker()); | |
62 | |
63 // We filter out all unready entries from the set of unsynced handles. This | 61 // We filter out all unready entries from the set of unsynced handles. This |
64 // new set of ready and unsynced items (which excludes throttled items as | 62 // new set of ready and unsynced items is then what we use to determine what |
65 // well) is then what we use to determine what is a candidate for commit. | 63 // is a candidate for commit. The caller of this SyncerCommand is responsible |
| 64 // for ensuring that no throttled types are included among the |
| 65 // requested_types. |
66 FilterUnreadyEntries(trans_, | 66 FilterUnreadyEntries(trans_, |
67 session->nudge_tracker()->GetThrottledTypes(), | 67 requested_types_, |
68 encrypted_types, | 68 encrypted_types, |
69 passphrase_missing, | 69 passphrase_missing, |
70 all_unsynced_handles, | 70 all_unsynced_handles, |
71 &ready_unsynced_set); | 71 &ready_unsynced_set); |
72 | 72 |
73 BuildCommitIds(trans_, | 73 BuildCommitIds(trans_, |
74 session->context()->routing_info(), | 74 session->context()->routing_info(), |
75 ready_unsynced_set); | 75 ready_unsynced_set); |
76 | 76 |
77 const vector<syncable::Id>& verified_commit_ids = | 77 const vector<syncable::Id>& verified_commit_ids = |
(...skipping 22 matching lines...) Expand all Loading... |
100 return false; | 100 return false; |
101 } | 101 } |
102 | 102 |
103 // An entry is not considered ready for commit if any are true: | 103 // An entry is not considered ready for commit if any are true: |
104 // 1. It's in conflict. | 104 // 1. It's in conflict. |
105 // 2. It requires encryption (either the type is encrypted but a passphrase | 105 // 2. It requires encryption (either the type is encrypted but a passphrase |
106 // is missing from the cryptographer, or the entry itself wasn't properly | 106 // is missing from the cryptographer, or the entry itself wasn't properly |
107 // encrypted). | 107 // encrypted). |
108 // 3. It's type is currently throttled. | 108 // 3. It's type is currently throttled. |
109 // 4. It's a delete but has not been committed. | 109 // 4. It's a delete but has not been committed. |
110 bool IsEntryReadyForCommit(ModelTypeSet throttled_types, | 110 bool IsEntryReadyForCommit(ModelTypeSet requested_types, |
111 ModelTypeSet encrypted_types, | 111 ModelTypeSet encrypted_types, |
112 bool passphrase_missing, | 112 bool passphrase_missing, |
113 const syncable::Entry& entry) { | 113 const syncable::Entry& entry) { |
114 DCHECK(entry.Get(syncable::IS_UNSYNCED)); | 114 DCHECK(entry.Get(syncable::IS_UNSYNCED)); |
115 if (IsEntryInConflict(entry)) | 115 if (IsEntryInConflict(entry)) |
116 return false; | 116 return false; |
117 | 117 |
118 const ModelType type = entry.GetModelType(); | 118 const ModelType type = entry.GetModelType(); |
119 // We special case the nigori node because even though it is considered an | 119 // We special case the nigori node because even though it is considered an |
120 // "encrypted type", not all nigori node changes require valid encryption | 120 // "encrypted type", not all nigori node changes require valid encryption |
121 // (ex: sync_tabs). | 121 // (ex: sync_tabs). |
122 if ((type != NIGORI) && encrypted_types.Has(type) && | 122 if ((type != NIGORI) && encrypted_types.Has(type) && |
123 (passphrase_missing || | 123 (passphrase_missing || |
124 syncable::EntryNeedsEncryption(encrypted_types, entry))) { | 124 syncable::EntryNeedsEncryption(encrypted_types, entry))) { |
125 // This entry requires encryption but is not properly encrypted (possibly | 125 // This entry requires encryption but is not properly encrypted (possibly |
126 // due to the cryptographer not being initialized or the user hasn't | 126 // due to the cryptographer not being initialized or the user hasn't |
127 // provided the most recent passphrase). | 127 // provided the most recent passphrase). |
128 DVLOG(1) << "Excluding entry from commit due to lack of encryption " | 128 DVLOG(1) << "Excluding entry from commit due to lack of encryption " |
129 << entry; | 129 << entry; |
130 return false; | 130 return false; |
131 } | 131 } |
132 | 132 |
133 // Look at the throttled types. | 133 // Ignore it if it's not in our set of requested types. |
134 if (throttled_types.Has(type)) | 134 if (!requested_types.Has(type)) |
135 return false; | 135 return false; |
136 | 136 |
137 if (entry.Get(syncable::IS_DEL) && !entry.Get(syncable::ID).ServerKnows()) { | 137 if (entry.Get(syncable::IS_DEL) && !entry.Get(syncable::ID).ServerKnows()) { |
138 // New clients (following the resolution of crbug.com/125381) should not | 138 // New clients (following the resolution of crbug.com/125381) should not |
139 // create such items. Old clients may have left some in the database | 139 // create such items. Old clients may have left some in the database |
140 // (crbug.com/132905), but we should now be cleaning them on startup. | 140 // (crbug.com/132905), but we should now be cleaning them on startup. |
141 NOTREACHED() << "Found deleted and unsynced local item: " << entry; | 141 NOTREACHED() << "Found deleted and unsynced local item: " << entry; |
142 return false; | 142 return false; |
143 } | 143 } |
144 | 144 |
(...skipping 12 matching lines...) Expand all Loading... |
157 } | 157 } |
158 | 158 |
159 DVLOG(2) << "Entry is ready for commit: " << entry; | 159 DVLOG(2) << "Entry is ready for commit: " << entry; |
160 return true; | 160 return true; |
161 } | 161 } |
162 | 162 |
163 } // namespace | 163 } // namespace |
164 | 164 |
165 void GetCommitIdsCommand::FilterUnreadyEntries( | 165 void GetCommitIdsCommand::FilterUnreadyEntries( |
166 syncable::BaseTransaction* trans, | 166 syncable::BaseTransaction* trans, |
167 ModelTypeSet throttled_types, | 167 ModelTypeSet requested_types, |
168 ModelTypeSet encrypted_types, | 168 ModelTypeSet encrypted_types, |
169 bool passphrase_missing, | 169 bool passphrase_missing, |
170 const syncable::Directory::Metahandles& unsynced_handles, | 170 const syncable::Directory::Metahandles& unsynced_handles, |
171 std::set<int64>* ready_unsynced_set) { | 171 std::set<int64>* ready_unsynced_set) { |
172 for (syncable::Directory::Metahandles::const_iterator iter = | 172 for (syncable::Directory::Metahandles::const_iterator iter = |
173 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { | 173 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { |
174 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); | 174 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); |
175 if (IsEntryReadyForCommit(throttled_types, | 175 if (IsEntryReadyForCommit(requested_types, |
176 encrypted_types, | 176 encrypted_types, |
177 passphrase_missing, | 177 passphrase_missing, |
178 entry)) { | 178 entry)) { |
179 ready_unsynced_set->insert(*iter); | 179 ready_unsynced_set->insert(*iter); |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 bool GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( | 184 bool GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( |
185 syncable::BaseTransaction* trans, | 185 syncable::BaseTransaction* trans, |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // delete trees. | 425 // delete trees. |
426 | 426 |
427 // Add moves and creates, and prepend their uncommitted parents. | 427 // Add moves and creates, and prepend their uncommitted parents. |
428 AddCreatesAndMoves(trans, routes, ready_unsynced_set); | 428 AddCreatesAndMoves(trans, routes, ready_unsynced_set); |
429 | 429 |
430 // Add all deletes. | 430 // Add all deletes. |
431 AddDeletes(trans, ready_unsynced_set); | 431 AddDeletes(trans, ready_unsynced_set); |
432 } | 432 } |
433 | 433 |
434 } // namespace syncer | 434 } // namespace syncer |
OLD | NEW |