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_; |
} |