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

Side by Side Diff: chrome/browser/sync/engine/get_commit_ids_command.cc

Issue 7795002: [Sync] Gracefully handle writing to a node when the cryptographer is not ready. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments Created 9 years, 3 months 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
OLDNEW
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"
11 #include "chrome/browser/sync/engine/syncer_util.h" 12 #include "chrome/browser/sync/engine/syncer_util.h"
13 #include "chrome/browser/sync/syncable/directory_manager.h"
12 #include "chrome/browser/sync/syncable/syncable.h" 14 #include "chrome/browser/sync/syncable/syncable.h"
15 #include "chrome/browser/sync/util/cryptographer.h"
13 16
14 using std::set; 17 using std::set;
15 using std::vector; 18 using std::vector;
16 19
17 namespace browser_sync { 20 namespace browser_sync {
18 21
19 using sessions::OrderedCommitSet; 22 using sessions::OrderedCommitSet;
20 using sessions::SyncSession; 23 using sessions::SyncSession;
21 using sessions::StatusController; 24 using sessions::StatusController;
22 25
23 GetCommitIdsCommand::GetCommitIdsCommand(int commit_batch_size) 26 GetCommitIdsCommand::GetCommitIdsCommand(int commit_batch_size)
24 : requested_commit_batch_size_(commit_batch_size) {} 27 : requested_commit_batch_size_(commit_batch_size) {}
25 28
26 GetCommitIdsCommand::~GetCommitIdsCommand() {} 29 GetCommitIdsCommand::~GetCommitIdsCommand() {}
27 30
28 void GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { 31 void GetCommitIdsCommand::ExecuteImpl(SyncSession* session) {
29 // Gather the full set of unsynced items and store it in the session. They 32 // Gather the full set of unsynced items and store it in the session. They
30 // are not in the correct order for commit. 33 // are not in the correct order for commit.
31 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; 34 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles;
32 SyncerUtil::GetUnsyncedEntries(session->write_transaction(), 35 SyncerUtil::GetUnsyncedEntries(session->write_transaction(),
33 &all_unsynced_handles); 36 &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 }
34 StatusController* status = session->status_controller(); 46 StatusController* status = session->status_controller();
35 status->set_unsynced_handles(all_unsynced_handles); 47 status->set_unsynced_handles(all_unsynced_handles);
36 48
37 BuildCommitIds(status->unsynced_handles(), session->write_transaction(), 49 BuildCommitIds(status->unsynced_handles(), session->write_transaction(),
38 session->routing_info()); 50 session->routing_info());
39 51
40 const vector<syncable::Id>& verified_commit_ids = 52 const vector<syncable::Id>& verified_commit_ids =
41 ordered_commit_set_->GetAllCommitIds(); 53 ordered_commit_set_->GetAllCommitIds();
42 54
43 for (size_t i = 0; i < verified_commit_ids.size(); i++) 55 for (size_t i = 0; i < verified_commit_ids.size(); i++)
44 VLOG(1) << "Debug commit batch result:" << verified_commit_ids[i]; 56 VLOG(1) << "Debug commit batch result:" << verified_commit_ids[i];
45 57
46 status->set_commit_set(*ordered_commit_set_.get()); 58 status->set_commit_set(*ordered_commit_set_.get());
47 } 59 }
48 60
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
49 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( 92 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors(
50 syncable::BaseTransaction* trans, 93 syncable::BaseTransaction* trans,
51 syncable::Id parent_id, 94 syncable::Id parent_id,
52 const ModelSafeRoutingInfo& routes) { 95 const ModelSafeRoutingInfo& routes) {
53 OrderedCommitSet item_dependencies(routes); 96 OrderedCommitSet item_dependencies(routes);
54 97
55 // Climb the tree adding entries leaf -> root. 98 // Climb the tree adding entries leaf -> root.
56 while (!parent_id.ServerKnows()) { 99 while (!parent_id.ServerKnows()) {
57 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id); 100 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id);
58 CHECK(parent.good()) << "Bad user-only parent in item path."; 101 CHECK(parent.good()) << "Bad user-only parent in item path.";
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // delete trees. 291 // delete trees.
249 292
250 // Add moves and creates, and prepend their uncommitted parents. 293 // Add moves and creates, and prepend their uncommitted parents.
251 AddCreatesAndMoves(unsynced_handles, write_transaction, routes); 294 AddCreatesAndMoves(unsynced_handles, write_transaction, routes);
252 295
253 // Add all deletes. 296 // Add all deletes.
254 AddDeletes(unsynced_handles, write_transaction); 297 AddDeletes(unsynced_handles, write_transaction);
255 } 298 }
256 299
257 } // namespace browser_sync 300 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/get_commit_ids_command.h ('k') | chrome/browser/sync/engine/nigori_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698