diff options
author | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 03:57:44 +0000 |
---|---|---|
committer | nick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 03:57:44 +0000 |
commit | fca88254a5b6c949ed39a9b1f7bdfec99b240d82 (patch) | |
tree | 80eeed4227317877f9dc6170134835f817845e76 /chrome/browser/sync | |
parent | 9c1a8a7845da4778c4976cafc6c8c39cec00b796 (diff) | |
download | chromium_src-fca88254a5b6c949ed39a9b1f7bdfec99b240d82.zip chromium_src-fca88254a5b6c949ed39a9b1f7bdfec99b240d82.tar.gz chromium_src-fca88254a5b6c949ed39a9b1f7bdfec99b240d82.tar.bz2 |
Remove extended attributes. The lame broken codepath in the DBS was causing
several tests to fail their SaveChanges()es. Add unit test for the DBS migrations.
BUG=47466
TEST=sync_unit_tests (and included new tests).
Review URL: http://codereview.chromium.org/2830027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51225 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/engine/build_commit_command.cc | 16 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_unittest.cc | 64 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_util.cc | 24 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_util.h | 4 | ||||
-rw-r--r-- | chrome/browser/sync/protocol/sync.proto | 12 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/directory_backing_store.cc | 118 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/directory_backing_store.h | 16 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/directory_backing_store_unittest.cc | 139 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/syncable.cc | 135 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/syncable.h | 89 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/syncable_unittest.cc | 65 |
11 files changed, 182 insertions, 500 deletions
diff --git a/chrome/browser/sync/engine/build_commit_command.cc b/chrome/browser/sync/engine/build_commit_command.cc index a697c69..49f5f25 100644 --- a/chrome/browser/sync/engine/build_commit_command.cc +++ b/chrome/browser/sync/engine/build_commit_command.cc @@ -19,7 +19,6 @@ using std::set; using std::string; using std::vector; -using syncable::ExtendedAttribute; using syncable::IS_DEL; using syncable::Id; using syncable::MutableEntry; @@ -163,21 +162,6 @@ void BuildCommitCommand::ExecuteImpl(SyncSession* session) { sync_entry->set_mtime(ClientTimeToServerTime( meta_entry.Get(syncable::MTIME))); - set<ExtendedAttribute> extended_attributes; - meta_entry.GetAllExtendedAttributes( - session->write_transaction(), &extended_attributes); - set<ExtendedAttribute>::iterator iter; - sync_pb::ExtendedAttributes* mutable_extended_attributes = - sync_entry->mutable_extended_attributes(); - for (iter = extended_attributes.begin(); iter != extended_attributes.end(); - ++iter) { - sync_pb::ExtendedAttributes_ExtendedAttribute *extended_attribute = - mutable_extended_attributes->add_extendedattribute(); - extended_attribute->set_key(iter->key()); - SyncerProtoUtil::CopyBlobIntoProtoBytes(iter->value(), - extended_attribute->mutable_value()); - } - // Deletion is final on the server, let's move things and then delete them. if (meta_entry.Get(IS_DEL)) { sync_entry->set_deleted(true); diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc index 7a5a767..6933cd4 100644 --- a/chrome/browser/sync/engine/syncer_unittest.cc +++ b/chrome/browser/sync/engine/syncer_unittest.cc @@ -49,13 +49,10 @@ using syncable::Blob; using syncable::CountEntriesWithName; using syncable::Directory; using syncable::Entry; -using syncable::ExtendedAttribute; -using syncable::ExtendedAttributeKey; using syncable::GetFirstEntryWithName; using syncable::GetOnlyEntryWithName; using syncable::Id; using syncable::MutableEntry; -using syncable::MutableExtendedAttribute; using syncable::ReadTransaction; using syncable::ScopedDirLookup; using syncable::WriteTransaction; @@ -95,12 +92,6 @@ using sessions::StatusController; using sessions::SyncSessionContext; using sessions::SyncSession; -namespace { -const char* kTestData = "Hello World!"; -const int kTestDataLen = 12; -const int64 kTestLogRequestTimestamp = 123456; -} // namespace - class SyncerTest : public testing::Test, public SyncSession::Delegate, public ModelSafeWorkerRegistrar, @@ -211,10 +202,6 @@ class SyncerTest : public testing::Test, void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { EXPECT_FALSE(entry->Get(IS_DIR)); EXPECT_FALSE(entry->Get(IS_DEL)); - Blob test_value(kTestData, kTestData + kTestDataLen); - ExtendedAttributeKey key(entry->Get(META_HANDLE), "DATA"); - MutableExtendedAttribute attr(trans, CREATE, key); - attr.mutable_value()->swap(test_value); sync_pb::EntitySpecifics specifics; specifics.MutableExtension(sync_pb::bookmark)->set_url("http://demo/"); specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG"); @@ -224,11 +211,6 @@ class SyncerTest : public testing::Test, void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { EXPECT_FALSE(entry->Get(IS_DIR)); EXPECT_FALSE(entry->Get(IS_DEL)); - Blob test_value(kTestData, kTestData + kTestDataLen); - ExtendedAttributeKey key(entry->Get(META_HANDLE), "DATA"); - ExtendedAttribute attr(trans, GET_BY_HANDLE, key); - EXPECT_FALSE(attr.is_deleted()); - EXPECT_TRUE(test_value == attr.value()); VerifyTestBookmarkDataInEntry(entry); } void VerifyTestBookmarkDataInEntry(Entry* entry) { @@ -542,7 +524,6 @@ TEST_F(SyncerTest, TestCommitMetahandleIterator) { TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); ASSERT_TRUE(dir.good()); - string xattr_key = "key"; { WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), @@ -1067,51 +1048,6 @@ TEST_F(SyncerTest, DontGetStuckWithTwoSameNames) { syncer_events_.clear(); } -TEST_F(SyncerTest, ExtendedAttributeWithNullCharacter) { - ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); - ASSERT_TRUE(dir.good()); - size_t xattr_count = 2; - string xattr_keys[] = { "key", "key2" }; - syncable::Blob xattr_values[2]; - const char* value[] = { "value", "val\0ue" }; - int value_length[] = { 5, 6 }; - for (size_t i = 0; i < xattr_count; i++) { - for (int j = 0; j < value_length[i]; j++) - xattr_values[i].push_back(value[i][j]); - } - sync_pb::SyncEntity* ent = - mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); - mock_server_->AddUpdateExtendedAttributes( - ent, xattr_keys, xattr_values, xattr_count); - - // Add some other items. - mock_server_->AddUpdateBookmark(2, 0, "fred", 2, 10); - mock_server_->AddUpdateBookmark(3, 0, "sue", 15, 10); - - syncer_->SyncShare(this); - ReadTransaction trans(dir, __FILE__, __LINE__); - Entry entry1(&trans, syncable::GET_BY_ID, ids_.FromNumber(1)); - ASSERT_TRUE(entry1.good()); - EXPECT_TRUE(1 == entry1.Get(syncable::BASE_VERSION)); - EXPECT_TRUE(1 == entry1.Get(syncable::SERVER_VERSION)); - set<ExtendedAttribute> client_extended_attributes; - entry1.GetAllExtendedAttributes(&trans, &client_extended_attributes); - EXPECT_TRUE(xattr_count == client_extended_attributes.size()); - for (size_t i = 0; i < xattr_count; i++) { - ExtendedAttributeKey key(entry1.Get(syncable::META_HANDLE), xattr_keys[i]); - ExtendedAttribute expected_xattr(&trans, syncable::GET_BY_HANDLE, key); - EXPECT_TRUE(expected_xattr.good()); - for (int j = 0; j < value_length[i]; ++j) { - EXPECT_TRUE(xattr_values[i][j] == - static_cast<char>(expected_xattr.value().at(j))); - } - } - Entry entry2(&trans, syncable::GET_BY_ID, ids_.FromNumber(2)); - ASSERT_TRUE(entry2.good()); - Entry entry3(&trans, syncable::GET_BY_ID, ids_.FromNumber(3)); - ASSERT_TRUE(entry3.good()); -} - TEST_F(SyncerTest, TestBasicUpdate) { ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); ASSERT_TRUE(dir.good()); diff --git a/chrome/browser/sync/engine/syncer_util.cc b/chrome/browser/sync/engine/syncer_util.cc index 41181d6..8b5f7b9 100644 --- a/chrome/browser/sync/engine/syncer_util.cc +++ b/chrome/browser/sync/engine/syncer_util.cc @@ -30,7 +30,6 @@ using syncable::CTIME; using syncable::ComparePathNames; using syncable::Directory; using syncable::Entry; -using syncable::ExtendedAttributeKey; using syncable::GET_BY_HANDLE; using syncable::GET_BY_ID; using syncable::ID; @@ -42,7 +41,6 @@ using syncable::Id; using syncable::META_HANDLE; using syncable::MTIME; using syncable::MutableEntry; -using syncable::MutableExtendedAttribute; using syncable::NEXT_ID; using syncable::NON_UNIQUE_NAME; using syncable::PARENT_ID; @@ -407,28 +405,6 @@ void SyncerUtil::UpdateServerFieldsFromUpdate( if (server_entry.version() > local_entry->Get(BASE_VERSION)) { local_entry->Put(IS_UNAPPLIED_UPDATE, true); } - ApplyExtendedAttributes(local_entry, server_entry); -} - -// static -void SyncerUtil::ApplyExtendedAttributes( - syncable::MutableEntry* local_entry, - const SyncEntity& server_entry) { - local_entry->DeleteAllExtendedAttributes(local_entry->write_transaction()); - if (server_entry.has_extended_attributes()) { - const sync_pb::ExtendedAttributes & extended_attributes = - server_entry.extended_attributes(); - for (int i = 0; i < extended_attributes.extendedattribute_size(); i++) { - const string& string_key = - extended_attributes.extendedattribute(i).key(); - ExtendedAttributeKey key(local_entry->Get(META_HANDLE), string_key); - MutableExtendedAttribute local_attribute(local_entry->write_transaction(), - CREATE, key); - SyncerProtoUtil::CopyProtoBytesIntoBlob( - extended_attributes.extendedattribute(i).value(), - local_attribute.mutable_value()); - } - } } // Creates a new Entry iff no Entry exists with the given id. diff --git a/chrome/browser/sync/engine/syncer_util.h b/chrome/browser/sync/engine/syncer_util.h index 809a931..76bf030 100644 --- a/chrome/browser/sync/engine/syncer_util.h +++ b/chrome/browser/sync/engine/syncer_util.h @@ -63,10 +63,6 @@ class SyncerUtil { const SyncEntity& server_entry, const std::string& name); - static void ApplyExtendedAttributes( - syncable::MutableEntry* local_entry, - const SyncEntity& server_entry); - // Creates a new Entry iff no Entry exists with the given id. static void CreateNewEntry(syncable::WriteTransaction *trans, const syncable::Id& id); diff --git a/chrome/browser/sync/protocol/sync.proto b/chrome/browser/sync/protocol/sync.proto index 2ca8b4c..9b3b4d31 100644 --- a/chrome/browser/sync/protocol/sync.proto +++ b/chrome/browser/sync/protocol/sync.proto @@ -10,15 +10,6 @@ option optimize_for = LITE_RUNTIME; package sync_pb; -// Used to store and send extended attributes, which are arbitrary -// key value pairs. -message ExtendedAttributes { - repeated group ExtendedAttribute = 1 { - required string key = 2; - required bytes value = 3; - } -} - // Used for inspecting how long we spent performing operations in different // backends. All times must be in millis. message ProfilingData { @@ -180,7 +171,8 @@ message SyncEntity { // Arbitrary key/value pairs associated with this item. // Present in both GetUpdatesResponse and CommitMessage. - optional ExtendedAttributes extended_attributes = 17; + // Deprecated. + // optional ExtendedAttributes extended_attributes = 17; // If true, indicates that this item has been (or should be) deleted. // Present in both GetUpdatesResponse and CommitMessage. diff --git a/chrome/browser/sync/syncable/directory_backing_store.cc b/chrome/browser/sync/syncable/directory_backing_store.cc index 2a29789..63df81d 100644 --- a/chrome/browser/sync/syncable/directory_backing_store.cc +++ b/chrome/browser/sync/syncable/directory_backing_store.cc @@ -40,7 +40,7 @@ static const string::size_type kUpdateStatementBufferSize = 2048; // Increment this version whenever updating DB tables. extern const int32 kCurrentDBVersion; // Global visibility for our unittest. -const int32 kCurrentDBVersion = 71; +const int32 kCurrentDBVersion = 72; namespace { @@ -215,7 +215,6 @@ bool DirectoryBackingStore::OpenAndConfigureHandleHelper( } DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, - ExtendedAttributes* xattrs_bucket, Directory::KernelLoadInfo* kernel_load_info) { if (!BeginLoad()) return FAILED_OPEN_DATABASE; @@ -226,7 +225,6 @@ DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, if (!DropDeletedEntries() || !LoadEntries(entry_bucket) || - !LoadExtendedAttributes(xattrs_bucket) || !LoadInfo(kernel_load_info)) { return FAILED_DATABASE_CORRUPT; } @@ -261,8 +259,7 @@ bool DirectoryBackingStore::SaveChanges( // just stop here if there's nothing to save. bool save_info = (Directory::KERNEL_SHARE_INFO_DIRTY == snapshot.kernel_info_status); - if (snapshot.dirty_metas.size() < 1 && snapshot.dirty_xattrs.size() < 1 && - !save_info) + if (snapshot.dirty_metas.size() < 1 && !save_info) return true; SQLTransaction transaction(dbhandle); @@ -276,18 +273,6 @@ bool DirectoryBackingStore::SaveChanges( return false; } - for (ExtendedAttributes::const_iterator i = snapshot.dirty_xattrs.begin(); - i != snapshot.dirty_xattrs.end(); ++i) { - DCHECK(i->second.dirty); - if (i->second.is_deleted) { - if (!DeleteExtendedAttributeFromDB(i)) - return false; - } else { - if (!SaveExtendedAttributeToDB(i)) - return false; - } - } - if (save_info) { const Directory::PersistedKernelInfo& info = snapshot.kernel_info; SQLStatement update; @@ -355,6 +340,13 @@ DirOpenResult DirectoryBackingStore::InitializeTables() { version_on_disk = 71; } + // Version 72 removed extended attributes, a legacy way to do extensible + // key/value information, stored in their own table. + if (version_on_disk == 71) { + if (MigrateVersion71To72()) + version_on_disk = 72; + } + // If one of the migrations requested it, drop columns that aren't current. // It's only safe to do this after migrating all the way to the current // version. @@ -450,31 +442,6 @@ bool DirectoryBackingStore::LoadEntries(MetahandlesIndex* entry_bucket) { return SQLITE_DONE == query_result; } -bool DirectoryBackingStore::LoadExtendedAttributes( - ExtendedAttributes* xattrs_bucket) { - SQLStatement statement; - statement.prepare( - load_dbhandle_, - "SELECT metahandle, key, value FROM extended_attributes"); - int step_result = statement.step(); - while (SQLITE_ROW == step_result) { - int64 metahandle = statement.column_int64(0); - - string path_string_key; - statement.column_string(1, &path_string_key); - - ExtendedAttributeValue val; - statement.column_blob_as_vector(2, &(val.value)); - val.is_deleted = false; - - ExtendedAttributeKey key(metahandle, path_string_key); - xattrs_bucket->insert(std::make_pair(key, val)); - step_result = statement.step(); - } - - return SQLITE_DONE == step_result; -} - bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { { SQLStatement query; @@ -542,49 +509,7 @@ bool DirectoryBackingStore::SaveEntryToDB(const EntryKernel& entry) { 1 == statement.changes()); } -bool DirectoryBackingStore::SaveExtendedAttributeToDB( - ExtendedAttributes::const_iterator i) { - DCHECK(save_dbhandle_); - SQLStatement insert; - insert.prepare(save_dbhandle_, - "INSERT INTO extended_attributes " - "(metahandle, key, value) " - "values ( ?, ?, ? )"); - insert.bind_int64(0, i->first.metahandle); - insert.bind_string(1, i->first.key); - insert.bind_blob(2, &i->second.value.at(0), i->second.value.size()); - return (SQLITE_DONE == insert.step() && - SQLITE_OK == insert.reset() && - 1 == insert.changes()); -} - -bool DirectoryBackingStore::DeleteExtendedAttributeFromDB( - ExtendedAttributes::const_iterator i) { - DCHECK(save_dbhandle_); - SQLStatement delete_attribute; - delete_attribute.prepare(save_dbhandle_, - "DELETE FROM extended_attributes " - "WHERE metahandle = ? AND key = ? "); - delete_attribute.bind_int64(0, i->first.metahandle); - delete_attribute.bind_string(1, i->first.key); - if (!(SQLITE_DONE == delete_attribute.step() && - SQLITE_OK == delete_attribute.reset() && - 1 == delete_attribute.changes())) { - LOG(ERROR) << "DeleteExtendedAttributeFromDB(),StepDone() failed " - << "for metahandle: " << i->first.metahandle << " key: " - << i->first.key; - return false; - } - // The attribute may have never been saved to the database if it was - // created and then immediately deleted. So don't check that we - // deleted exactly 1 row. - return true; -} - bool DirectoryBackingStore::DropDeletedEntries() { - static const char delete_extended_attributes[] = - "DELETE FROM extended_attributes WHERE metahandle IN " - "(SELECT metahandle from death_row)"; static const char delete_metas[] = "DELETE FROM metas WHERE metahandle IN " "(SELECT metahandle from death_row)"; // Put all statements into a transaction for better performance @@ -602,9 +527,6 @@ bool DirectoryBackingStore::DropDeletedEntries() { " AND is_unapplied_update < 1")) { return false; } - if (SQLITE_DONE != ExecQuery(load_dbhandle_, delete_extended_attributes)) { - return false; - } if (SQLITE_DONE != ExecQuery(load_dbhandle_, delete_metas)) { return false; } @@ -630,19 +552,6 @@ int DirectoryBackingStore::SafeDropTable(const char* table_name) { return result; } -int DirectoryBackingStore::CreateExtendedAttributeTable() { - int result = SafeDropTable("extended_attributes"); - if (result != SQLITE_DONE) - return result; - LOG(INFO) << "CreateExtendedAttributeTable"; - return ExecQuery(load_dbhandle_, - "CREATE TABLE extended_attributes(" - "metahandle bigint, " - "key varchar(127), " - "value blob, " - "PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE)"); -} - void DirectoryBackingStore::DropAllTables() { SafeDropTable("metas"); SafeDropTable("temp_metas"); @@ -889,6 +798,12 @@ bool DirectoryBackingStore::MigrateVersion70To71() { return true; } +bool DirectoryBackingStore::MigrateVersion71To72() { + SafeDropTable("extended_attributes"); + SetVersion(72); + return true; +} + int DirectoryBackingStore::CreateTables() { LOG(INFO) << "First run, creating tables"; // Create two little tables share_version and share_info @@ -950,9 +865,6 @@ int DirectoryBackingStore::CreateTables() { statement.bind_int64(1, now); result = statement.step(); } - if (result != SQLITE_DONE) - return result; - result = CreateExtendedAttributeTable(); return result; } diff --git a/chrome/browser/sync/syncable/directory_backing_store.h b/chrome/browser/sync/syncable/directory_backing_store.h index b492e5d..fcbd848 100644 --- a/chrome/browser/sync/syncable/directory_backing_store.h +++ b/chrome/browser/sync/syncable/directory_backing_store.h @@ -59,13 +59,11 @@ class DirectoryBackingStore { virtual ~DirectoryBackingStore(); - // Loads and drops all currently persisted meta entries into - // |entry_bucket|, all currently persisted xattrs in |xattrs_bucket|, - // and loads appropriate persisted kernel info in |info_bucket|. + // Loads and drops all currently persisted meta entries into |entry_bucket| + // and loads appropriate persisted kernel info into |info_bucket|. // NOTE: On success (return value of OPENED), the buckets are populated with // newly allocated items, meaning ownership is bestowed upon the caller. DirOpenResult Load(MetahandlesIndex* entry_bucket, - ExtendedAttributes* xattrs_bucket, Directory::KernelLoadInfo* kernel_load_info); // Updates the on-disk store with the input |snapshot| as a database @@ -80,9 +78,9 @@ class DirectoryBackingStore { FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion68To69); FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion69To70); FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion70To71); + FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion71To72); FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, ModelTypeIds); FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, Corruption); - FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, DeleteEntries); FRIEND_TEST_ALL_PREFIXES(MigrationTest, ToCurrentVersion); friend class MigrationTest; @@ -99,8 +97,6 @@ class DirectoryBackingStore { int CreateMetasTable(bool is_temporary); // Returns an sqlite return code, SQLITE_DONE on success. int CreateModelsTable(); - // Returns an sqlite return code, SQLITE_DONE on success. - int CreateExtendedAttributeTable(); // We don't need to load any synced and applied deleted entries, we can // in fact just purge them forever on startup. @@ -110,7 +106,6 @@ class DirectoryBackingStore { // Load helpers for entries and attributes. bool LoadEntries(MetahandlesIndex* entry_bucket); - bool LoadExtendedAttributes(ExtendedAttributes* xattrs_bucket); bool LoadInfo(Directory::KernelLoadInfo* info); // Save/update helpers for entries. Return false if sqlite commit fails. @@ -118,10 +113,6 @@ class DirectoryBackingStore { bool SaveNewEntryToDB(const EntryKernel& entry); bool UpdateEntryToDB(const EntryKernel& entry); - // Save/update helpers for attributes. Return false if sqlite commit fails. - bool SaveExtendedAttributeToDB(ExtendedAttributes::const_iterator i); - bool DeleteExtendedAttributeFromDB(ExtendedAttributes::const_iterator i); - // Creates a new sqlite3 handle to the backing database. Sets sqlite operation // timeout preferences and registers our overridden sqlite3 operators for // said handle. Returns true on success, false if the sqlite open operation @@ -161,6 +152,7 @@ class DirectoryBackingStore { bool MigrateVersion68To69(); bool MigrateVersion69To70(); bool MigrateVersion70To71(); + bool MigrateVersion71To72(); // The handle to our sqlite on-disk store for initialization and loading, and // for saving changes periodically via SaveChanges, respectively. diff --git a/chrome/browser/sync/syncable/directory_backing_store_unittest.cc b/chrome/browser/sync/syncable/directory_backing_store_unittest.cc index 0daed91..3d6d143 100644 --- a/chrome/browser/sync/syncable/directory_backing_store_unittest.cc +++ b/chrome/browser/sync/syncable/directory_backing_store_unittest.cc @@ -46,6 +46,7 @@ class MigrationTest : public testing::TestWithParam<int> { void SetUpVersion68Database(); void SetUpVersion69Database(); void SetUpVersion70Database(); + void SetUpVersion71Database(); void SetUpCurrentDatabaseAndCheckVersion() { SetUpVersion70Database(); // Prepopulates data. @@ -75,7 +76,7 @@ void MigrationTest::SetUpVersion67Database() { ASSERT_TRUE(connection.Execute( "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), " "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);" - "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL," + "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL," "base_version bigint default -1,server_version bigint default 0," "mtime bigint default 0,server_mtime bigint default 0," "ctime bigint default 0,server_ctime bigint default 0," @@ -529,6 +530,111 @@ void MigrationTest::SetUpVersion70Database() { ASSERT_TRUE(connection.CommitTransaction()); } +void MigrationTest::SetUpVersion71Database() { + sql::Connection connection; + ASSERT_TRUE(connection.Open(GetDatabasePath())); + ASSERT_TRUE(connection.BeginTransaction()); + ASSERT_TRUE(connection.Execute( + "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), " + "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);" + "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" + "INSERT INTO 'share_version' VALUES('nick@chromium.org',71);" + "CREATE TABLE metas(metahandle bigint primary key ON CONFLICT FAIL," + "base_version bigint default -1,server_version bigint default 0," + "mtime bigint default 0,server_mtime bigint default 0,ctime bigint " + "default 0,server_ctime bigint default 0,server_position_in_parent " + "bigint default 0,local_external_id bigint default 0,id varchar(255) " + "default 'r',parent_id varchar(255) default 'r',server_parent_id " + "varchar(255) default 'r',prev_id varchar(255) default 'r',next_id " + "varchar(255) default 'r',is_unsynced bit default 0," + "is_unapplied_update bit default 0,is_del bit default 0,is_dir bit " + "default 0,server_is_dir bit default 0,server_is_del bit default 0," + "non_unique_name varchar,server_non_unique_name varchar(255)," + "unique_server_tag varchar,unique_client_tag varchar,specifics blob," + "server_specifics blob);" + "INSERT INTO 'metas' VALUES(1,-1,0,129079956640320000,0," + "129079956640320000,0,0,0,'r','r','r','r','r',0,0,0,1,0,0,NULL,NULL," + "NULL,NULL,X'',X'');" + "INSERT INTO 'metas' VALUES(2,669,669,128976886618480000," + "128976886618480000,128976886618480000,128976886618480000,-2097152,4," + "'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_2',0,0,1,0,0,1," + "'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A16687474703A2F2F" + "7777772E676F6F676C652E636F6D2F12084141534741534741',X'C28810260A1768" + "7474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534144474144474144" + "47');" + "INSERT INTO 'metas' VALUES(4,681,681,129002163642690000," + "129002163642690000,129002163642690000,129002163642690000,-3145728,3," + "'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_4',0,0,1,0,0,1," + "'Welcome to Chromium','Welcome to Chromium',NULL,NULL,X'C28810350A31" + "687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F" + "656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687474703A2F2F7777" + "772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656E2F77656C636F6D" + "652E68746D6C1200');" + "INSERT INTO 'metas' VALUES(5,677,677,129001555500000000," + "129001555500000000,129001555500000000,129001555500000000,1048576,7," + "'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_5',0,0,1,0,0,1,'Google'," + "'Google',NULL,NULL,X'C28810220A16687474703A2F2F7777772E676F6F676C652" + "E636F6D2F12084147415347415347',X'C28810220A16687474703A2F2F7777772E6" + "76F6F676C652E636F6D2F12084147464447415347');" + "INSERT INTO 'metas' VALUES(6,694,694,129053976170000000," + "129053976170000000,129053976170000000,129053976170000000,-4194304,6," + "'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1,1,0,'The Internet'," + "'The Internet',NULL,NULL,X'C2881000',X'C2881000');" + "INSERT INTO 'metas' VALUES(7,663,663,128976864758480000," + "128976864758480000,128976864758480000,128976864758480000,1048576,0," + "'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Google Chrome','Google Chrome'" + ",'google_chrome',NULL,NULL,NULL);" + "INSERT INTO 'metas' VALUES(8,664,664,128976864758480000," + "128976864758480000,128976864758480000,128976864758480000,1048576,0," + "'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1,1,0,'Bookmarks'," + "'Bookmarks','google_chrome_bookmarks',NULL,X'C2881000',X'C2881000');" + "INSERT INTO 'metas' VALUES(9,665,665,128976864758480000," + "128976864758480000,128976864758480000,128976864758480000,1048576,1," + "'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0,0,0,1,1,0,'Bookmark Bar'," + "'Bookmark Bar','bookmark_bar',NULL,X'C2881000',X'C2881000');" + "INSERT INTO 'metas' VALUES(10,666,666,128976864758480000," + "128976864758480000,128976864758480000,128976864758480000,2097152,2," + "'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r',0,0,0,1,1,0," + "'Other Bookmarks','Other Bookmarks','other_bookmarks',NULL," + "X'C2881000',X'C2881000');" + "INSERT INTO 'metas' VALUES(11,683,683,129079956948440000," + "129079956948440000,129079956948440000,129079956948440000,-1048576,8," + "'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13',0,0,0,0,0,0," + "'Home (The Chromium Projects)','Home (The Chromium Projects)',NULL," + "NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756D2E6F72672F1" + "206414741545741',X'C28810290A1D687474703A2F2F6465762E6368726F6D69756" + "D2E6F72672F6F7468657212084146414756415346');" + "INSERT INTO 'metas' VALUES(12,685,685,129079957513650000," + "129079957513650000,129079957513650000,129079957513650000,0,9," + "'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_ID_14',0,0,0,1,1,0," + "'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C2881000'," + "X'C2881000');" + "INSERT INTO 'metas' VALUES(13,687,687,129079957985300000," + "129079957985300000,129079957985300000,129079957985300000,-917504,10," + "'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_ID_12',0,0,0,0,0,0," + "'ICANN | Internet Corporation for Assigned Names and Numbers'," + "'ICANN | Internet Corporation for Assigned Names and Numbers',NULL," + "NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636F6D2F120B504" + "E474158463041414646',X'C28810200A15687474703A2F2F7777772E6963616E6E2" + "E636F6D2F120744414146415346');" + "INSERT INTO 'metas' VALUES(14,692,692,129079958383000000," + "129079958383000000,129079958383000000,129079958383000000,1048576,11," + "'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r',0,0,0,0,0,0," + "'The WebKit Open Source Project','The WebKit Open Source Project'," + "NULL,NULL,""X'C288101A0A12687474703A2F2F7765626B69742E6F72672F120450" + "4E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F781205504E" + "473259');" + "CREATE TABLE models (model_id BLOB primary key, " + "last_download_timestamp INT, initial_sync_ended BOOLEAN default 0);" + "INSERT INTO 'models' VALUES(X'C2881000',694,1);" + "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, " + "store_birthday TEXT, db_create_version TEXT, db_create_time INT, " + "next_id INT default -2, cache_guid TEXT);" + "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," + "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064,-65542," + "'9010788312004066376x-6609234393368420856x');")); + ASSERT_TRUE(connection.CommitTransaction()); +} TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { SetUpVersion67Database(); @@ -674,6 +780,31 @@ TEST_F(DirectoryBackingStoreTest, MigrateVersion70To71) { ASSERT_FALSE(s.Step()); } + +TEST_F(DirectoryBackingStoreTest, MigrateVersion71To72) { + SetUpVersion71Database(); + + { + sql::Connection connection; + ASSERT_TRUE(connection.Open(GetDatabasePath())); + ASSERT_TRUE(connection.DoesTableExist("extended_attributes")); + } + + scoped_ptr<DirectoryBackingStore> dbs( + new DirectoryBackingStore(GetUsername(), GetDatabasePath())); + + dbs->BeginLoad(); + ASSERT_FALSE(dbs->needs_column_refresh_); + ASSERT_TRUE(dbs->MigrateVersion71To72()); + ASSERT_EQ(72, dbs->GetVersion()); + dbs->EndLoad(); + ASSERT_FALSE(dbs->needs_column_refresh_); + + sql::Connection connection; + ASSERT_TRUE(connection.Open(GetDatabasePath())); + ASSERT_FALSE(connection.DoesTableExist("extended_attributes")); +} + TEST_P(MigrationTest, ToCurrentVersion) { switch (GetParam()) { case 67: @@ -688,6 +819,9 @@ TEST_P(MigrationTest, ToCurrentVersion) { case 70: SetUpVersion70Database(); break; + case 71: + SetUpVersion71Database(); + break; default: // If you see this error, it may mean that you've increased the // database version number but you haven't finished adding unit tests @@ -739,6 +873,9 @@ TEST_P(MigrationTest, ToCurrentVersion) { ASSERT_FALSE(connection.DoesColumnExist("metas", "singleton_tag")); ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag")); ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag")); + + // Removed extended attributes in Version 72. + ASSERT_FALSE(connection.DoesTableExist("extended_attributes")); } MetahandlesIndex index; diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc index 17176fd..3e93d40 100644 --- a/chrome/browser/sync/syncable/syncable.cc +++ b/chrome/browser/sync/syncable/syncable.cc @@ -167,7 +167,6 @@ Directory::Kernel::Kernel(const FilePath& db_path, ids_index(new Directory::IdsIndex), parent_id_child_index(new Directory::ParentIdChildIndex), client_tag_index(new Directory::ClientTagIndex), - extended_attributes(new ExtendedAttributes), unapplied_update_metahandles(new MetahandleSet), unsynced_metahandles(new MetahandleSet), dirty_metahandles(new MetahandleSet), @@ -198,7 +197,6 @@ Directory::Kernel::~Kernel() { delete unsynced_metahandles; delete unapplied_update_metahandles; delete dirty_metahandles; - delete extended_attributes; delete parent_id_child_index; delete client_tag_index; delete ids_index; @@ -254,14 +252,12 @@ DirOpenResult Directory::OpenImpl(const FilePath& file_path, // Temporary indices before kernel_ initialized in case Load fails. We 0(1) // swap these later. MetahandlesIndex metas_bucket; - ExtendedAttributes xattrs_bucket; - DirOpenResult result = store_->Load(&metas_bucket, &xattrs_bucket, &info); + DirOpenResult result = store_->Load(&metas_bucket, &info); if (OPENED != result) return result; kernel_ = new Kernel(db_path, name, info); kernel_->metahandles_index->swap(metas_bucket); - kernel_->extended_attributes->swap(xattrs_bucket); InitializeIndices(); return OPENED; } @@ -526,15 +522,6 @@ void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) { } ClearDirtyMetahandles(); - // Do the same for extended attributes. - for (ExtendedAttributes::iterator i = kernel_->extended_attributes->begin(); - i != kernel_->extended_attributes->end(); ++i) { - if (!i->second.dirty) - continue; - snapshot->dirty_xattrs[i->first] = i->second; - i->second.dirty = false; - } - // Fill kernel_info_status and kernel_info. snapshot->kernel_info = kernel_->persisted_info; // To avoid duplicates when the process crashes, we record the next_id to be @@ -595,19 +582,6 @@ void Directory::VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot) { delete entry; } } - - ExtendedAttributes::const_iterator i = snapshot.dirty_xattrs.begin(); - while (i != snapshot.dirty_xattrs.end()) { - ExtendedAttributeKey key(i->first.metahandle, i->first.key); - ExtendedAttributes::iterator found = - kernel_->extended_attributes->find(key); - if (found == kernel_->extended_attributes->end() || - found->second.dirty || !i->second.is_deleted) { - ++i; - } else { - kernel_->extended_attributes->erase(found); - } - } } void Directory::PurgeEntriesWithTypeIn(const std::set<ModelType>& types) { @@ -666,15 +640,6 @@ void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { (*found)->mark_dirty(kernel_->dirty_metahandles); } } - - for (ExtendedAttributes::const_iterator i = snapshot.dirty_xattrs.begin(); - i != snapshot.dirty_xattrs.end(); ++i) { - ExtendedAttributeKey key(i->first.metahandle, i->first.key); - ExtendedAttributes::iterator found = - kernel_->extended_attributes->find(key); - if (found != kernel_->extended_attributes->end()) - found->second.dirty = true; - } } int64 Directory::last_download_timestamp(ModelType model_type) const { @@ -752,46 +717,6 @@ void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, kernel_->unsynced_metahandles->end(), back_inserter(*result)); } -void Directory::GetAllExtendedAttributes(BaseTransaction* trans, - int64 metahandle, - std::set<ExtendedAttribute>* result) { - AttributeKeySet keys; - GetExtendedAttributesList(trans, metahandle, &keys); - AttributeKeySet::iterator iter; - for (iter = keys.begin(); iter != keys.end(); ++iter) { - ExtendedAttributeKey key(metahandle, *iter); - ExtendedAttribute extended_attribute(trans, GET_BY_HANDLE, key); - CHECK(extended_attribute.good()); - result->insert(extended_attribute); - } -} - -void Directory::GetExtendedAttributesList(BaseTransaction* trans, - int64 metahandle, AttributeKeySet* result) { - ExtendedAttributes::iterator iter; - for (iter = kernel_->extended_attributes->begin(); - iter != kernel_->extended_attributes->end(); ++iter) { - if (iter->first.metahandle == metahandle) { - if (!iter->second.is_deleted) - result->insert(iter->first.key); - } - } -} - -void Directory::DeleteAllExtendedAttributes(WriteTransaction* trans, - int64 metahandle) { - AttributeKeySet keys; - GetExtendedAttributesList(trans, metahandle, &keys); - AttributeKeySet::iterator iter; - for (iter = keys.begin(); iter != keys.end(); ++iter) { - ExtendedAttributeKey key(metahandle, *iter); - MutableExtendedAttribute attribute(trans, GET_BY_HANDLE, key); - // This flags the attribute for deletion during SaveChanges. At that time - // any deleted attributes are purged from disk and memory. - attribute.delete_attribute(); - } -} - int64 Directory::unsynced_entity_count() const { ScopedKernelLock lock(this); return kernel_->unsynced_metahandles->size(); @@ -1096,20 +1021,6 @@ const string& Entry::Get(StringField field) const { return kernel_->ref(field); } -void Entry::GetAllExtendedAttributes(BaseTransaction* trans, - std::set<ExtendedAttribute> *result) { - dir()->GetAllExtendedAttributes(trans, kernel_->ref(META_HANDLE), result); -} - -void Entry::GetExtendedAttributesList(BaseTransaction* trans, - AttributeKeySet* result) { - dir()->GetExtendedAttributesList(trans, kernel_->ref(META_HANDLE), result); -} - -void Entry::DeleteAllExtendedAttributes(WriteTransaction *trans) { - dir()->DeleteAllExtendedAttributes(trans, kernel_->ref(META_HANDLE)); -} - syncable::ModelType Entry::GetServerModelType() const { ModelType specifics_type = GetModelTypeFromSpecifics(Get(SERVER_SPECIFICS)); if (specifics_type != UNSPECIFIED) @@ -1492,41 +1403,6 @@ Id Directory::GetLastChildId(BaseTransaction* trans, return GetChildWithNullIdField(NEXT_ID, trans, parent_id); } -ExtendedAttribute::ExtendedAttribute(BaseTransaction* trans, GetByHandle, - const ExtendedAttributeKey& key) { - Directory::Kernel* const kernel = trans->directory()->kernel_; - ScopedKernelLock lock(trans->directory()); - Init(trans, kernel, &lock, key); -} - -bool ExtendedAttribute::Init(BaseTransaction* trans, - Directory::Kernel* const kernel, - ScopedKernelLock* lock, - const ExtendedAttributeKey& key) { - i_ = kernel->extended_attributes->find(key); - good_ = kernel->extended_attributes->end() != i_; - return good_; -} - -MutableExtendedAttribute::MutableExtendedAttribute( - WriteTransaction* trans, GetByHandle, - const ExtendedAttributeKey& key) : - ExtendedAttribute(trans, GET_BY_HANDLE, key) { -} - -MutableExtendedAttribute::MutableExtendedAttribute( - WriteTransaction* trans, Create, const ExtendedAttributeKey& key) { - Directory::Kernel* const kernel = trans->directory()->kernel_; - ScopedKernelLock lock(trans->directory()); - if (!Init(trans, kernel, &lock, key)) { - ExtendedAttributeValue val; - val.is_deleted = false; - val.dirty = true; - i_ = kernel->extended_attributes->insert(std::make_pair(key, val)).first; - good_ = true; - } -} - bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, const Id& new_parent_id) { if (entry_id.IsRoot()) @@ -1543,15 +1419,6 @@ bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, return true; } -const Blob* GetExtendedAttributeValue(const Entry& e, - const string& attribute_name) { - ExtendedAttributeKey key(e.Get(META_HANDLE), attribute_name); - ExtendedAttribute extended_attribute(e.trans(), GET_BY_HANDLE, key); - if (extended_attribute.good() && !extended_attribute.is_deleted()) - return &extended_attribute.value(); - return NULL; -} - // This function sets only the flags needed to get this entry to sync. void MarkForSyncing(syncable::MutableEntry* e) { DCHECK_NE(static_cast<MutableEntry*>(NULL), e); diff --git a/chrome/browser/sync/syncable/syncable.h b/chrome/browser/sync/syncable/syncable.h index c3ad2e9..fc5f33f 100644 --- a/chrome/browser/sync/syncable/syncable.h +++ b/chrome/browser/sync/syncable/syncable.h @@ -182,7 +182,6 @@ class WriteTransaction; class ReadTransaction; class Directory; class ScopedDirLookup; -class ExtendedAttribute; // Instead of: // Entry e = transaction.GetById(id); @@ -417,13 +416,6 @@ class Entry { return kernel_->ref(ID).IsRoot(); } - void GetAllExtendedAttributes(BaseTransaction* trans, - std::set<ExtendedAttribute>* result); - void GetExtendedAttributesList(BaseTransaction* trans, - AttributeKeySet* result); - // Flags all extended attributes for deletion on the next SaveChanges. - void DeleteAllExtendedAttributes(WriteTransaction *trans); - Directory* dir() const; const EntryKernel GetKernelCopy() const { @@ -606,27 +598,6 @@ struct DirectoryChangeEvent { } }; -struct ExtendedAttributeKey { - int64 metahandle; - std::string key; - inline bool operator < (const ExtendedAttributeKey& x) const { - if (metahandle != x.metahandle) - return metahandle < x.metahandle; - return key.compare(x.key) < 0; - } - ExtendedAttributeKey(int64 metahandle, const std::string& key) - : metahandle(metahandle), key(key) { } -}; - -struct ExtendedAttributeValue { - Blob value; - bool is_deleted; - bool dirty; -}; - -typedef std::map<ExtendedAttributeKey, ExtendedAttributeValue> - ExtendedAttributes; - // A list of metahandles whose metadata should not be purged. typedef std::multiset<int64> Pegs; @@ -661,9 +632,7 @@ struct PathMatcher; class Directory { friend class BaseTransaction; friend class Entry; - friend class ExtendedAttribute; friend class MutableEntry; - friend class MutableExtendedAttribute; friend class ReadTransaction; friend class ReadTransactionWithoutDB; friend class ScopedKernelLock; @@ -723,7 +692,6 @@ class Directory { KernelShareInfoStatus kernel_info_status; PersistedKernelInfo kernel_info; OriginalEntries dirty_metas; - ExtendedAttributes dirty_xattrs; SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { } }; @@ -866,14 +834,6 @@ class Directory { void GetUnappliedUpdateMetaHandles(BaseTransaction* trans, UnappliedUpdateMetaHandles* result); - void GetAllExtendedAttributes(BaseTransaction* trans, int64 metahandle, - std::set<ExtendedAttribute>* result); - // Get all extended attribute keys associated with a metahandle - void GetExtendedAttributesList(BaseTransaction* trans, int64 metahandle, - AttributeKeySet* result); - // Flags all extended attributes for deletion on the next SaveChanges. - void DeleteAllExtendedAttributes(WriteTransaction* trans, int64 metahandle); - // Get the channel for post save notification, used by the syncer. inline Channel* channel() const { return kernel_->channel; @@ -1002,7 +962,6 @@ class Directory { // So we don't have to create an EntryKernel every time we want to // look something up in an index. Needle in haystack metaphor. EntryKernel needle; - ExtendedAttributes* const extended_attributes; // 3 in-memory indices on bits used extremely frequently by the syncer. MetahandleSet* const unapplied_update_metahandles; @@ -1135,54 +1094,6 @@ int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, int64 Now(); -class ExtendedAttribute { - public: - ExtendedAttribute(BaseTransaction* trans, GetByHandle, - const ExtendedAttributeKey& key); - int64 metahandle() const { return i_->first.metahandle; } - const std::string& key() const { return i_->first.key; } - const Blob& value() const { return i_->second.value; } - bool is_deleted() const { return i_->second.is_deleted; } - bool good() const { return good_; } - bool operator < (const ExtendedAttribute& x) const { - return i_->first < x.i_->first; - } - protected: - bool Init(BaseTransaction* trans, - Directory::Kernel* const kernel, - ScopedKernelLock* lock, - const ExtendedAttributeKey& key); - ExtendedAttribute() { } - ExtendedAttributes::iterator i_; - bool good_; -}; - -class MutableExtendedAttribute : public ExtendedAttribute { - public: - MutableExtendedAttribute(WriteTransaction* trans, GetByHandle, - const ExtendedAttributeKey& key); - MutableExtendedAttribute(WriteTransaction* trans, Create, - const ExtendedAttributeKey& key); - - Blob* mutable_value() { - i_->second.dirty = true; - i_->second.is_deleted = false; - return &(i_->second.value); - } - - void delete_attribute() { - i_->second.dirty = true; - i_->second.is_deleted = true; - } -}; - -// Get an extended attribute from an Entry by name. Returns a pointer -// to a const Blob containing the attribute data, or NULL if there is -// no attribute with the given name. The pointer is valid for the -// duration of the Entry's transaction. -const Blob* GetExtendedAttributeValue(const Entry& e, - const std::string& attribute_name); - // This function sets only the flags needed to get this entry to sync. void MarkForSyncing(syncable::MutableEntry* e); diff --git a/chrome/browser/sync/syncable/syncable_unittest.cc b/chrome/browser/sync/syncable/syncable_unittest.cc index 43bb5a9..809a47c 100644 --- a/chrome/browser/sync/syncable/syncable_unittest.cc +++ b/chrome/browser/sync/syncable/syncable_unittest.cc @@ -47,28 +47,27 @@ using std::string; namespace syncable { namespace { -// A lot of these tests were written expecting to be able to read and write -// object data on entries. However, the design has changed. -void PutDataAsExtendedAttribute(WriteTransaction* wtrans, - MutableEntry* e, - const char* bytes, - size_t bytes_length) { - ExtendedAttributeKey key(e->Get(META_HANDLE), "DATA"); - MutableExtendedAttribute attr(wtrans, CREATE, key); - Blob bytes_blob(bytes, bytes + bytes_length); - attr.mutable_value()->swap(bytes_blob); +void PutDataAsBookmarkFavicon(WriteTransaction* wtrans, + MutableEntry* e, + const char* bytes, + size_t bytes_length) { + sync_pb::EntitySpecifics specifics; + specifics.MutableExtension(sync_pb::bookmark)->set_url("http://demo/"); + specifics.MutableExtension(sync_pb::bookmark)->set_favicon(bytes, + bytes_length); + e->Put(SPECIFICS, specifics); } -void ExpectDataFromExtendedAttributeEquals(BaseTransaction* trans, - Entry* e, - const char* bytes, - size_t bytes_length) { +void ExpectDataFromBookmarkFaviconEquals(BaseTransaction* trans, + Entry* e, + const char* bytes, + size_t bytes_length) { ASSERT_TRUE(e->good()); - Blob expected_value(bytes, bytes + bytes_length); - ExtendedAttributeKey key(e->Get(META_HANDLE), "DATA"); - ExtendedAttribute attr(trans, GET_BY_HANDLE, key); - EXPECT_FALSE(attr.is_deleted()); - EXPECT_EQ(expected_value, attr.value()); + ASSERT_TRUE(e->Get(SPECIFICS).HasExtension(sync_pb::bookmark)); + ASSERT_EQ("http://demo/", + e->Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); + ASSERT_EQ(std::string(bytes, bytes_length), + e->Get(SPECIFICS).GetExtension(sync_pb::bookmark).favicon()); } } // namespace @@ -138,7 +137,7 @@ TEST_F(SyncableGeneralTest, General) { WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); ASSERT_TRUE(e.good()); - PutDataAsExtendedAttribute(&trans, &e, s, sizeof(s)); + PutDataAsBookmarkFavicon(&trans, &e, s, sizeof(s)); } // Test reading back the contents that we just wrote. @@ -146,7 +145,7 @@ TEST_F(SyncableGeneralTest, General) { WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); ASSERT_TRUE(e.good()); - ExpectDataFromExtendedAttributeEquals(&trans, &e, s, sizeof(s)); + ExpectDataFromBookmarkFaviconEquals(&trans, &e, s, sizeof(s)); } // Verify it exists in the folder. @@ -1410,7 +1409,7 @@ class DirectoryKernelStalenessBugDelegate : public ThreadBugDelegate { MutableEntry me(&trans, CREATE, trans.root_id(), "Jeff"); me.Put(BASE_VERSION, 1); me.Put(ID, jeff_id); - PutDataAsExtendedAttribute(&trans, &me, test_bytes, + PutDataAsBookmarkFavicon(&trans, &me, test_bytes, sizeof(test_bytes)); } { @@ -1439,7 +1438,7 @@ class DirectoryKernelStalenessBugDelegate : public ThreadBugDelegate { CHECK(dir.good()); ReadTransaction trans(dir, __FILE__, __LINE__); Entry e(&trans, GET_BY_ID, jeff_id); - ExpectDataFromExtendedAttributeEquals(&trans, &e, test_bytes, + ExpectDataFromBookmarkFaviconEquals(&trans, &e, test_bytes, sizeof(test_bytes)); } // Same result as CloseAllDirectories, but more code coverage. @@ -1577,26 +1576,6 @@ void FakeSync(MutableEntry* e, const char* fake_id) { e->Put(ID, Id::CreateFromServerId(fake_id)); } -TEST_F(SyncableDirectoryTest, Bug1509232) { - const string a = "alpha"; - const Id entry_id = dir_.get()->NextId(); - CreateEntry(a, entry_id); - { - WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); - MutableEntry e(&trans, GET_BY_ID, entry_id); - ASSERT_TRUE(e.good()); - ExtendedAttributeKey key(e.Get(META_HANDLE), "resourcefork"); - MutableExtendedAttribute ext(&trans, CREATE, key); - ASSERT_TRUE(ext.good()); - const char value[] = "stuff"; - Blob value_blob(value, value + arraysize(value)); - ext.mutable_value()->swap(value_blob); - ext.delete_attribute(); - } - // This call to SaveChanges used to CHECK fail. - dir_.get()->SaveChanges(); -} - class SyncableClientTagTest : public SyncableDirectoryTest { public: static const int kBaseVersion = 1; |