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

Unified Diff: components/webdata/common/web_database_backend.cc

Issue 2225333003: Recreate the WebData database on a catastrophic SQL error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 4 years, 4 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
« no previous file with comments | « components/webdata/common/web_database_backend.h ('k') | components/webdata/common/web_database_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webdata/common/web_database_backend.cc
diff --git a/components/webdata/common/web_database_backend.cc b/components/webdata/common/web_database_backend.cc
index 1408bd2b9d8613ab61a2fbae136ff58bd7375a7e..a4446061f91307de7084ab03a4376ef5f0adfad7 100644
--- a/components/webdata/common/web_database_backend.cc
+++ b/components/webdata/common/web_database_backend.cc
@@ -41,32 +41,6 @@ void WebDatabaseBackend::InitDatabase() {
}
}
-sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() {
- if (init_complete_ || db_path_.empty()) {
- return init_status_;
- }
- init_complete_ = true;
- db_.reset(new WebDatabase());
-
- for (const auto& table : tables_)
- db_->AddTable(table);
-
- // Unretained to avoid a ref loop since we own |db_|.
- db_->set_error_callback(base::Bind(&WebDatabaseBackend::DatabaseErrorCallback,
- base::Unretained(this)));
- diagnostics_.clear();
- init_status_ = db_->Init(db_path_);
- if (init_status_ != sql::INIT_OK) {
- LOG(ERROR) << "Cannot initialize the web database: " << init_status_;
- diagnostics_ += sql::GetCorruptFileDiagnosticsInfo(db_path_);
- db_.reset();
- return init_status_;
- }
-
- db_->BeginTransaction();
- return init_status_;
-}
-
void WebDatabaseBackend::ShutdownDatabase() {
if (db_ && init_status_ == sql::INIT_OK)
db_->CommitTransaction();
@@ -118,12 +92,47 @@ WebDatabaseBackend::~WebDatabaseBackend() {
ShutdownDatabase();
}
+void WebDatabaseBackend::LoadDatabaseIfNecessary() {
+ if (init_complete_ || db_path_.empty())
+ return;
+
+ init_complete_ = true;
+ db_.reset(new WebDatabase());
+
+ for (const auto& table : tables_)
+ db_->AddTable(table);
+
+ // Unretained to avoid a ref loop since we own |db_|.
+ db_->set_error_callback(base::Bind(&WebDatabaseBackend::DatabaseErrorCallback,
+ base::Unretained(this)));
+ diagnostics_.clear();
+ catastrophic_error_occurred_ = false;
+ init_status_ = db_->Init(db_path_);
+
+ if (init_status_ != sql::INIT_OK) {
+ LOG(ERROR) << "Cannot initialize the web database: " << init_status_;
+ db_.reset();
+ return;
+ }
+
+ // A catastrophic error might have happened and recovered.
+ if (catastrophic_error_occurred_) {
+ init_status_ = sql::INIT_OK_WITH_DATA_LOSS;
+ LOG(WARNING)
+ << "Webdata recovered from a catastrophic error. Data loss possible.";
+ }
+ db_->BeginTransaction();
+}
+
void WebDatabaseBackend::DatabaseErrorCallback(int error,
sql::Statement* statement) {
// We ignore any further error callbacks after the first catastrophic error.
if (!catastrophic_error_occurred_ && sql::IsErrorCatastrophic(error)) {
catastrophic_error_occurred_ = true;
diagnostics_ = db_->GetDiagnosticInfo(error, statement);
+ diagnostics_ += sql::GetCorruptFileDiagnosticsInfo(db_path_);
+
+ db_->GetSQLConnection()->RazeAndClose();
}
}
« no previous file with comments | « components/webdata/common/web_database_backend.h ('k') | components/webdata/common/web_database_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698