OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
6 #define CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 6 #define CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // SaveChanges is called a new sqlite3 handle is created, and it will get closed | 52 // SaveChanges is called a new sqlite3 handle is created, and it will get closed |
53 // when the DBS is destroyed, which is the reason for the requirement that the | 53 // when the DBS is destroyed, which is the reason for the requirement that the |
54 // thread that "uses" the DBS is the thread that destroys it. | 54 // thread that "uses" the DBS is the thread that destroys it. |
55 class DirectoryBackingStore { | 55 class DirectoryBackingStore { |
56 public: | 56 public: |
57 DirectoryBackingStore(const std::string& dir_name, | 57 DirectoryBackingStore(const std::string& dir_name, |
58 const FilePath& backing_filepath); | 58 const FilePath& backing_filepath); |
59 | 59 |
60 virtual ~DirectoryBackingStore(); | 60 virtual ~DirectoryBackingStore(); |
61 | 61 |
62 // Loads and drops all currently persisted meta entries into | 62 // Loads and drops all currently persisted meta entries into |entry_bucket| |
63 // |entry_bucket|, all currently persisted xattrs in |xattrs_bucket|, | 63 // and loads appropriate persisted kernel info into |info_bucket|. |
64 // and loads appropriate persisted kernel info in |info_bucket|. | |
65 // NOTE: On success (return value of OPENED), the buckets are populated with | 64 // NOTE: On success (return value of OPENED), the buckets are populated with |
66 // newly allocated items, meaning ownership is bestowed upon the caller. | 65 // newly allocated items, meaning ownership is bestowed upon the caller. |
67 DirOpenResult Load(MetahandlesIndex* entry_bucket, | 66 DirOpenResult Load(MetahandlesIndex* entry_bucket, |
68 ExtendedAttributes* xattrs_bucket, | |
69 Directory::KernelLoadInfo* kernel_load_info); | 67 Directory::KernelLoadInfo* kernel_load_info); |
70 | 68 |
71 // Updates the on-disk store with the input |snapshot| as a database | 69 // Updates the on-disk store with the input |snapshot| as a database |
72 // transaction. Does NOT open any syncable transactions as this would cause | 70 // transaction. Does NOT open any syncable transactions as this would cause |
73 // opening transactions elsewhere to block on synchronous I/O. | 71 // opening transactions elsewhere to block on synchronous I/O. |
74 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread | 72 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread |
75 // calls SaveChanges *must* be the thread that owns/destroys |this|. | 73 // calls SaveChanges *must* be the thread that owns/destroys |this|. |
76 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot); | 74 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot); |
77 | 75 |
78 private: | 76 private: |
79 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion67To68); | 77 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion67To68); |
80 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion68To69); | 78 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion68To69); |
81 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion69To70); | 79 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion69To70); |
82 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion70To71); | 80 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion70To71); |
| 81 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, MigrateVersion71To72); |
83 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, ModelTypeIds); | 82 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, ModelTypeIds); |
84 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, Corruption); | 83 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, Corruption); |
85 FRIEND_TEST_ALL_PREFIXES(DirectoryBackingStoreTest, DeleteEntries); | |
86 FRIEND_TEST_ALL_PREFIXES(MigrationTest, ToCurrentVersion); | 84 FRIEND_TEST_ALL_PREFIXES(MigrationTest, ToCurrentVersion); |
87 friend class MigrationTest; | 85 friend class MigrationTest; |
88 | 86 |
89 // General Directory initialization and load helpers. | 87 // General Directory initialization and load helpers. |
90 DirOpenResult InitializeTables(); | 88 DirOpenResult InitializeTables(); |
91 // Returns an sqlite return code, usually SQLITE_DONE. | 89 // Returns an sqlite return code, usually SQLITE_DONE. |
92 int CreateTables(); | 90 int CreateTables(); |
93 | 91 |
94 // Create 'share_info' or 'temp_share_info' depending on value of | 92 // Create 'share_info' or 'temp_share_info' depending on value of |
95 // is_temporary. Returns an sqlite return code, SQLITE_DONE on success. | 93 // is_temporary. Returns an sqlite return code, SQLITE_DONE on success. |
96 int CreateShareInfoTable(bool is_temporary); | 94 int CreateShareInfoTable(bool is_temporary); |
97 // Create 'metas' or 'temp_metas' depending on value of is_temporary. | 95 // Create 'metas' or 'temp_metas' depending on value of is_temporary. |
98 // Returns an sqlite return code, SQLITE_DONE on success. | 96 // Returns an sqlite return code, SQLITE_DONE on success. |
99 int CreateMetasTable(bool is_temporary); | 97 int CreateMetasTable(bool is_temporary); |
100 // Returns an sqlite return code, SQLITE_DONE on success. | 98 // Returns an sqlite return code, SQLITE_DONE on success. |
101 int CreateModelsTable(); | 99 int CreateModelsTable(); |
102 // Returns an sqlite return code, SQLITE_DONE on success. | |
103 int CreateExtendedAttributeTable(); | |
104 | 100 |
105 // We don't need to load any synced and applied deleted entries, we can | 101 // We don't need to load any synced and applied deleted entries, we can |
106 // in fact just purge them forever on startup. | 102 // in fact just purge them forever on startup. |
107 bool DropDeletedEntries(); | 103 bool DropDeletedEntries(); |
108 // Drops a table if it exists, harmless if the table did not already exist. | 104 // Drops a table if it exists, harmless if the table did not already exist. |
109 int SafeDropTable(const char* table_name); | 105 int SafeDropTable(const char* table_name); |
110 | 106 |
111 // Load helpers for entries and attributes. | 107 // Load helpers for entries and attributes. |
112 bool LoadEntries(MetahandlesIndex* entry_bucket); | 108 bool LoadEntries(MetahandlesIndex* entry_bucket); |
113 bool LoadExtendedAttributes(ExtendedAttributes* xattrs_bucket); | |
114 bool LoadInfo(Directory::KernelLoadInfo* info); | 109 bool LoadInfo(Directory::KernelLoadInfo* info); |
115 | 110 |
116 // Save/update helpers for entries. Return false if sqlite commit fails. | 111 // Save/update helpers for entries. Return false if sqlite commit fails. |
117 bool SaveEntryToDB(const EntryKernel& entry); | 112 bool SaveEntryToDB(const EntryKernel& entry); |
118 bool SaveNewEntryToDB(const EntryKernel& entry); | 113 bool SaveNewEntryToDB(const EntryKernel& entry); |
119 bool UpdateEntryToDB(const EntryKernel& entry); | 114 bool UpdateEntryToDB(const EntryKernel& entry); |
120 | 115 |
121 // Save/update helpers for attributes. Return false if sqlite commit fails. | |
122 bool SaveExtendedAttributeToDB(ExtendedAttributes::const_iterator i); | |
123 bool DeleteExtendedAttributeFromDB(ExtendedAttributes::const_iterator i); | |
124 | |
125 // Creates a new sqlite3 handle to the backing database. Sets sqlite operation | 116 // Creates a new sqlite3 handle to the backing database. Sets sqlite operation |
126 // timeout preferences and registers our overridden sqlite3 operators for | 117 // timeout preferences and registers our overridden sqlite3 operators for |
127 // said handle. Returns true on success, false if the sqlite open operation | 118 // said handle. Returns true on success, false if the sqlite open operation |
128 // did not succeed. | 119 // did not succeed. |
129 bool OpenAndConfigureHandleHelper(sqlite3** handle) const; | 120 bool OpenAndConfigureHandleHelper(sqlite3** handle) const; |
130 // Initialize and destroy load_dbhandle_. Broken out for testing. | 121 // Initialize and destroy load_dbhandle_. Broken out for testing. |
131 bool BeginLoad(); | 122 bool BeginLoad(); |
132 void EndLoad(); | 123 void EndLoad(); |
133 | 124 |
134 // Lazy creation of save_dbhandle_ for use by SaveChanges code path. | 125 // Lazy creation of save_dbhandle_ for use by SaveChanges code path. |
(...skipping 19 matching lines...) Expand all Loading... |
154 void(*handler_function) ( | 145 void(*handler_function) ( |
155 SQLStatement* old_value_query, | 146 SQLStatement* old_value_query, |
156 int old_value_column, | 147 int old_value_column, |
157 sync_pb::EntitySpecifics* mutable_new_value)); | 148 sync_pb::EntitySpecifics* mutable_new_value)); |
158 | 149 |
159 // Individual version migrations. | 150 // Individual version migrations. |
160 bool MigrateVersion67To68(); | 151 bool MigrateVersion67To68(); |
161 bool MigrateVersion68To69(); | 152 bool MigrateVersion68To69(); |
162 bool MigrateVersion69To70(); | 153 bool MigrateVersion69To70(); |
163 bool MigrateVersion70To71(); | 154 bool MigrateVersion70To71(); |
| 155 bool MigrateVersion71To72(); |
164 | 156 |
165 // The handle to our sqlite on-disk store for initialization and loading, and | 157 // The handle to our sqlite on-disk store for initialization and loading, and |
166 // for saving changes periodically via SaveChanges, respectively. | 158 // for saving changes periodically via SaveChanges, respectively. |
167 // TODO(timsteele): We should only have one handle here. The reason we need | 159 // TODO(timsteele): We should only have one handle here. The reason we need |
168 // two at the moment is because the DB can be opened by either the AuthWatcher | 160 // two at the moment is because the DB can be opened by either the AuthWatcher |
169 // or SyncCore threads, but SaveChanges is always called by the latter. We | 161 // or SyncCore threads, but SaveChanges is always called by the latter. We |
170 // need to change initialization so the DB is only accessed from one thread. | 162 // need to change initialization so the DB is only accessed from one thread. |
171 sqlite3* load_dbhandle_; | 163 sqlite3* load_dbhandle_; |
172 sqlite3* save_dbhandle_; | 164 sqlite3* save_dbhandle_; |
173 | 165 |
174 std::string dir_name_; | 166 std::string dir_name_; |
175 FilePath backing_filepath_; | 167 FilePath backing_filepath_; |
176 | 168 |
177 // Set to true if migration left some old columns around that need to be | 169 // Set to true if migration left some old columns around that need to be |
178 // discarded. | 170 // discarded. |
179 bool needs_column_refresh_; | 171 bool needs_column_refresh_; |
180 | 172 |
181 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); | 173 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); |
182 }; | 174 }; |
183 | 175 |
184 } // namespace syncable | 176 } // namespace syncable |
185 | 177 |
186 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ | 178 #endif // CHROME_BROWSER_SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ |
OLD | NEW |