diff options
author | maniscalco <maniscalco@chromium.org> | 2015-04-17 10:22:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-17 17:22:52 +0000 |
commit | a3918ade366d69a50c0c7a65ee8215b87c61326a (patch) | |
tree | ef15cb72f179a00d199059f58d47519914d826cb /sync | |
parent | 9797abaa5b60464ee061ef0b55237e6f7a13d3dd (diff) | |
download | chromium_src-a3918ade366d69a50c0c7a65ee8215b87c61326a.zip chromium_src-a3918ade366d69a50c0c7a65ee8215b87c61326a.tar.gz chromium_src-a3918ade366d69a50c0c7a65ee8215b87c61326a.tar.bz2 |
[Sync] Make more of DirectoryBackingStore's methods private
This is a refactoring change with no changes in behavior. See bug for
related work.
Remove method declarations for unimplemented methods.
Collapse multiple anonymous namespaces into one.
Make SaveEntryToDB an anon scoped function instead of a static method.
Update documentation for some methods.
BUG=475557
Review URL: https://codereview.chromium.org/1085373002
Cr-Commit-Position: refs/heads/master@{#325659}
Diffstat (limited to 'sync')
-rw-r--r-- | sync/syncable/directory_backing_store.cc | 64 | ||||
-rw-r--r-- | sync/syncable/directory_backing_store.h | 104 |
2 files changed, 80 insertions, 88 deletions
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc index d6cb0e6c..29d2e8a 100644 --- a/sync/syncable/directory_backing_store.cc +++ b/sync/syncable/directory_backing_store.cc @@ -30,36 +30,9 @@ using std::string; -namespace { - -bool IsSyncBackingDatabase32KEnabled() { - const std::string group_name = - base::FieldTrialList::FindFullName("SyncBackingDatabase32K"); - return group_name == "Enabled"; -} - -void OnSqliteError(const base::Closure& catastrophic_error_handler, - int err, - sql::Statement* statement) { - // An error has been detected. Ignore unless it is catastrophic. - if (sql::IsErrorCatastrophic(err)) { - // At this point sql::* and DirectoryBackingStore may be on the callstack so - // don't invoke the error handler directly. Instead, PostTask to this thread - // to avoid potential reentrancy issues. - base::MessageLoop::current()->PostTask(FROM_HERE, - catastrophic_error_handler); - } -} - -} // namespace - namespace syncer { namespace syncable { -// This just has to be big enough to hold an UPDATE or INSERT statement that -// modifies all the columns in the entry table. -static const string::size_type kUpdateStatementBufferSize = 2048; - // Increment this version whenever updating DB tables. const int32 kCurrentDBVersion = 89; @@ -164,6 +137,29 @@ scoped_ptr<EntryKernel> UnpackEntry(sql::Statement* statement) { namespace { +// This just has to be big enough to hold an UPDATE or INSERT statement that +// modifies all the columns in the entry table. +static const string::size_type kUpdateStatementBufferSize = 2048; + +bool IsSyncBackingDatabase32KEnabled() { + const std::string group_name = + base::FieldTrialList::FindFullName("SyncBackingDatabase32K"); + return group_name == "Enabled"; +} + +void OnSqliteError(const base::Closure& catastrophic_error_handler, + int err, + sql::Statement* statement) { + // An error has been detected. Ignore unless it is catastrophic. + if (sql::IsErrorCatastrophic(err)) { + // At this point sql::* and DirectoryBackingStore may be on the callstack so + // don't invoke the error handler directly. Instead, PostTask to this thread + // to avoid potential reentrancy issues. + base::MessageLoop::current()->PostTask(FROM_HERE, + catastrophic_error_handler); + } +} + string ComposeCreateTableColumnSpecs() { const ColumnSpec* begin = g_metas_columns; const ColumnSpec* end = g_metas_columns + arraysize(g_metas_columns); @@ -191,6 +187,12 @@ void AppendColumnList(std::string* output) { } } +bool SaveEntryToDB(sql::Statement* save_statement, const EntryKernel& entry) { + save_statement->Reset(true); + BindFields(entry, save_statement); + return save_statement->Run(); +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -699,14 +701,6 @@ bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { return true; } -/* static */ -bool DirectoryBackingStore::SaveEntryToDB(sql::Statement* save_statement, - const EntryKernel& entry) { - save_statement->Reset(true); - BindFields(entry, save_statement); - return save_statement->Run(); -} - bool DirectoryBackingStore::SafeDropTable(const char* table_name) { string query = "DROP TABLE IF EXISTS "; query.append(table_name); diff --git a/sync/syncable/directory_backing_store.h b/sync/syncable/directory_backing_store.h index b3168aa..6d6efd4 100644 --- a/sync/syncable/directory_backing_store.h +++ b/sync/syncable/directory_backing_store.h @@ -44,15 +44,6 @@ struct ColumnSpec; // in tests. The concrete class used in non-test scenarios is // OnDiskDirectoryBackingStore. class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { - friend class TestDirectoryBackingStore; - friend class DirectoryBackingStoreTest; - FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, - IncreaseDatabasePageSizeFrom4KTo32K); - FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, - CatastrophicErrorHandler_KeptAcrossReset); - FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, - CatastrophicErrorHandler_Invocation); - public: explicit DirectoryBackingStore(const std::string& dir_name); virtual ~DirectoryBackingStore(); @@ -122,41 +113,15 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { // Return true on success, false on failure. bool OpenInMemory(); - // General Directory initialization and load helpers. + // Initialize database tables. Return true on success, false on error. bool InitializeTables(); - bool CreateTables(); - // Create 'share_info' or 'temp_share_info' depending on value of - // is_temporary. Returns an sqlite - bool CreateShareInfoTable(bool is_temporary); - - bool CreateShareInfoTableVersion71(bool is_temporary); - // Create 'metas' or 'temp_metas' depending on value of is_temporary. Also - // create a 'deleted_metas' table using same schema. - bool CreateMetasTable(bool is_temporary); - bool CreateModelsTable(); - bool CreateV71ModelsTable(); - bool CreateV75ModelsTable(); - bool CreateV81ModelsTable(); - - // Drops a table if it exists, harmless if the table did not already exist. - bool SafeDropTable(const char* table_name); - - // Load helpers for entries and attributes. + // Load helpers for entries and attributes. Return true on success, false on + // error. bool LoadEntries(Directory::MetahandlesMap* handles_map, MetahandleSet* metahandles_to_purge); bool LoadDeleteJournals(JournalIndex* delete_journals); bool LoadInfo(Directory::KernelLoadInfo* info); - bool SafeToPurgeOnLoading(const EntryKernel& entry) const; - - // Save/update helpers for entries. Return false if sqlite commit fails. - static bool SaveEntryToDB(sql::Statement* save_statement, - const EntryKernel& entry); - bool SaveNewEntryToDB(const EntryKernel& entry); - bool UpdateEntryToDB(const EntryKernel& entry); - - // Close save_dbhandle_. Broken out for testing. - void EndSave(); enum EntryTable { METAS_TABLE, @@ -166,9 +131,6 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { // specified by |from| table. Does synchronous I/O. Returns false on error. bool DeleteEntries(EntryTable from, const MetahandleSet& handles); - // Drop all tables in preparation for reinitialization. - void DropAllTables(); - // Serialization helpers for ModelType. These convert between // the ModelType enum and the values we persist in the database to identify // a model. We persist a default instance of the specifics protobuf as the @@ -178,11 +140,6 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { static std::string GenerateCacheGUID(); - // Runs an integrity check on the current database. If the - // integrity check fails, false is returned and error is populated - // with an error message. - bool CheckIntegrity(sqlite3* handle, std::string* error) const; - // Checks that the references between sync nodes is consistent. static bool VerifyReferenceIntegrity( const Directory::MetahandlesMap* handles_map); @@ -192,13 +149,6 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { bool SetVersion(int version); int GetVersion(); - bool MigrateToSpecifics(const char* old_columns, - const char* specifics_column, - void(*handler_function) ( - sql::Statement* old_value_query, - int old_value_column, - sync_pb::EntitySpecifics* mutable_new_value)); - // Individual version migrations. bool MigrateVersion67To68(); bool MigrateVersion68To69(); @@ -230,8 +180,56 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { void ResetAndCreateConnection(); private: + friend class TestDirectoryBackingStore; + friend class DirectoryBackingStoreTest; + FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, + IncreaseDatabasePageSizeFrom4KTo32K); + FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, + CatastrophicErrorHandler_KeptAcrossReset); + FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, + CatastrophicErrorHandler_Invocation); + + // Drop all tables in preparation for reinitialization. + void DropAllTables(); + + bool SafeToPurgeOnLoading(const EntryKernel& entry) const; + + // Drops a table if it exists, harmless if the table did not already exist. + bool SafeDropTable(const char* table_name); + + bool CreateTables(); + + // Create 'share_info' or 'temp_share_info' depending on value of + // is_temporary. Returns true on success, false on error. + bool CreateShareInfoTable(bool is_temporary); + bool CreateShareInfoTableVersion71(bool is_temporary); + + // Create 'metas' or 'temp_metas' depending on value of is_temporary. Also + // create a 'deleted_metas' table using same schema. Returns true on success, + // false on error. + bool CreateMetasTable(bool is_temporary); + + // Returns true on success, false on error. + bool CreateModelsTable(); + bool CreateV71ModelsTable(); + bool CreateV75ModelsTable(); + bool CreateV81ModelsTable(); + + // Returns true on success, false on error. + bool MigrateToSpecifics(const char* old_columns, + const char* specifics_column, + void(*handler_function) ( + sql::Statement* old_value_query, + int old_value_column, + sync_pb::EntitySpecifics* mutable_new_value)); + + // Returns true on success, false on error. bool Vacuum(); + + // Returns true on success, false on error. bool IncreasePageSizeTo32K(); + + // Returns true on success, false on error. bool GetDatabasePageSize(int* page_size); // Prepares |save_statement| for saving entries in |table|. |