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/get_commit_ids_command.h" | 5 #include "chrome/browser/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 |
11 #include "chrome/browser/sync/engine/nigori_util.h" | |
12 #include "chrome/browser/sync/engine/syncer_util.h" | 11 #include "chrome/browser/sync/engine/syncer_util.h" |
13 #include "chrome/browser/sync/syncable/directory_manager.h" | |
14 #include "chrome/browser/sync/syncable/syncable.h" | 12 #include "chrome/browser/sync/syncable/syncable.h" |
15 #include "chrome/browser/sync/util/cryptographer.h" | |
16 | 13 |
17 using std::set; | 14 using std::set; |
18 using std::vector; | 15 using std::vector; |
19 | 16 |
20 namespace browser_sync { | 17 namespace browser_sync { |
21 | 18 |
22 using sessions::OrderedCommitSet; | 19 using sessions::OrderedCommitSet; |
23 using sessions::SyncSession; | 20 using sessions::SyncSession; |
24 using sessions::StatusController; | 21 using sessions::StatusController; |
25 | 22 |
26 GetCommitIdsCommand::GetCommitIdsCommand(int commit_batch_size) | 23 GetCommitIdsCommand::GetCommitIdsCommand(int commit_batch_size) |
27 : requested_commit_batch_size_(commit_batch_size) {} | 24 : requested_commit_batch_size_(commit_batch_size) {} |
28 | 25 |
29 GetCommitIdsCommand::~GetCommitIdsCommand() {} | 26 GetCommitIdsCommand::~GetCommitIdsCommand() {} |
30 | 27 |
31 void GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { | 28 void GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { |
32 // Gather the full set of unsynced items and store it in the session. They | 29 // Gather the full set of unsynced items and store it in the session. They |
33 // are not in the correct order for commit. | 30 // are not in the correct order for commit. |
34 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; | 31 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; |
35 SyncerUtil::GetUnsyncedEntries(session->write_transaction(), | 32 SyncerUtil::GetUnsyncedEntries(session->write_transaction(), |
36 &all_unsynced_handles); | 33 &all_unsynced_handles); |
37 | |
38 Cryptographer *cryptographer = | |
39 session->context()->directory_manager()->GetCryptographer( | |
40 session->write_transaction()); | |
41 if (cryptographer) { | |
42 FilterEntriesNeedingEncryption(cryptographer->GetEncryptedTypes(), | |
43 session->write_transaction(), | |
44 &all_unsynced_handles); | |
45 } | |
46 StatusController* status = session->status_controller(); | 34 StatusController* status = session->status_controller(); |
47 status->set_unsynced_handles(all_unsynced_handles); | 35 status->set_unsynced_handles(all_unsynced_handles); |
48 | 36 |
49 BuildCommitIds(status->unsynced_handles(), session->write_transaction(), | 37 BuildCommitIds(status->unsynced_handles(), session->write_transaction(), |
50 session->routing_info()); | 38 session->routing_info()); |
51 | 39 |
52 const vector<syncable::Id>& verified_commit_ids = | 40 const vector<syncable::Id>& verified_commit_ids = |
53 ordered_commit_set_->GetAllCommitIds(); | 41 ordered_commit_set_->GetAllCommitIds(); |
54 | 42 |
55 for (size_t i = 0; i < verified_commit_ids.size(); i++) | 43 for (size_t i = 0; i < verified_commit_ids.size(); i++) |
56 VLOG(1) << "Debug commit batch result:" << verified_commit_ids[i]; | 44 VLOG(1) << "Debug commit batch result:" << verified_commit_ids[i]; |
57 | 45 |
58 status->set_commit_set(*ordered_commit_set_.get()); | 46 status->set_commit_set(*ordered_commit_set_.get()); |
59 } | 47 } |
60 | 48 |
61 // We create a new list of unsynced handles which omits all handles to entries | |
62 // that require encryption but are written in plaintext. If any were found we | |
63 // overwrite |unsynced_handles| with this new list, else no change is made. | |
64 // Static. | |
65 void GetCommitIdsCommand::FilterEntriesNeedingEncryption( | |
66 const syncable::ModelTypeSet& encrypted_types, | |
67 syncable::BaseTransaction* trans, | |
68 syncable::Directory::UnsyncedMetaHandles* unsynced_handles) { | |
69 bool removed_handles = false; | |
70 syncable::Directory::UnsyncedMetaHandles::iterator iter; | |
71 syncable::Directory::UnsyncedMetaHandles new_unsynced_handles; | |
72 new_unsynced_handles.reserve(unsynced_handles->size()); | |
73 // TODO(zea): If this becomes a bottleneck, we should merge this loop into the | |
74 // AddCreatesAndMoves and AddDeletes loops. | |
75 for (iter = unsynced_handles->begin(); | |
76 iter != unsynced_handles->end(); | |
77 ++iter) { | |
78 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); | |
79 if (syncable::EntryNeedsEncryption(encrypted_types, entry)) { | |
80 // This entry requires encryption but is not encrypted (possibly due to | |
81 // the cryptographer not being initialized). Don't add it to our new list | |
82 // of unsynced handles. | |
83 removed_handles = true; | |
84 } else { | |
85 new_unsynced_handles.push_back(*iter); | |
86 } | |
87 } | |
88 if (removed_handles) | |
89 *unsynced_handles = new_unsynced_handles; | |
90 } | |
91 | |
92 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( | 49 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( |
93 syncable::BaseTransaction* trans, | 50 syncable::BaseTransaction* trans, |
94 syncable::Id parent_id, | 51 syncable::Id parent_id, |
95 const ModelSafeRoutingInfo& routes) { | 52 const ModelSafeRoutingInfo& routes) { |
96 OrderedCommitSet item_dependencies(routes); | 53 OrderedCommitSet item_dependencies(routes); |
97 | 54 |
98 // Climb the tree adding entries leaf -> root. | 55 // Climb the tree adding entries leaf -> root. |
99 while (!parent_id.ServerKnows()) { | 56 while (!parent_id.ServerKnows()) { |
100 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id); | 57 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id); |
101 CHECK(parent.good()) << "Bad user-only parent in item path."; | 58 CHECK(parent.good()) << "Bad user-only parent in item path."; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // delete trees. | 248 // delete trees. |
292 | 249 |
293 // Add moves and creates, and prepend their uncommitted parents. | 250 // Add moves and creates, and prepend their uncommitted parents. |
294 AddCreatesAndMoves(unsynced_handles, write_transaction, routes); | 251 AddCreatesAndMoves(unsynced_handles, write_transaction, routes); |
295 | 252 |
296 // Add all deletes. | 253 // Add all deletes. |
297 AddDeletes(unsynced_handles, write_transaction); | 254 AddDeletes(unsynced_handles, write_transaction); |
298 } | 255 } |
299 | 256 |
300 } // namespace browser_sync | 257 } // namespace browser_sync |
OLD | NEW |