Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 5 #ifndef SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
| 6 #define SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 6 #define SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 // The DirectoryBackingStore will own an sqlite lock on its database for most of | 37 // The DirectoryBackingStore will own an sqlite lock on its database for most of |
| 38 // its lifetime. You must not have two DirectoryBackingStore objects accessing | 38 // its lifetime. You must not have two DirectoryBackingStore objects accessing |
| 39 // the database simultaneously. Because the lock exists at the database level, | 39 // the database simultaneously. Because the lock exists at the database level, |
| 40 // not even two separate browser instances would be able to acquire it | 40 // not even two separate browser instances would be able to acquire it |
| 41 // simultaneously. | 41 // simultaneously. |
| 42 // | 42 // |
| 43 // This class is abstract so that we can extend it in interesting ways for use | 43 // This class is abstract so that we can extend it in interesting ways for use |
| 44 // in tests. The concrete class used in non-test scenarios is | 44 // in tests. The concrete class used in non-test scenarios is |
| 45 // OnDiskDirectoryBackingStore. | 45 // OnDiskDirectoryBackingStore. |
| 46 class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { | 46 class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe { |
| 47 friend class TestDirectoryBackingStore; | |
|
maniscalco
2015/04/15 18:10:43
TestDirectoryBackingStore is friend so it can .rel
Nicolas Zea
2015/04/16 15:56:33
nit: these should all be within the private: secti
maniscalco
2015/04/16 16:03:45
Done.
| |
| 47 friend class DirectoryBackingStoreTest; | 48 friend class DirectoryBackingStoreTest; |
| 48 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, | 49 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, |
| 49 IncreaseDatabasePageSizeFrom4KTo32K); | 50 IncreaseDatabasePageSizeFrom4KTo32K); |
| 50 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, | 51 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, |
| 51 CatastrophicErrorHandler_KeptAcrossReset); | 52 CatastrophicErrorHandler_KeptAcrossReset); |
| 52 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, | 53 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, |
| 53 CatastrophicErrorHandler_Invocation); | 54 CatastrophicErrorHandler_Invocation); |
| 54 | 55 |
| 55 public: | 56 public: |
| 56 explicit DirectoryBackingStore(const std::string& dir_name); | 57 explicit DirectoryBackingStore(const std::string& dir_name); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 // already a handler, the existing handler is overwritten with | 100 // already a handler, the existing handler is overwritten with |
| 100 // |catastrophic_error_handler|. | 101 // |catastrophic_error_handler|. |
| 101 virtual void SetCatastrophicErrorHandler( | 102 virtual void SetCatastrophicErrorHandler( |
| 102 const base::Closure& catastrophic_error_handler); | 103 const base::Closure& catastrophic_error_handler); |
| 103 | 104 |
| 104 protected: | 105 protected: |
| 105 // For test classes. | 106 // For test classes. |
| 106 DirectoryBackingStore(const std::string& dir_name, | 107 DirectoryBackingStore(const std::string& dir_name, |
| 107 sql::Connection* connection); | 108 sql::Connection* connection); |
| 108 | 109 |
| 110 // An accessor for the underlying sql::Connection. Avoid using outside of | |
| 111 // tests. | |
| 112 sql::Connection* db(); | |
| 113 | |
| 114 // Return true if the DB is open. | |
| 115 bool IsOpen() const; | |
| 116 | |
| 117 // Open the DB at |path|. | |
| 118 // Return true on success, false on failure. | |
| 119 bool Open(const base::FilePath& path); | |
| 120 | |
| 121 // Open an in memory DB. | |
| 122 // Return true on success, false on failure. | |
| 123 bool OpenInMemory(); | |
| 124 | |
| 109 // General Directory initialization and load helpers. | 125 // General Directory initialization and load helpers. |
| 110 bool InitializeTables(); | 126 bool InitializeTables(); |
| 111 bool CreateTables(); | 127 bool CreateTables(); |
| 112 | 128 |
| 113 // Create 'share_info' or 'temp_share_info' depending on value of | 129 // Create 'share_info' or 'temp_share_info' depending on value of |
| 114 // is_temporary. Returns an sqlite | 130 // is_temporary. Returns an sqlite |
| 115 bool CreateShareInfoTable(bool is_temporary); | 131 bool CreateShareInfoTable(bool is_temporary); |
| 116 | 132 |
| 117 bool CreateShareInfoTableVersion71(bool is_temporary); | 133 bool CreateShareInfoTableVersion71(bool is_temporary); |
| 118 // Create 'metas' or 'temp_metas' depending on value of is_temporary. Also | 134 // Create 'metas' or 'temp_metas' depending on value of is_temporary. Also |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 bool MigrateVersion86To87(); | 222 bool MigrateVersion86To87(); |
| 207 bool MigrateVersion87To88(); | 223 bool MigrateVersion87To88(); |
| 208 bool MigrateVersion88To89(); | 224 bool MigrateVersion88To89(); |
| 209 | 225 |
| 210 // Accessor for needs_column_refresh_. Used in tests. | 226 // Accessor for needs_column_refresh_. Used in tests. |
| 211 bool needs_column_refresh() const; | 227 bool needs_column_refresh() const; |
| 212 | 228 |
| 213 // Destroys the existing Connection and creates a new one. | 229 // Destroys the existing Connection and creates a new one. |
| 214 void ResetAndCreateConnection(); | 230 void ResetAndCreateConnection(); |
| 215 | 231 |
| 216 scoped_ptr<sql::Connection> db_; | |
| 217 | |
| 218 private: | 232 private: |
| 219 bool Vacuum(); | 233 bool Vacuum(); |
| 220 bool IncreasePageSizeTo32K(); | 234 bool IncreasePageSizeTo32K(); |
| 221 bool GetDatabasePageSize(int* page_size); | 235 bool GetDatabasePageSize(int* page_size); |
| 222 | 236 |
| 223 // Prepares |save_statement| for saving entries in |table|. | 237 // Prepares |save_statement| for saving entries in |table|. |
| 224 void PrepareSaveEntryStatement(EntryTable table, | 238 void PrepareSaveEntryStatement(EntryTable table, |
| 225 sql::Statement* save_statement); | 239 sql::Statement* save_statement); |
| 226 | 240 |
| 227 const std::string dir_name_; | 241 const std::string dir_name_; |
| 228 const int database_page_size_; | 242 const int database_page_size_; |
| 243 | |
| 244 scoped_ptr<sql::Connection> db_; | |
| 229 sql::Statement save_meta_statement_; | 245 sql::Statement save_meta_statement_; |
| 230 sql::Statement save_delete_journal_statement_; | 246 sql::Statement save_delete_journal_statement_; |
| 231 | 247 |
| 232 // Set to true if migration left some old columns around that need to be | 248 // Set to true if migration left some old columns around that need to be |
| 233 // discarded. | 249 // discarded. |
| 234 bool needs_column_refresh_; | 250 bool needs_column_refresh_; |
| 235 | 251 |
| 236 // We keep a copy of the Closure so we reinstall it when the underlying | 252 // We keep a copy of the Closure so we reinstall it when the underlying |
| 237 // sql::Connection is destroyed/recreated. | 253 // sql::Connection is destroyed/recreated. |
| 238 base::Closure catastrophic_error_handler_; | 254 base::Closure catastrophic_error_handler_; |
| 239 | 255 |
| 240 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); | 256 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); |
| 241 }; | 257 }; |
| 242 | 258 |
| 243 } // namespace syncable | 259 } // namespace syncable |
| 244 } // namespace syncer | 260 } // namespace syncer |
| 245 | 261 |
| 246 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 262 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
| OLD | NEW |