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

Side by Side 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: derat's comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/webdata/common/web_database_backend.h" 5 #include "components/webdata/common/web_database_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 db_->AddTable(table); 52 db_->AddTable(table);
53 53
54 // Unretained to avoid a ref loop since we own |db_|. 54 // Unretained to avoid a ref loop since we own |db_|.
55 db_->set_error_callback(base::Bind(&WebDatabaseBackend::DatabaseErrorCallback, 55 db_->set_error_callback(base::Bind(&WebDatabaseBackend::DatabaseErrorCallback,
56 base::Unretained(this))); 56 base::Unretained(this)));
57 diagnostics_.clear(); 57 diagnostics_.clear();
58 init_status_ = db_->Init(db_path_); 58 init_status_ = db_->Init(db_path_);
59 if (init_status_ != sql::INIT_OK) { 59 if (init_status_ != sql::INIT_OK) {
60 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; 60 LOG(ERROR) << "Cannot initialize the web database: " << init_status_;
61 diagnostics_ += sql::GetCorruptFileDiagnosticsInfo(db_path_); 61 diagnostics_ += sql::GetCorruptFileDiagnosticsInfo(db_path_);
62 db_.reset(); 62 if (!catastrophic_error_occurred_)
63 db_.reset();
63 return init_status_; 64 return init_status_;
64 } 65 }
65 66
66 db_->BeginTransaction(); 67 db_->BeginTransaction();
67 return init_status_; 68 return init_status_;
68 } 69 }
69 70
70 void WebDatabaseBackend::ShutdownDatabase() { 71 void WebDatabaseBackend::ShutdownDatabase() {
71 if (db_ && init_status_ == sql::INIT_OK) 72 if (db_ && init_status_ == sql::INIT_OK)
72 db_->CommitTransaction(); 73 db_->CommitTransaction();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 WebDatabaseBackend::~WebDatabaseBackend() { 118 WebDatabaseBackend::~WebDatabaseBackend() {
118 ShutdownDatabase(); 119 ShutdownDatabase();
119 } 120 }
120 121
121 void WebDatabaseBackend::DatabaseErrorCallback(int error, 122 void WebDatabaseBackend::DatabaseErrorCallback(int error,
122 sql::Statement* statement) { 123 sql::Statement* statement) {
123 // We ignore any further error callbacks after the first catastrophic error. 124 // We ignore any further error callbacks after the first catastrophic error.
124 if (!catastrophic_error_occurred_ && sql::IsErrorCatastrophic(error)) { 125 if (!catastrophic_error_occurred_ && sql::IsErrorCatastrophic(error)) {
125 catastrophic_error_occurred_ = true; 126 catastrophic_error_occurred_ = true;
126 diagnostics_ = db_->GetDiagnosticInfo(error, statement); 127 diagnostics_ = db_->GetDiagnosticInfo(error, statement);
128
129 task_runner_->PostTask(
130 FROM_HERE,
131 base::Bind(&WebDatabaseBackend::RazeAndCloseDatabase, this));
127 } 132 }
128 } 133 }
129 134
135 void WebDatabaseBackend::RazeAndCloseDatabase() {
136 if (!db_)
137 return;
138
139 db_->GetSQLConnection()->RollbackAllTransactions();
140 db_->GetSQLConnection()->Raze();
141 db_.reset();
Scott Hess - ex-Googler 2016/08/10 17:16:19 These three lines are essentially identical to wha
afakhry 2016/08/11 17:32:54 Interesting. Thanks! Done.
142 }
143
130 void WebDatabaseBackend::Commit() { 144 void WebDatabaseBackend::Commit() {
131 DCHECK(db_); 145 DCHECK(db_);
132 DCHECK_EQ(sql::INIT_OK, init_status_); 146 DCHECK_EQ(sql::INIT_OK, init_status_);
133 db_->CommitTransaction(); 147 db_->CommitTransaction();
134 db_->BeginTransaction(); 148 db_->BeginTransaction();
135 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698