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

Side by Side Diff: sync/syncable/directory_backing_store.h

Issue 11441026: [Sync] Add support for loading, updating and querying delete journals in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make IsDeleteJournalEnabled() public Created 8 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Loads and drops all currently persisted meta entries into |entry_bucket| 49 // Loads and drops all currently persisted meta entries into |entry_bucket|
50 // and loads appropriate persisted kernel info into |info_bucket|. 50 // and loads appropriate persisted kernel info into |info_bucket|.
51 // 51 //
52 // This function can perform some cleanup tasks behind the scenes. It will 52 // This function can perform some cleanup tasks behind the scenes. It will
53 // clean up unused entries from the database and migrate to the latest 53 // clean up unused entries from the database and migrate to the latest
54 // database version. The caller can safely ignore these details. 54 // database version. The caller can safely ignore these details.
55 // 55 //
56 // NOTE: On success (return value of OPENED), the buckets are populated with 56 // NOTE: On success (return value of OPENED), the buckets are populated with
57 // newly allocated items, meaning ownership is bestowed upon the caller. 57 // newly allocated items, meaning ownership is bestowed upon the caller.
58 virtual DirOpenResult Load(MetahandlesIndex* entry_bucket, 58 virtual DirOpenResult Load(MetahandlesIndex* entry_bucket,
59 JournalIndex* delete_journals,
59 Directory::KernelLoadInfo* kernel_load_info) = 0; 60 Directory::KernelLoadInfo* kernel_load_info) = 0;
60 61
61 // Updates the on-disk store with the input |snapshot| as a database 62 // Updates the on-disk store with the input |snapshot| as a database
62 // transaction. Does NOT open any syncable transactions as this would cause 63 // transaction. Does NOT open any syncable transactions as this would cause
63 // opening transactions elsewhere to block on synchronous I/O. 64 // opening transactions elsewhere to block on synchronous I/O.
64 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread 65 // DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread
65 // calls SaveChanges *must* be the thread that owns/destroys |this|. 66 // calls SaveChanges *must* be the thread that owns/destroys |this|.
66 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot); 67 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot);
67 68
68 protected: 69 protected:
(...skipping 18 matching lines...) Expand all
87 bool CreateV75ModelsTable(); 88 bool CreateV75ModelsTable();
88 89
89 // We don't need to load any synced and applied deleted entries, we can 90 // We don't need to load any synced and applied deleted entries, we can
90 // in fact just purge them forever on startup. 91 // in fact just purge them forever on startup.
91 bool DropDeletedEntries(); 92 bool DropDeletedEntries();
92 // Drops a table if it exists, harmless if the table did not already exist. 93 // Drops a table if it exists, harmless if the table did not already exist.
93 bool SafeDropTable(const char* table_name); 94 bool SafeDropTable(const char* table_name);
94 95
95 // Load helpers for entries and attributes. 96 // Load helpers for entries and attributes.
96 bool LoadEntries(MetahandlesIndex* entry_bucket); 97 bool LoadEntries(MetahandlesIndex* entry_bucket);
98 bool LoadDeleteJournals(JournalIndex* delete_journals);
97 bool LoadInfo(Directory::KernelLoadInfo* info); 99 bool LoadInfo(Directory::KernelLoadInfo* info);
98 100
99 // Save/update helpers for entries. Return false if sqlite commit fails. 101 // Save/update helpers for entries. Return false if sqlite commit fails.
100 bool SaveEntryToDB(const EntryKernel& entry); 102 static bool SaveEntryToDB(sql::Statement* save_statement,
103 const EntryKernel& entry);
101 bool SaveNewEntryToDB(const EntryKernel& entry); 104 bool SaveNewEntryToDB(const EntryKernel& entry);
102 bool UpdateEntryToDB(const EntryKernel& entry); 105 bool UpdateEntryToDB(const EntryKernel& entry);
103 106
104 DirOpenResult DoLoad(MetahandlesIndex* entry_bucket, 107 DirOpenResult DoLoad(MetahandlesIndex* entry_bucket,
105 Directory::KernelLoadInfo* kernel_load_info); 108 Directory::KernelLoadInfo* kernel_load_info);
106 109
107 // Close save_dbhandle_. Broken out for testing. 110 // Close save_dbhandle_. Broken out for testing.
108 void EndSave(); 111 void EndSave();
109 112
110 // Removes each entry whose metahandle is in |handles| from the database. 113 enum EntryTable {
111 // Does synchronous I/O. Returns false on error. 114 METAS_TABLE,
112 bool DeleteEntries(const MetahandleSet& handles); 115 DELETE_JOURNAL_TABLE,
116 };
117 // Removes each entry whose metahandle is in |handles| from the table
118 // specified by |from| table. Does synchronous I/O. Returns false on error.
119 bool DeleteEntries(EntryTable from, const MetahandleSet& handles);
113 120
114 // Drop all tables in preparation for reinitialization. 121 // Drop all tables in preparation for reinitialization.
115 void DropAllTables(); 122 void DropAllTables();
116 123
117 // Serialization helpers for ModelType. These convert between 124 // Serialization helpers for ModelType. These convert between
118 // the ModelType enum and the values we persist in the database to identify 125 // the ModelType enum and the values we persist in the database to identify
119 // a model. We persist a default instance of the specifics protobuf as the 126 // a model. We persist a default instance of the specifics protobuf as the
120 // ID, rather than the enum value. 127 // ID, rather than the enum value.
121 static ModelType ModelIdToModelTypeEnum(const void* data, int length); 128 static ModelType ModelIdToModelTypeEnum(const void* data, int length);
122 static std::string ModelTypeEnumToModelId(ModelType model_type); 129 static std::string ModelTypeEnumToModelId(ModelType model_type);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool MigrateVersion77To78(); 164 bool MigrateVersion77To78();
158 bool MigrateVersion78To79(); 165 bool MigrateVersion78To79();
159 bool MigrateVersion79To80(); 166 bool MigrateVersion79To80();
160 bool MigrateVersion80To81(); 167 bool MigrateVersion80To81();
161 bool MigrateVersion81To82(); 168 bool MigrateVersion81To82();
162 bool MigrateVersion82To83(); 169 bool MigrateVersion82To83();
163 bool MigrateVersion83To84(); 170 bool MigrateVersion83To84();
164 bool MigrateVersion84To85(); 171 bool MigrateVersion84To85();
165 172
166 scoped_ptr<sql::Connection> db_; 173 scoped_ptr<sql::Connection> db_;
167 sql::Statement save_entry_statement_; 174 sql::Statement save_meta_statment_;
175 sql::Statement save_delete_journal_statment_;
168 std::string dir_name_; 176 std::string dir_name_;
169 177
170 // Set to true if migration left some old columns around that need to be 178 // Set to true if migration left some old columns around that need to be
171 // discarded. 179 // discarded.
172 bool needs_column_refresh_; 180 bool needs_column_refresh_;
173 181
182 private:
183 // Helper function for loading entries from specified table.
184 template<class T>
185 bool LoadEntriesInternal(const std::string& table, T* bucket);
186
187 // Prepares |save_statement| for saving entries in |table|.
188 void PrepareSaveEntryStatement(EntryTable table,
189 sql::Statement* save_statement);
190
174 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore); 191 DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore);
175 }; 192 };
176 193
177 } // namespace syncable 194 } // namespace syncable
178 } // namespace syncer 195 } // namespace syncer
179 196
180 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_ 197 #endif // SYNC_SYNCABLE_DIRECTORY_BACKING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698