OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 20 matching lines...) Expand all Loading... |
31 #include "base/file_util.h" | 31 #include "base/file_util.h" |
32 #include "base/logging.h" | 32 #include "base/logging.h" |
33 #include "base/perftimer.h" | 33 #include "base/perftimer.h" |
34 #include "base/scoped_ptr.h" | 34 #include "base/scoped_ptr.h" |
35 #include "base/string_number_conversions.h" | 35 #include "base/string_number_conversions.h" |
36 #include "base/string_util.h" | 36 #include "base/string_util.h" |
37 #include "base/stl_util-inl.h" | 37 #include "base/stl_util-inl.h" |
38 #include "base/time.h" | 38 #include "base/time.h" |
39 #include "chrome/browser/sync/engine/syncer.h" | 39 #include "chrome/browser/sync/engine/syncer.h" |
40 #include "chrome/browser/sync/engine/syncer_util.h" | 40 #include "chrome/browser/sync/engine/syncer_util.h" |
41 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | |
42 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | |
43 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | |
44 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | |
45 #include "chrome/browser/sync/protocol/service_constants.h" | 41 #include "chrome/browser/sync/protocol/service_constants.h" |
46 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 42 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
47 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
48 #include "chrome/browser/sync/syncable/directory_backing_store.h" | 44 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
49 #include "chrome/browser/sync/syncable/directory_manager.h" | 45 #include "chrome/browser/sync/syncable/directory_manager.h" |
50 #include "chrome/browser/sync/syncable/syncable-inl.h" | 46 #include "chrome/browser/sync/syncable/syncable-inl.h" |
51 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 47 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
52 #include "chrome/browser/sync/syncable/syncable_columns.h" | 48 #include "chrome/browser/sync/syncable/syncable_columns.h" |
53 #include "chrome/browser/sync/util/crypto_helpers.h" | 49 #include "chrome/browser/sync/util/crypto_helpers.h" |
54 #include "chrome/common/deprecated/event_sys-inl.h" | 50 #include "chrome/common/deprecated/event_sys-inl.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 void Directory::Kernel::AddRef() { | 216 void Directory::Kernel::AddRef() { |
221 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); | 217 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); |
222 } | 218 } |
223 | 219 |
224 void Directory::Kernel::Release() { | 220 void Directory::Kernel::Release() { |
225 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) | 221 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) |
226 delete this; | 222 delete this; |
227 } | 223 } |
228 | 224 |
229 Directory::Kernel::~Kernel() { | 225 Directory::Kernel::~Kernel() { |
230 CHECK(0 == refcount); | 226 CHECK_EQ(0, refcount); |
231 delete channel; | 227 delete channel; |
232 changes_channel.Notify(kShutdownChangesEvent); | 228 changes_channel.Notify(kShutdownChangesEvent); |
233 delete unsynced_metahandles; | 229 delete unsynced_metahandles; |
234 delete unapplied_update_metahandles; | 230 delete unapplied_update_metahandles; |
235 delete dirty_metahandles; | 231 delete dirty_metahandles; |
236 delete metahandles_to_purge; | 232 delete metahandles_to_purge; |
237 delete parent_id_child_index; | 233 delete parent_id_child_index; |
238 delete client_tag_index; | 234 delete client_tag_index; |
239 delete ids_index; | 235 delete ids_index; |
240 STLDeleteElements(metahandles_index); | 236 STLDeleteElements(metahandles_index); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 entry->put(IS_DEL, false); | 479 entry->put(IS_DEL, false); |
484 entry->mark_dirty(kernel_->dirty_metahandles); | 480 entry->mark_dirty(kernel_->dirty_metahandles); |
485 CHECK(kernel_->parent_id_child_index->insert(entry).second); | 481 CHECK(kernel_->parent_id_child_index->insert(entry).second); |
486 } | 482 } |
487 | 483 |
488 void Directory::Delete(EntryKernel* const entry) { | 484 void Directory::Delete(EntryKernel* const entry) { |
489 DCHECK(!entry->ref(IS_DEL)); | 485 DCHECK(!entry->ref(IS_DEL)); |
490 entry->put(IS_DEL, true); | 486 entry->put(IS_DEL, true); |
491 entry->mark_dirty(kernel_->dirty_metahandles); | 487 entry->mark_dirty(kernel_->dirty_metahandles); |
492 ScopedKernelLock lock(this); | 488 ScopedKernelLock lock(this); |
493 CHECK(1 == kernel_->parent_id_child_index->erase(entry)); | 489 CHECK_EQ(1U, kernel_->parent_id_child_index->erase(entry)); |
494 } | 490 } |
495 | 491 |
496 bool Directory::ReindexId(EntryKernel* const entry, const Id& new_id) { | 492 bool Directory::ReindexId(EntryKernel* const entry, const Id& new_id) { |
497 ScopedKernelLock lock(this); | 493 ScopedKernelLock lock(this); |
498 if (NULL != GetEntryById(new_id, &lock)) | 494 if (NULL != GetEntryById(new_id, &lock)) |
499 return false; | 495 return false; |
500 CHECK(1 == kernel_->ids_index->erase(entry)); | 496 CHECK_EQ(1U, kernel_->ids_index->erase(entry)); |
501 entry->put(ID, new_id); | 497 entry->put(ID, new_id); |
502 CHECK(kernel_->ids_index->insert(entry).second); | 498 CHECK(kernel_->ids_index->insert(entry).second); |
503 return true; | 499 return true; |
504 } | 500 } |
505 | 501 |
506 void Directory::ReindexParentId(EntryKernel* const entry, | 502 void Directory::ReindexParentId(EntryKernel* const entry, |
507 const Id& new_parent_id) { | 503 const Id& new_parent_id) { |
508 | |
509 ScopedKernelLock lock(this); | 504 ScopedKernelLock lock(this); |
510 if (entry->ref(IS_DEL)) { | 505 if (entry->ref(IS_DEL)) { |
511 entry->put(PARENT_ID, new_parent_id); | 506 entry->put(PARENT_ID, new_parent_id); |
512 return; | 507 return; |
513 } | 508 } |
514 | 509 |
515 if (entry->ref(PARENT_ID) == new_parent_id) { | 510 if (entry->ref(PARENT_ID) == new_parent_id) { |
516 return; | 511 return; |
517 } | 512 } |
518 | 513 |
519 CHECK(1 == kernel_->parent_id_child_index->erase(entry)); | 514 CHECK_EQ(1U, kernel_->parent_id_child_index->erase(entry)); |
520 entry->put(PARENT_ID, new_parent_id); | 515 entry->put(PARENT_ID, new_parent_id); |
521 CHECK(kernel_->parent_id_child_index->insert(entry).second); | 516 CHECK(kernel_->parent_id_child_index->insert(entry).second); |
522 } | 517 } |
523 | 518 |
524 void Directory::ClearDirtyMetahandles() { | 519 void Directory::ClearDirtyMetahandles() { |
525 kernel_->transaction_mutex.AssertAcquired(); | 520 kernel_->transaction_mutex.AssertAcquired(); |
526 kernel_->dirty_metahandles->clear(); | 521 kernel_->dirty_metahandles->clear(); |
527 } | 522 } |
528 | 523 |
529 bool Directory::SafeToPurgeFromMemory(const EntryKernel* const entry) const { | 524 bool Directory::SafeToPurgeFromMemory(const EntryKernel* const entry) const { |
530 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && | 525 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && |
531 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && | 526 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && |
532 !entry->ref(IS_UNSYNCED); | 527 !entry->ref(IS_UNSYNCED); |
533 | 528 |
534 if (safe) { | 529 if (safe) { |
535 int64 handle = entry->ref(META_HANDLE); | 530 int64 handle = entry->ref(META_HANDLE); |
536 CHECK(kernel_->dirty_metahandles->count(handle) == 0); | 531 CHECK_EQ(kernel_->dirty_metahandles->count(handle), 0U); |
537 // TODO(tim): Bug 49278. | 532 // TODO(tim): Bug 49278. |
538 CHECK(!kernel_->unsynced_metahandles->count(handle)); | 533 CHECK(!kernel_->unsynced_metahandles->count(handle)); |
539 CHECK(!kernel_->unapplied_update_metahandles->count(handle)); | 534 CHECK(!kernel_->unapplied_update_metahandles->count(handle)); |
540 } | 535 } |
541 | 536 |
542 return safe; | 537 return safe; |
543 } | 538 } |
544 | 539 |
545 void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) { | 540 void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) { |
546 ReadTransaction trans(this, __FILE__, __LINE__); | 541 ReadTransaction trans(this, __FILE__, __LINE__); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 while (!parentid.IsRoot()) { | 989 while (!parentid.IsRoot()) { |
995 if (!idfilter.ShouldConsider(parentid)) | 990 if (!idfilter.ShouldConsider(parentid)) |
996 break; | 991 break; |
997 Entry parent(trans, GET_BY_ID, parentid); | 992 Entry parent(trans, GET_BY_ID, parentid); |
998 CHECK(parent.good()) << e; | 993 CHECK(parent.good()) << e; |
999 CHECK(parent.Get(IS_DIR)) << parent << e; | 994 CHECK(parent.Get(IS_DIR)) << parent << e; |
1000 CHECK(!parent.Get(IS_DEL)) << parent << e; | 995 CHECK(!parent.Get(IS_DEL)) << parent << e; |
1001 CHECK(handles.end() != handles.find(parent.Get(META_HANDLE))) | 996 CHECK(handles.end() != handles.find(parent.Get(META_HANDLE))) |
1002 << e << parent; | 997 << e << parent; |
1003 parentid = parent.Get(PARENT_ID); | 998 parentid = parent.Get(PARENT_ID); |
1004 CHECK(--safety_count >= 0) << e << parent; | 999 CHECK_GE(--safety_count, 0) << e << parent; |
1005 } | 1000 } |
1006 } | 1001 } |
1007 int64 base_version = e.Get(BASE_VERSION); | 1002 int64 base_version = e.Get(BASE_VERSION); |
1008 int64 server_version = e.Get(SERVER_VERSION); | 1003 int64 server_version = e.Get(SERVER_VERSION); |
1009 bool using_unique_client_tag = !e.Get(UNIQUE_CLIENT_TAG).empty(); | 1004 bool using_unique_client_tag = !e.Get(UNIQUE_CLIENT_TAG).empty(); |
1010 if (CHANGES_VERSION == base_version || 0 == base_version) { | 1005 if (CHANGES_VERSION == base_version || 0 == base_version) { |
1011 if (e.Get(IS_UNAPPLIED_UPDATE)) { | 1006 if (e.Get(IS_UNAPPLIED_UPDATE)) { |
1012 // Must be a new item, or a de-duplicated unique client tag | 1007 // Must be a new item, or a de-duplicated unique client tag |
1013 // that was created both locally and remotely. | 1008 // that was created both locally and remotely. |
1014 if (!using_unique_client_tag) { | 1009 if (!using_unique_client_tag) { |
1015 CHECK(e.Get(IS_DEL)) << e; | 1010 CHECK(e.Get(IS_DEL)) << e; |
1016 } | 1011 } |
1017 // It came from the server, so it must have a server ID. | 1012 // It came from the server, so it must have a server ID. |
1018 CHECK(id.ServerKnows()) << e; | 1013 CHECK(id.ServerKnows()) << e; |
1019 } else { | 1014 } else { |
1020 if (e.Get(IS_DIR)) { | 1015 if (e.Get(IS_DIR)) { |
1021 // TODO(chron): Implement this mode if clients ever need it. | 1016 // TODO(chron): Implement this mode if clients ever need it. |
1022 // For now, you can't combine a client tag and a directory. | 1017 // For now, you can't combine a client tag and a directory. |
1023 CHECK(!using_unique_client_tag) << e; | 1018 CHECK(!using_unique_client_tag) << e; |
1024 } | 1019 } |
1025 // Should be an uncomitted item, or a successfully deleted one. | 1020 // Should be an uncomitted item, or a successfully deleted one. |
1026 if (!e.Get(IS_DEL)) { | 1021 if (!e.Get(IS_DEL)) { |
1027 CHECK(e.Get(IS_UNSYNCED)) << e; | 1022 CHECK(e.Get(IS_UNSYNCED)) << e; |
1028 } | 1023 } |
1029 // If the next check failed, it would imply that an item exists | 1024 // If the next check failed, it would imply that an item exists |
1030 // on the server, isn't waiting for application locally, but either | 1025 // on the server, isn't waiting for application locally, but either |
1031 // is an unsynced create or a sucessful delete in the local copy. | 1026 // is an unsynced create or a sucessful delete in the local copy. |
1032 // Either way, that's a mismatch. | 1027 // Either way, that's a mismatch. |
1033 CHECK(0 == server_version) << e; | 1028 CHECK_EQ(0, server_version) << e; |
1034 // Items that aren't using the unique client tag should have a zero | 1029 // Items that aren't using the unique client tag should have a zero |
1035 // base version only if they have a local ID. Items with unique client | 1030 // base version only if they have a local ID. Items with unique client |
1036 // tags are allowed to use the zero base version for undeletion and | 1031 // tags are allowed to use the zero base version for undeletion and |
1037 // de-duplication; the unique client tag trumps the server ID. | 1032 // de-duplication; the unique client tag trumps the server ID. |
1038 if (!using_unique_client_tag) { | 1033 if (!using_unique_client_tag) { |
1039 CHECK(!id.ServerKnows()) << e; | 1034 CHECK(!id.ServerKnows()) << e; |
1040 } | 1035 } |
1041 } | 1036 } |
1042 } else { | 1037 } else { |
1043 CHECK(id.ServerKnows()); | 1038 CHECK(id.ServerKnows()); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 // Loose check for server-created top-level folders that aren't | 1258 // Loose check for server-created top-level folders that aren't |
1264 // bound to a particular model type. | 1259 // bound to a particular model type. |
1265 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(SERVER_IS_DIR)) | 1260 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(SERVER_IS_DIR)) |
1266 return TOP_LEVEL_FOLDER; | 1261 return TOP_LEVEL_FOLDER; |
1267 | 1262 |
1268 // Otherwise, we don't have a server type yet. That should only happen | 1263 // Otherwise, we don't have a server type yet. That should only happen |
1269 // if the item is an uncommitted locally created item. | 1264 // if the item is an uncommitted locally created item. |
1270 // It's possible we'll need to relax these checks in the future; they're | 1265 // It's possible we'll need to relax these checks in the future; they're |
1271 // just here for now as a safety measure. | 1266 // just here for now as a safety measure. |
1272 DCHECK(Get(IS_UNSYNCED)); | 1267 DCHECK(Get(IS_UNSYNCED)); |
1273 DCHECK(Get(SERVER_VERSION) == 0); | 1268 DCHECK_EQ(Get(SERVER_VERSION), 0); |
1274 DCHECK(Get(SERVER_IS_DEL)); | 1269 DCHECK(Get(SERVER_IS_DEL)); |
1275 // Note: can't enforce !Get(ID).ServerKnows() here because that could | 1270 // Note: can't enforce !Get(ID).ServerKnows() here because that could |
1276 // actually happen if we hit AttemptReuniteLostCommitResponses. | 1271 // actually happen if we hit AttemptReuniteLostCommitResponses. |
1277 return UNSPECIFIED; | 1272 return UNSPECIFIED; |
1278 } | 1273 } |
1279 | 1274 |
1280 syncable::ModelType Entry::GetModelType() const { | 1275 syncable::ModelType Entry::GetModelType() const { |
1281 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); | 1276 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); |
1282 if (specifics_type != UNSPECIFIED) | 1277 if (specifics_type != UNSPECIFIED) |
1283 return specifics_type; | 1278 return specifics_type; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 MetahandleSet* index; | 1489 MetahandleSet* index; |
1495 if (IS_UNSYNCED == field) | 1490 if (IS_UNSYNCED == field) |
1496 index = dir()->kernel_->unsynced_metahandles; | 1491 index = dir()->kernel_->unsynced_metahandles; |
1497 else | 1492 else |
1498 index = dir()->kernel_->unapplied_update_metahandles; | 1493 index = dir()->kernel_->unapplied_update_metahandles; |
1499 | 1494 |
1500 ScopedKernelLock lock(dir()); | 1495 ScopedKernelLock lock(dir()); |
1501 if (value) | 1496 if (value) |
1502 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); | 1497 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); |
1503 else | 1498 else |
1504 CHECK(1 == index->erase(kernel_->ref(META_HANDLE))); | 1499 CHECK_EQ(1U, index->erase(kernel_->ref(META_HANDLE))); |
1505 kernel_->put(field, value); | 1500 kernel_->put(field, value); |
1506 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1501 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1507 } | 1502 } |
1508 return true; | 1503 return true; |
1509 } | 1504 } |
1510 | 1505 |
1511 void MutableEntry::UnlinkFromOrder() { | 1506 void MutableEntry::UnlinkFromOrder() { |
1512 ScopedKernelLock lock(dir()); | 1507 ScopedKernelLock lock(dir()); |
1513 dir()->UnlinkEntryFromOrder(kernel_, write_transaction(), &lock); | 1508 dir()->UnlinkEntryFromOrder(kernel_, write_transaction(), &lock); |
1514 } | 1509 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 } | 1702 } |
1708 | 1703 |
1709 std::ostream& operator<<(std::ostream& s, const Blob& blob) { | 1704 std::ostream& operator<<(std::ostream& s, const Blob& blob) { |
1710 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) | 1705 for (Blob::const_iterator i = blob.begin(); i != blob.end(); ++i) |
1711 s << std::hex << std::setw(2) | 1706 s << std::hex << std::setw(2) |
1712 << std::setfill('0') << static_cast<unsigned int>(*i); | 1707 << std::setfill('0') << static_cast<unsigned int>(*i); |
1713 return s << std::dec; | 1708 return s << std::dec; |
1714 } | 1709 } |
1715 | 1710 |
1716 } // namespace syncable | 1711 } // namespace syncable |
OLD | NEW |