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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent, and remove some redundant using declarations Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 25 matching lines...) Expand all
36 GetCommitIdsCommand::~GetCommitIdsCommand() {} 36 GetCommitIdsCommand::~GetCommitIdsCommand() {}
37 37
38 SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { 38 SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) {
39 // Gather the full set of unsynced items and store it in the session. They 39 // Gather the full set of unsynced items and store it in the session. They
40 // are not in the correct order for commit. 40 // are not in the correct order for commit.
41 std::set<int64> ready_unsynced_set; 41 std::set<int64> ready_unsynced_set;
42 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles; 42 syncable::Directory::UnsyncedMetaHandles all_unsynced_handles;
43 GetUnsyncedEntries(session->write_transaction(), 43 GetUnsyncedEntries(session->write_transaction(),
44 &all_unsynced_handles); 44 &all_unsynced_handles);
45 45
46 syncable::ModelTypeSet encrypted_types; 46 syncer::ModelTypeSet encrypted_types;
47 bool passphrase_missing = false; 47 bool passphrase_missing = false;
48 Cryptographer* cryptographer = 48 Cryptographer* cryptographer =
49 session->context()-> 49 session->context()->
50 directory()->GetCryptographer(session->write_transaction()); 50 directory()->GetCryptographer(session->write_transaction());
51 if (cryptographer) { 51 if (cryptographer) {
52 encrypted_types = cryptographer->GetEncryptedTypes(); 52 encrypted_types = cryptographer->GetEncryptedTypes();
53 passphrase_missing = cryptographer->has_pending_keys(); 53 passphrase_missing = cryptographer->has_pending_keys();
54 }; 54 };
55 55
56 const syncable::ModelTypeSet throttled_types = 56 const syncer::ModelTypeSet throttled_types =
57 session->context()->throttled_data_type_tracker()->GetThrottledTypes(); 57 session->context()->throttled_data_type_tracker()->GetThrottledTypes();
58 // We filter out all unready entries from the set of unsynced handles. This 58 // We filter out all unready entries from the set of unsynced handles. This
59 // new set of ready and unsynced items (which excludes throttled items as 59 // new set of ready and unsynced items (which excludes throttled items as
60 // well) is then what we use to determine what is a candidate for commit. 60 // well) is then what we use to determine what is a candidate for commit.
61 FilterUnreadyEntries(session->write_transaction(), 61 FilterUnreadyEntries(session->write_transaction(),
62 throttled_types, 62 throttled_types,
63 encrypted_types, 63 encrypted_types,
64 passphrase_missing, 64 passphrase_missing,
65 all_unsynced_handles, 65 all_unsynced_handles,
66 &ready_unsynced_set); 66 &ready_unsynced_set);
(...skipping 28 matching lines...) Expand all
95 return false; 95 return false;
96 } 96 }
97 97
98 // An entry is not considered ready for commit if any are true: 98 // An entry is not considered ready for commit if any are true:
99 // 1. It's in conflict. 99 // 1. It's in conflict.
100 // 2. It requires encryption (either the type is encrypted but a passphrase 100 // 2. It requires encryption (either the type is encrypted but a passphrase
101 // is missing from the cryptographer, or the entry itself wasn't properly 101 // is missing from the cryptographer, or the entry itself wasn't properly
102 // encrypted). 102 // encrypted).
103 // 3. It's type is currently throttled. 103 // 3. It's type is currently throttled.
104 // 4. It's a delete but has not been committed. 104 // 4. It's a delete but has not been committed.
105 bool IsEntryReadyForCommit(syncable::ModelTypeSet throttled_types, 105 bool IsEntryReadyForCommit(syncer::ModelTypeSet throttled_types,
106 syncable::ModelTypeSet encrypted_types, 106 syncer::ModelTypeSet encrypted_types,
107 bool passphrase_missing, 107 bool passphrase_missing,
108 const syncable::Entry& entry) { 108 const syncable::Entry& entry) {
109 DCHECK(entry.Get(syncable::IS_UNSYNCED)); 109 DCHECK(entry.Get(syncable::IS_UNSYNCED));
110 if (IsEntryInConflict(entry)) 110 if (IsEntryInConflict(entry))
111 return false; 111 return false;
112 112
113 const syncable::ModelType type = entry.GetModelType(); 113 const syncer::ModelType type = entry.GetModelType();
114 // We special case the nigori node because even though it is considered an 114 // We special case the nigori node because even though it is considered an
115 // "encrypted type", not all nigori node changes require valid encryption 115 // "encrypted type", not all nigori node changes require valid encryption
116 // (ex: sync_tabs). 116 // (ex: sync_tabs).
117 if ((type != syncable::NIGORI) && 117 if ((type != syncer::NIGORI) &&
118 encrypted_types.Has(type) && 118 encrypted_types.Has(type) &&
119 (passphrase_missing || 119 (passphrase_missing ||
120 syncable::EntryNeedsEncryption(encrypted_types, entry))) { 120 syncable::EntryNeedsEncryption(encrypted_types, entry))) {
121 // This entry requires encryption but is not properly encrypted (possibly 121 // This entry requires encryption but is not properly encrypted (possibly
122 // due to the cryptographer not being initialized or the user hasn't 122 // due to the cryptographer not being initialized or the user hasn't
123 // provided the most recent passphrase). 123 // provided the most recent passphrase).
124 DVLOG(1) << "Excluding entry from commit due to lack of encryption " 124 DVLOG(1) << "Excluding entry from commit due to lack of encryption "
125 << entry; 125 << entry;
126 return false; 126 return false;
127 } 127 }
(...skipping 25 matching lines...) Expand all
153 } 153 }
154 154
155 DVLOG(2) << "Entry is ready for commit: " << entry; 155 DVLOG(2) << "Entry is ready for commit: " << entry;
156 return true; 156 return true;
157 } 157 }
158 158
159 } // namespace 159 } // namespace
160 160
161 void GetCommitIdsCommand::FilterUnreadyEntries( 161 void GetCommitIdsCommand::FilterUnreadyEntries(
162 syncable::BaseTransaction* trans, 162 syncable::BaseTransaction* trans,
163 syncable::ModelTypeSet throttled_types, 163 syncer::ModelTypeSet throttled_types,
164 syncable::ModelTypeSet encrypted_types, 164 syncer::ModelTypeSet encrypted_types,
165 bool passphrase_missing, 165 bool passphrase_missing,
166 const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, 166 const syncable::Directory::UnsyncedMetaHandles& unsynced_handles,
167 std::set<int64>* ready_unsynced_set) { 167 std::set<int64>* ready_unsynced_set) {
168 for (syncable::Directory::UnsyncedMetaHandles::const_iterator iter = 168 for (syncable::Directory::UnsyncedMetaHandles::const_iterator iter =
169 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { 169 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) {
170 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); 170 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter);
171 if (IsEntryReadyForCommit(throttled_types, 171 if (IsEntryReadyForCommit(throttled_types,
172 encrypted_types, 172 encrypted_types,
173 passphrase_missing, 173 passphrase_missing,
174 entry)) { 174 entry)) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // delete trees. 427 // delete trees.
428 428
429 // Add moves and creates, and prepend their uncommitted parents. 429 // Add moves and creates, and prepend their uncommitted parents.
430 AddCreatesAndMoves(write_transaction, routes, ready_unsynced_set); 430 AddCreatesAndMoves(write_transaction, routes, ready_unsynced_set);
431 431
432 // Add all deletes. 432 // Add all deletes.
433 AddDeletes(write_transaction, ready_unsynced_set); 433 AddDeletes(write_transaction, ready_unsynced_set);
434 } 434 }
435 435
436 } // namespace syncer 436 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698