| OLD | NEW |
| 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 Loading... |
| 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 syncer::ModelTypeSet encrypted_types; | 46 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 syncer::ModelTypeSet throttled_types = | 56 const 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 Loading... |
| 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(syncer::ModelTypeSet throttled_types, | 105 bool IsEntryReadyForCommit(ModelTypeSet throttled_types, |
| 106 syncer::ModelTypeSet encrypted_types, | 106 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 syncer::ModelType type = entry.GetModelType(); | 113 const 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 != syncer::NIGORI) && encrypted_types.Has(type) && | 117 if ((type != NIGORI) && encrypted_types.Has(type) && |
| 118 (passphrase_missing || | 118 (passphrase_missing || |
| 119 syncable::EntryNeedsEncryption(encrypted_types, entry))) { | 119 syncable::EntryNeedsEncryption(encrypted_types, entry))) { |
| 120 // This entry requires encryption but is not properly encrypted (possibly | 120 // This entry requires encryption but is not properly encrypted (possibly |
| 121 // due to the cryptographer not being initialized or the user hasn't | 121 // due to the cryptographer not being initialized or the user hasn't |
| 122 // provided the most recent passphrase). | 122 // provided the most recent passphrase). |
| 123 DVLOG(1) << "Excluding entry from commit due to lack of encryption " | 123 DVLOG(1) << "Excluding entry from commit due to lack of encryption " |
| 124 << entry; | 124 << entry; |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 DVLOG(2) << "Entry is ready for commit: " << entry; | 154 DVLOG(2) << "Entry is ready for commit: " << entry; |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| 159 | 159 |
| 160 void GetCommitIdsCommand::FilterUnreadyEntries( | 160 void GetCommitIdsCommand::FilterUnreadyEntries( |
| 161 syncable::BaseTransaction* trans, | 161 syncable::BaseTransaction* trans, |
| 162 syncer::ModelTypeSet throttled_types, | 162 ModelTypeSet throttled_types, |
| 163 syncer::ModelTypeSet encrypted_types, | 163 ModelTypeSet encrypted_types, |
| 164 bool passphrase_missing, | 164 bool passphrase_missing, |
| 165 const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, | 165 const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, |
| 166 std::set<int64>* ready_unsynced_set) { | 166 std::set<int64>* ready_unsynced_set) { |
| 167 for (syncable::Directory::UnsyncedMetaHandles::const_iterator iter = | 167 for (syncable::Directory::UnsyncedMetaHandles::const_iterator iter = |
| 168 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { | 168 unsynced_handles.begin(); iter != unsynced_handles.end(); ++iter) { |
| 169 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); | 169 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); |
| 170 if (IsEntryReadyForCommit(throttled_types, | 170 if (IsEntryReadyForCommit(throttled_types, |
| 171 encrypted_types, | 171 encrypted_types, |
| 172 passphrase_missing, | 172 passphrase_missing, |
| 173 entry)) { | 173 entry)) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // delete trees. | 426 // delete trees. |
| 427 | 427 |
| 428 // Add moves and creates, and prepend their uncommitted parents. | 428 // Add moves and creates, and prepend their uncommitted parents. |
| 429 AddCreatesAndMoves(write_transaction, routes, ready_unsynced_set); | 429 AddCreatesAndMoves(write_transaction, routes, ready_unsynced_set); |
| 430 | 430 |
| 431 // Add all deletes. | 431 // Add all deletes. |
| 432 AddDeletes(write_transaction, ready_unsynced_set); | 432 AddDeletes(write_transaction, ready_unsynced_set); |
| 433 } | 433 } |
| 434 | 434 |
| 435 } // namespace syncer | 435 } // namespace syncer |
| OLD | NEW |