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

Unified Diff: components/webdata/common/web_database_service.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_service.h ('k') | sql/init_status.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webdata/common/web_database_service.cc
diff --git a/components/webdata/common/web_database_service.cc b/components/webdata/common/web_database_service.cc
index a5ed8633b2f705ba2a83c7c2f73b87591a3a2b4f..79bc298022c7bed8fd3590bea99cf2f0b7cd553e 100644
--- a/components/webdata/common/web_database_service.cc
+++ b/components/webdata/common/web_database_service.cc
@@ -134,22 +134,31 @@ void WebDatabaseService::RegisterDBErrorCallback(
void WebDatabaseService::OnDatabaseLoadDone(sql::InitStatus status,
const std::string& diagnostics) {
- if (status == sql::INIT_OK) {
- db_loaded_ = true;
-
- for (const auto& loaded_callback : loaded_callbacks_) {
- if (!loaded_callback.is_null())
- loaded_callback.Run();
- }
-
- loaded_callbacks_.clear();
- } else {
+ // The INIT_OK_WITH_DATA_LOSS status is an initialization success but with
+ // suspected data loss, so we also run the error callbacks.
+ if (status != sql::INIT_OK) {
// Notify that the database load failed.
- for (const auto& error_callback : error_callbacks_) {
+ while (!error_callbacks_.empty()) {
+ // The profile error callback is a message box that runs in a nested run
+ // loop. While it's being displayed, other OnDatabaseLoadDone() will run
+ // (posted from WebDatabaseBackend::Delegate::DBLoaded()). We need to make
+ // sure that after the callback running the message box returns, it checks
+ // |error_callbacks_| before it accesses it.
+ DBLoadErrorCallback error_callback = error_callbacks_.back();
+ error_callbacks_.pop_back();
if (!error_callback.is_null())
error_callback.Run(status, diagnostics);
}
+ }
+
+ if (status == sql::INIT_OK || status == sql::INIT_OK_WITH_DATA_LOSS) {
+ db_loaded_ = true;
- error_callbacks_.clear();
+ while (!loaded_callbacks_.empty()) {
+ DBLoadedCallback loaded_callback = loaded_callbacks_.back();
+ loaded_callbacks_.pop_back();
+ if (!loaded_callback.is_null())
+ loaded_callback.Run();
+ }
}
}
« no previous file with comments | « components/webdata/common/web_database_service.h ('k') | sql/init_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698