| 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/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "sync/syncable/on_disk_directory_backing_store.h" | 49 #include "sync/syncable/on_disk_directory_backing_store.h" |
| 50 | 50 |
| 51 using base::TimeDelta; | 51 using base::TimeDelta; |
| 52 using sync_pb::GetUpdatesCallerInfo; | 52 using sync_pb::GetUpdatesCallerInfo; |
| 53 | 53 |
| 54 namespace syncer { | 54 namespace syncer { |
| 55 | 55 |
| 56 using sessions::SyncSessionContext; | 56 using sessions::SyncSessionContext; |
| 57 using syncable::ImmutableWriteTransactionInfo; | 57 using syncable::ImmutableWriteTransactionInfo; |
| 58 using syncable::SPECIFICS; | 58 using syncable::SPECIFICS; |
| 59 using syncable::UNIQUE_POSITION; |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 // Delays for syncer nudges. | 63 // Delays for syncer nudges. |
| 63 static const int kDefaultNudgeDelayMilliseconds = 200; | 64 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 64 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 65 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 65 static const int kSyncRefreshDelayMsec = 500; | 66 static const int kSyncRefreshDelayMsec = 500; |
| 66 static const int kSyncSchedulerDelayMsec = 250; | 67 static const int kSyncSchedulerDelayMsec = 250; |
| 67 | 68 |
| 68 // Maximum count and size for traffic recorder. | 69 // Maximum count and size for traffic recorder. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} | 215 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} |
| 215 SyncManagerImpl::NotificationInfo::~NotificationInfo() {} | 216 SyncManagerImpl::NotificationInfo::~NotificationInfo() {} |
| 216 | 217 |
| 217 DictionaryValue* SyncManagerImpl::NotificationInfo::ToValue() const { | 218 DictionaryValue* SyncManagerImpl::NotificationInfo::ToValue() const { |
| 218 DictionaryValue* value = new DictionaryValue(); | 219 DictionaryValue* value = new DictionaryValue(); |
| 219 value->SetInteger("totalCount", total_count); | 220 value->SetInteger("totalCount", total_count); |
| 220 value->SetString("payload", payload); | 221 value->SetString("payload", payload); |
| 221 return value; | 222 return value; |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool SyncManagerImpl::VisiblePositionsDiffer( | |
| 225 const syncable::EntryKernelMutation& mutation) const { | |
| 226 const syncable::EntryKernel& a = mutation.original; | |
| 227 const syncable::EntryKernel& b = mutation.mutated; | |
| 228 // If the datatype isn't one where the browser model cares about position, | |
| 229 // don't bother notifying that data model of position-only changes. | |
| 230 if (!ShouldMaintainPosition(GetModelTypeFromSpecifics(b.ref(SPECIFICS)))) { | |
| 231 return false; | |
| 232 } | |
| 233 if (a.ref(syncable::NEXT_ID) != b.ref(syncable::NEXT_ID)) | |
| 234 return true; | |
| 235 if (a.ref(syncable::PARENT_ID) != b.ref(syncable::PARENT_ID)) | |
| 236 return true; | |
| 237 return false; | |
| 238 } | |
| 239 | |
| 240 bool SyncManagerImpl::VisiblePropertiesDiffer( | 225 bool SyncManagerImpl::VisiblePropertiesDiffer( |
| 241 const syncable::EntryKernelMutation& mutation, | 226 const syncable::EntryKernelMutation& mutation, |
| 242 Cryptographer* cryptographer) const { | 227 Cryptographer* cryptographer) const { |
| 243 const syncable::EntryKernel& a = mutation.original; | 228 const syncable::EntryKernel& a = mutation.original; |
| 244 const syncable::EntryKernel& b = mutation.mutated; | 229 const syncable::EntryKernel& b = mutation.mutated; |
| 245 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); | 230 const sync_pb::EntitySpecifics& a_specifics = a.ref(SPECIFICS); |
| 246 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); | 231 const sync_pb::EntitySpecifics& b_specifics = b.ref(SPECIFICS); |
| 247 DCHECK_EQ(GetModelTypeFromSpecifics(a_specifics), | 232 DCHECK_EQ(GetModelTypeFromSpecifics(a_specifics), |
| 248 GetModelTypeFromSpecifics(b_specifics)); | 233 GetModelTypeFromSpecifics(b_specifics)); |
| 249 ModelType model_type = GetModelTypeFromSpecifics(b_specifics); | 234 ModelType model_type = GetModelTypeFromSpecifics(b_specifics); |
| 250 // Suppress updates to items that aren't tracked by any browser model. | 235 // Suppress updates to items that aren't tracked by any browser model. |
| 251 if (model_type < FIRST_REAL_MODEL_TYPE || | 236 if (model_type < FIRST_REAL_MODEL_TYPE || |
| 252 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { | 237 !a.ref(syncable::UNIQUE_SERVER_TAG).empty()) { |
| 253 return false; | 238 return false; |
| 254 } | 239 } |
| 255 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) | 240 if (a.ref(syncable::IS_DIR) != b.ref(syncable::IS_DIR)) |
| 256 return true; | 241 return true; |
| 257 if (!AreSpecificsEqual(cryptographer, | 242 if (!AreSpecificsEqual(cryptographer, |
| 258 a.ref(syncable::SPECIFICS), | 243 a.ref(syncable::SPECIFICS), |
| 259 b.ref(syncable::SPECIFICS))) { | 244 b.ref(syncable::SPECIFICS))) { |
| 260 return true; | 245 return true; |
| 261 } | 246 } |
| 262 // We only care if the name has changed if neither specifics is encrypted | 247 // We only care if the name has changed if neither specifics is encrypted |
| 263 // (encrypted nodes blow away the NON_UNIQUE_NAME). | 248 // (encrypted nodes blow away the NON_UNIQUE_NAME). |
| 264 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && | 249 if (!a_specifics.has_encrypted() && !b_specifics.has_encrypted() && |
| 265 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) | 250 a.ref(syncable::NON_UNIQUE_NAME) != b.ref(syncable::NON_UNIQUE_NAME)) |
| 266 return true; | 251 return true; |
| 267 if (VisiblePositionsDiffer(mutation)) | 252 if (!a.ref(UNIQUE_POSITION).Equals(b.ref(UNIQUE_POSITION))) |
| 268 return true; | 253 return true; |
| 269 return false; | 254 return false; |
| 270 } | 255 } |
| 271 | 256 |
| 272 void SyncManagerImpl::ThrowUnrecoverableError() { | 257 void SyncManagerImpl::ThrowUnrecoverableError() { |
| 273 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 274 ReadTransaction trans(FROM_HERE, GetUserShare()); | 259 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 275 trans.GetWrappedTrans()->OnUnrecoverableError( | 260 trans.GetWrappedTrans()->OnUnrecoverableError( |
| 276 FROM_HERE, "Simulating unrecoverable error for testing purposes."); | 261 FROM_HERE, "Simulating unrecoverable error for testing purposes."); |
| 277 } | 262 } |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 880 |
| 896 ChangeReorderBuffer change_buffers[MODEL_TYPE_COUNT]; | 881 ChangeReorderBuffer change_buffers[MODEL_TYPE_COUNT]; |
| 897 | 882 |
| 898 Cryptographer* crypto = directory()->GetCryptographer(trans); | 883 Cryptographer* crypto = directory()->GetCryptographer(trans); |
| 899 const syncable::ImmutableEntryKernelMutationMap& mutations = | 884 const syncable::ImmutableEntryKernelMutationMap& mutations = |
| 900 write_transaction_info.Get().mutations; | 885 write_transaction_info.Get().mutations; |
| 901 for (syncable::EntryKernelMutationMap::const_iterator it = | 886 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 902 mutations.Get().begin(); it != mutations.Get().end(); ++it) { | 887 mutations.Get().begin(); it != mutations.Get().end(); ++it) { |
| 903 bool existed_before = !it->second.original.ref(syncable::IS_DEL); | 888 bool existed_before = !it->second.original.ref(syncable::IS_DEL); |
| 904 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); | 889 bool exists_now = !it->second.mutated.ref(syncable::IS_DEL); |
| 890 bool positions_differ = !it->second.original.ref(UNIQUE_POSITION).Equals( |
| 891 it->second.mutated.ref(UNIQUE_POSITION)); |
| 905 | 892 |
| 906 // Omit items that aren't associated with a model. | 893 // Omit items that aren't associated with a model. |
| 907 ModelType type = | 894 ModelType type = |
| 908 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); | 895 GetModelTypeFromSpecifics(it->second.mutated.ref(SPECIFICS)); |
| 909 if (type < FIRST_REAL_MODEL_TYPE) | 896 if (type < FIRST_REAL_MODEL_TYPE) |
| 910 continue; | 897 continue; |
| 911 | 898 |
| 912 int64 handle = it->first; | 899 int64 handle = it->first; |
| 913 if (exists_now && !existed_before) | 900 if (exists_now && !existed_before) |
| 914 change_buffers[type].PushAddedItem(handle); | 901 change_buffers[type].PushAddedItem(handle); |
| 915 else if (!exists_now && existed_before) | 902 else if (!exists_now && existed_before) |
| 916 change_buffers[type].PushDeletedItem(handle); | 903 change_buffers[type].PushDeletedItem(handle); |
| 917 else if (exists_now && existed_before && | 904 else if (exists_now && existed_before && |
| 918 VisiblePropertiesDiffer(it->second, crypto)) { | 905 VisiblePropertiesDiffer(it->second, crypto)) { |
| 919 change_buffers[type].PushUpdatedItem( | 906 change_buffers[type].PushUpdatedItem( |
| 920 handle, VisiblePositionsDiffer(it->second)); | 907 handle, positions_differ); |
| 921 } | 908 } |
| 922 | 909 |
| 923 SetExtraChangeRecordData(handle, type, &change_buffers[type], crypto, | 910 SetExtraChangeRecordData(handle, type, &change_buffers[type], crypto, |
| 924 it->second.original, existed_before, exists_now); | 911 it->second.original, existed_before, exists_now); |
| 925 } | 912 } |
| 926 | 913 |
| 927 ReadTransaction read_trans(GetUserShare(), trans); | 914 ReadTransaction read_trans(GetUserShare(), trans); |
| 928 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 915 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 929 if (!change_buffers[i].IsEmpty()) { | 916 if (!change_buffers[i].IsEmpty()) { |
| 930 if (change_buffers[i].GetAllChangesInTreeOrder(&read_trans, | 917 if (change_buffers[i].GetAllChangesInTreeOrder(&read_trans, |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1343 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1357 return kDefaultNudgeDelayMilliseconds; | 1344 return kDefaultNudgeDelayMilliseconds; |
| 1358 } | 1345 } |
| 1359 | 1346 |
| 1360 // static. | 1347 // static. |
| 1361 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1348 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1362 return kPreferencesNudgeDelayMilliseconds; | 1349 return kPreferencesNudgeDelayMilliseconds; |
| 1363 } | 1350 } |
| 1364 | 1351 |
| 1365 } // namespace syncer | 1352 } // namespace syncer |
| OLD | NEW |