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

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

Powered by Google App Engine
This is Rietveld 408576698