| OLD | NEW |
| 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/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 static const InvariantCheckLevel kInvariantCheckLevel = VERIFY_IN_MEMORY; | 64 static const InvariantCheckLevel kInvariantCheckLevel = VERIFY_IN_MEMORY; |
| 65 | 65 |
| 66 // Max number of milliseconds to spend checking syncable entry invariants | 66 // Max number of milliseconds to spend checking syncable entry invariants |
| 67 static const int kInvariantCheckMaxMs = 50; | 67 static const int kInvariantCheckMaxMs = 50; |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 using std::string; | 70 using std::string; |
| 71 | 71 |
| 72 | |
| 73 namespace syncable { | 72 namespace syncable { |
| 74 | 73 |
| 75 #define ENUM_CASE(x) case x: return #x; break | 74 #define ENUM_CASE(x) case x: return #x; break |
| 76 | 75 |
| 77 std::string WriterTagToString(WriterTag writer_tag) { | 76 std::string WriterTagToString(WriterTag writer_tag) { |
| 78 switch (writer_tag) { | 77 switch (writer_tag) { |
| 79 ENUM_CASE(INVALID); | 78 ENUM_CASE(INVALID); |
| 80 ENUM_CASE(SYNCER); | 79 ENUM_CASE(SYNCER); |
| 81 ENUM_CASE(AUTHWATCHER); | 80 ENUM_CASE(AUTHWATCHER); |
| 82 ENUM_CASE(UNITTEST); | 81 ENUM_CASE(UNITTEST); |
| 83 ENUM_CASE(VACUUM_AFTER_SAVE); | 82 ENUM_CASE(VACUUM_AFTER_SAVE); |
| 84 ENUM_CASE(PURGE_ENTRIES); | 83 ENUM_CASE(PURGE_ENTRIES); |
| 85 ENUM_CASE(SYNCAPI); | 84 ENUM_CASE(SYNCAPI); |
| 86 }; | 85 }; |
| 87 NOTREACHED(); | 86 NOTREACHED(); |
| 88 return ""; | 87 return ""; |
| 89 } | 88 } |
| 90 | 89 |
| 91 #undef ENUM_CASE | 90 #undef ENUM_CASE |
| 92 | 91 |
| 93 namespace { | 92 WriteTransactionInfo::WriteTransactionInfo( |
| 93 int64 id, |
| 94 tracked_objects::Location location, |
| 95 WriterTag writer, |
| 96 ImmutableEntryKernelMutationMap mutations) |
| 97 : id(id), |
| 98 location_string(location.ToString()), |
| 99 writer(writer), |
| 100 mutations(mutations) {} |
| 101 |
| 102 WriteTransactionInfo::WriteTransactionInfo() |
| 103 : id(-1), writer(INVALID) {} |
| 104 |
| 105 WriteTransactionInfo::~WriteTransactionInfo() {} |
| 106 |
| 107 base::DictionaryValue* WriteTransactionInfo::ToValue( |
| 108 size_t max_mutations_size) const { |
| 109 DictionaryValue* dict = new DictionaryValue(); |
| 110 dict->SetString("id", base::Int64ToString(id)); |
| 111 dict->SetString("location", location_string); |
| 112 dict->SetString("writer", WriterTagToString(writer)); |
| 113 Value* mutations_value = NULL; |
| 114 const size_t mutations_size = mutations.Get().size(); |
| 115 if (mutations_size <= max_mutations_size) { |
| 116 mutations_value = EntryKernelMutationMapToValue(mutations.Get()); |
| 117 } else { |
| 118 mutations_value = |
| 119 Value::CreateStringValue( |
| 120 base::Uint64ToString(static_cast<uint64>(mutations_size)) + |
| 121 " mutations"); |
| 122 } |
| 123 dict->Set("mutations", mutations_value); |
| 124 return dict; |
| 125 } |
| 94 | 126 |
| 95 DictionaryValue* EntryKernelMutationToValue( | 127 DictionaryValue* EntryKernelMutationToValue( |
| 96 const EntryKernelMutation& mutation) { | 128 const EntryKernelMutation& mutation) { |
| 97 DictionaryValue* dict = new DictionaryValue(); | 129 DictionaryValue* dict = new DictionaryValue(); |
| 98 dict->Set("original", mutation.original.ToValue()); | 130 dict->Set("original", mutation.original.ToValue()); |
| 99 dict->Set("mutated", mutation.mutated.ToValue()); | 131 dict->Set("mutated", mutation.mutated.ToValue()); |
| 100 return dict; | 132 return dict; |
| 101 } | 133 } |
| 102 | 134 |
| 103 } // namespace | |
| 104 | |
| 105 ListValue* EntryKernelMutationMapToValue( | 135 ListValue* EntryKernelMutationMapToValue( |
| 106 const EntryKernelMutationMap& mutations) { | 136 const EntryKernelMutationMap& mutations) { |
| 107 ListValue* list = new ListValue(); | 137 ListValue* list = new ListValue(); |
| 108 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); | 138 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); |
| 109 it != mutations.end(); ++it) { | 139 it != mutations.end(); ++it) { |
| 110 list->Append(EntryKernelMutationToValue(it->second)); | 140 list->Append(EntryKernelMutationToValue(it->second)); |
| 111 } | 141 } |
| 112 return list; | 142 return list; |
| 113 } | 143 } |
| 114 | 144 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 398 } |
| 369 | 399 |
| 370 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} | 400 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} |
| 371 | 401 |
| 372 Directory::Kernel::Kernel(const FilePath& db_path, | 402 Directory::Kernel::Kernel(const FilePath& db_path, |
| 373 const string& name, | 403 const string& name, |
| 374 const KernelLoadInfo& info, | 404 const KernelLoadInfo& info, |
| 375 DirectoryChangeDelegate* delegate) | 405 DirectoryChangeDelegate* delegate) |
| 376 : db_path(db_path), | 406 : db_path(db_path), |
| 377 refcount(1), | 407 refcount(1), |
| 408 next_write_transaction_id(0), |
| 378 name(name), | 409 name(name), |
| 379 metahandles_index(new Directory::MetahandlesIndex), | 410 metahandles_index(new Directory::MetahandlesIndex), |
| 380 ids_index(new Directory::IdsIndex), | 411 ids_index(new Directory::IdsIndex), |
| 381 parent_id_child_index(new Directory::ParentIdChildIndex), | 412 parent_id_child_index(new Directory::ParentIdChildIndex), |
| 382 client_tag_index(new Directory::ClientTagIndex), | 413 client_tag_index(new Directory::ClientTagIndex), |
| 383 unapplied_update_metahandles(new MetahandleSet), | 414 unapplied_update_metahandles(new MetahandleSet), |
| 384 unsynced_metahandles(new MetahandleSet), | 415 unsynced_metahandles(new MetahandleSet), |
| 385 dirty_metahandles(new MetahandleSet), | 416 dirty_metahandles(new MetahandleSet), |
| 386 metahandles_to_purge(new MetahandleSet), | 417 metahandles_to_purge(new MetahandleSet), |
| 387 info_status(Directory::KERNEL_SHARE_INFO_VALID), | 418 info_status(Directory::KERNEL_SHARE_INFO_VALID), |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 if (has_mutations) { | 1276 if (has_mutations) { |
| 1246 NotifyTransactionComplete(models_with_changes); | 1277 NotifyTransactionComplete(models_with_changes); |
| 1247 } | 1278 } |
| 1248 } | 1279 } |
| 1249 | 1280 |
| 1250 ModelTypeBitSet WriteTransaction::NotifyTransactionChangingAndEnding( | 1281 ModelTypeBitSet WriteTransaction::NotifyTransactionChangingAndEnding( |
| 1251 const ImmutableEntryKernelMutationMap& mutations) { | 1282 const ImmutableEntryKernelMutationMap& mutations) { |
| 1252 dirkernel_->transaction_mutex.AssertAcquired(); | 1283 dirkernel_->transaction_mutex.AssertAcquired(); |
| 1253 DCHECK(!mutations.Get().empty()); | 1284 DCHECK(!mutations.Get().empty()); |
| 1254 | 1285 |
| 1286 WriteTransactionInfo write_transaction_info( |
| 1287 dirkernel_->next_write_transaction_id, from_here_, writer_, mutations); |
| 1288 ++dirkernel_->next_write_transaction_id; |
| 1289 |
| 1290 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
| 1291 &write_transaction_info); |
| 1255 DirectoryChangeDelegate* const delegate = dirkernel_->delegate; | 1292 DirectoryChangeDelegate* const delegate = dirkernel_->delegate; |
| 1256 if (writer_ == syncable::SYNCAPI) { | 1293 if (writer_ == syncable::SYNCAPI) { |
| 1257 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 1294 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
| 1258 mutations.Get(), this); | 1295 immutable_write_transaction_info, this); |
| 1259 } else { | 1296 } else { |
| 1260 delegate->HandleCalculateChangesChangeEventFromSyncer( | 1297 delegate->HandleCalculateChangesChangeEventFromSyncer( |
| 1261 mutations.Get(), this); | 1298 immutable_write_transaction_info, this); |
| 1262 } | 1299 } |
| 1263 | 1300 |
| 1264 ModelTypeBitSet models_with_changes = | 1301 ModelTypeBitSet models_with_changes = |
| 1265 delegate->HandleTransactionEndingChangeEvent(this); | 1302 delegate->HandleTransactionEndingChangeEvent( |
| 1303 immutable_write_transaction_info, this); |
| 1266 | 1304 |
| 1267 dirkernel_->observers->Notify( | 1305 dirkernel_->observers->Notify( |
| 1268 &TransactionObserver::OnTransactionMutate, | 1306 &TransactionObserver::OnTransactionWrite, |
| 1269 from_here_, writer_, mutations, models_with_changes); | 1307 immutable_write_transaction_info, models_with_changes); |
| 1270 | 1308 |
| 1271 return models_with_changes; | 1309 return models_with_changes; |
| 1272 } | 1310 } |
| 1273 | 1311 |
| 1274 void WriteTransaction::NotifyTransactionComplete( | 1312 void WriteTransaction::NotifyTransactionComplete( |
| 1275 ModelTypeBitSet models_with_changes) { | 1313 ModelTypeBitSet models_with_changes) { |
| 1276 dirkernel_->delegate->HandleTransactionCompleteChangeEvent( | 1314 dirkernel_->delegate->HandleTransactionCompleteChangeEvent( |
| 1277 models_with_changes); | 1315 models_with_changes); |
| 1278 } | 1316 } |
| 1279 | 1317 |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 CHECK(result); | 1986 CHECK(result); |
| 1949 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), | 1987 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), |
| 1950 end = GetParentChildIndexUpperBound(lock, parent_id); | 1988 end = GetParentChildIndexUpperBound(lock, parent_id); |
| 1951 i != end; ++i) { | 1989 i != end; ++i) { |
| 1952 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); | 1990 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); |
| 1953 result->push_back((*i)->ref(META_HANDLE)); | 1991 result->push_back((*i)->ref(META_HANDLE)); |
| 1954 } | 1992 } |
| 1955 } | 1993 } |
| 1956 | 1994 |
| 1957 } // namespace syncable | 1995 } // namespace syncable |
| OLD | NEW |