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

Unified Diff: sync/syncable/directory.cc

Issue 1082893003: [Sync] Erase sync DB when corrupted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove an unnecessary include. 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.cc
diff --git a/sync/syncable/directory.cc b/sync/syncable/directory.cc
index 767b80770fc7a1d39ae9560caf8938023e2aafed..0f680d22ec50eaf0b9f62d5ba4a6e3910f09af6e 100644
--- a/sync/syncable/directory.cc
+++ b/sync/syncable/directory.cc
@@ -111,12 +111,12 @@ Directory::Directory(
: kernel_(NULL),
store_(store),
unrecoverable_error_handler_(unrecoverable_error_handler),
- report_unrecoverable_error_function_(
- report_unrecoverable_error_function),
+ report_unrecoverable_error_function_(report_unrecoverable_error_function),
unrecoverable_error_set_(false),
nigori_handler_(nigori_handler),
cryptographer_(cryptographer),
- invariant_check_level_(VERIFY_CHANGES) {
+ invariant_check_level_(VERIFY_CHANGES),
+ weak_ptr_factory_(this) {
}
Directory::~Directory() {
@@ -208,6 +208,12 @@ DirOpenResult Directory::OpenImpl(
if (!SaveChanges())
return FAILED_INITIAL_WRITE;
+ // Now that we've successfully opened the store, install an error handler to
+ // deal with catastrophic errors that may occur later on. Use a weak pointer
+ // because we cannot guarantee that this Directory will outlive the Closure.
+ store_->SetCatastrophicErrorHandler(base::Bind(
+ &Directory::OnCatastrophicError, weak_ptr_factory_.GetWeakPtr()));
+
return OPENED;
}
@@ -1554,6 +1560,12 @@ void Directory::GetAttachmentIdsToUpload(BaseTransaction* trans,
std::back_inserter(*ids));
}
+void Directory::OnCatastrophicError() {
+ ReadTransaction trans(FROM_HERE, this);
+ OnUnrecoverableError(&trans, FROM_HERE,
+ "Catastrophic error detected, Sync DB is unrecoverable");
+}
+
Directory::Kernel* Directory::kernel() {
return kernel_;
}

Powered by Google App Engine
This is Rietveld 408576698