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

Unified Diff: sync/syncable/directory_backing_store.cc

Issue 1072093002: [Sync] Update DirectoryBackingStore to detect Sync DB corruption (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. 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.cc
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc
index 514ed8dcf002ab351263536155e5e4ad32b364a2..a7eda74e4147455c117cb5836667d40b1463c8bc 100644
--- a/sync/syncable/directory_backing_store.cc
+++ b/sync/syncable/directory_backing_store.cc
@@ -13,9 +13,11 @@
#include "base/metrics/field_trial.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
+#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "sql/connection.h"
+#include "sql/error_delegate_util.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "sync/internal_api/public/base/node_ordinal.h"
@@ -36,6 +38,20 @@ bool IsSyncBackingDatabase32KEnabled() {
return group_name == "Enabled";
}
+void OnSqliteError(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ const base::Closure& catastrophic_error_handler,
+ int err,
+ sql::Statement* statement) {
+ // An error has been detected. Ignore unless it is catastrophic.
+ if (sql::IsErrorCatastrophic(err)) {
+ // At this point sql::* and DirectoryBackingStore may be on the callstack so
+ // don't invoke the error handler directly. Instead, PostTask to this thread
+ // to avoid potential reentrancy issues.
+ task_runner->PostTask(FROM_HERE, catastrophic_error_handler);
Nicolas Zea 2015/04/13 20:16:33 nit: do you need the task runner? Can you just pos
maniscalco 2015/04/14 17:44:14 Good idea. Done.
+ }
+}
+
} // namespace
namespace syncer {
@@ -185,6 +201,7 @@ DirectoryBackingStore::DirectoryBackingStore(const string& dir_name)
: dir_name_(dir_name),
database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096),
needs_column_refresh_(false) {
+ DCHECK(base::ThreadTaskRunnerHandle::IsSet());
ResetAndCreateConnection();
}
@@ -194,6 +211,7 @@ DirectoryBackingStore::DirectoryBackingStore(const string& dir_name,
dir_name_(dir_name),
database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096),
needs_column_refresh_(false) {
+ DCHECK(base::ThreadTaskRunnerHandle::IsSet());
}
DirectoryBackingStore::~DirectoryBackingStore() {
@@ -1641,6 +1659,19 @@ void DirectoryBackingStore::ResetAndCreateConnection() {
db_->set_exclusive_locking();
db_->set_cache_size(32);
db_->set_page_size(database_page_size_);
+ if (!catastrophic_error_handler_.is_null())
+ SetCatastrophicErrorHandler(catastrophic_error_handler_);
+}
+
+void DirectoryBackingStore::SetCatastrophicErrorHandler(
+ const base::Closure& catastrophic_error_handler) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!catastrophic_error_handler.is_null());
+ catastrophic_error_handler_ = catastrophic_error_handler;
+ sql::Connection::ErrorCallback error_callback =
+ base::Bind(&OnSqliteError, base::ThreadTaskRunnerHandle::Get(),
+ catastrophic_error_handler_);
+ db_->set_error_callback(error_callback);
}
} // namespace syncable

Powered by Google App Engine
This is Rietveld 408576698