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

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

Powered by Google App Engine
This is Rietveld 408576698