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

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

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

Powered by Google App Engine
This is Rietveld 408576698