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

Unified Diff: sync/syncable/directory_backing_store.h

Issue 1072093002: [Sync] Update DirectoryBackingStore to detect Sync DB corruption (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply CR feedback. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: sync/syncable/directory_backing_store.h
diff --git a/sync/syncable/directory_backing_store.h b/sync/syncable/directory_backing_store.h
index 81add28ec358e2c4523b22584a44ccd9e3be0a45..bb3641f49c876e1bd80f1170e7ec15fffa3956cb 100644
--- a/sync/syncable/directory_backing_store.h
+++ b/sync/syncable/directory_backing_store.h
@@ -47,6 +47,10 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe {
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);
@@ -72,8 +76,31 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe {
// opening transactions elsewhere to block on synchronous I/O.
// DO NOT CALL THIS FROM MORE THAN ONE THREAD EVER. Also, whichever thread
// calls SaveChanges *must* be the thread that owns/destroys |this|.
+ //
+ // Returns true if the changes were saved successfully. Returns false if an
+ // error (of any kind) occurred. See also |SetCatastrophicErrorHandler| for a
+ // systematic way of handling underlying DB errors.
virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot);
+ // Set the catastrophic error handler.
+ //
+ // When a catastrophic error is encountered while accessing the underlying DB,
+ // |catastrophic_error_handler| will be invoked (via PostTask) on the thread
+ // on which this DirectoryBackingStore object lives.
+ //
+ // For a definition of what's catastrophic, see sql::IsErrorCatastrophic.
+ //
+ // |catastrophic_error_handler| must be initialized (i.e. !is_null()).
+ //
+ // A single operation (like Load or SaveChanges) may result in the
+ // |catastrophic_error_handler| being invoked several times.
+ //
+ // There can be at most one handler. If this method is invoked when there is
+ // already a handler, the existing handler is overwritten with
+ // |catastrophic_error_handler|.
+ virtual void SetCatastrophicErrorHandler(
+ const base::Closure& catastrophic_error_handler);
+
protected:
// For test classes.
DirectoryBackingStore(const std::string& dir_name,
@@ -206,6 +233,10 @@ class SYNC_EXPORT_PRIVATE DirectoryBackingStore : public base::NonThreadSafe {
// discarded.
bool needs_column_refresh_;
+ // We keep a copy of the Closure so we reinstall it when the underlying
+ // sql::Connection is destroyed/recreated.
+ base::Closure catastrophic_error_handler_;
+
DISALLOW_COPY_AND_ASSIGN(DirectoryBackingStore);
};
« no previous file with comments | « sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc ('k') | sync/syncable/directory_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698