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

Side by Side 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: 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_service.h" 5 #include "components/webdata/common/web_database_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void WebDatabaseService::RegisterDBErrorCallback( 130 void WebDatabaseService::RegisterDBErrorCallback(
131 const DBLoadErrorCallback& callback) { 131 const DBLoadErrorCallback& callback) {
132 error_callbacks_.push_back(callback); 132 error_callbacks_.push_back(callback);
133 } 133 }
134 134
135 void WebDatabaseService::OnDatabaseLoadDone(sql::InitStatus status, 135 void WebDatabaseService::OnDatabaseLoadDone(sql::InitStatus status,
136 const std::string& diagnostics) { 136 const std::string& diagnostics) {
137 if (status == sql::INIT_OK) { 137 if (status == sql::INIT_OK) {
138 db_loaded_ = true; 138 db_loaded_ = true;
139 139
140 for (const auto& loaded_callback : loaded_callbacks_) { 140 while (!loaded_callbacks_.empty()) {
141 DBLoadedCallback loaded_callback = loaded_callbacks_.back();
142 loaded_callbacks_.pop_back();
141 if (!loaded_callback.is_null()) 143 if (!loaded_callback.is_null())
142 loaded_callback.Run(); 144 loaded_callback.Run();
143 } 145 }
144
145 loaded_callbacks_.clear();
146 } else { 146 } else {
147 // Notify that the database load failed. 147 // Notify that the database load failed.
148 for (const auto& error_callback : error_callbacks_) { 148 while (!error_callbacks_.empty()) {
149 // The profile error callback is a message box that runs in a nested run
150 // loop. While it's being displayed, other OnDatabaseLoadDone() will run
151 // (posted from WebDatabaseBackend::Delegate::DBLoaded()). We need to make
152 // sure that after the callback running the message box returns, it checks
153 // |error_callbacks_| before it accesses it.
Scott Hess - ex-Googler 2016/08/10 17:16:19 If I understand this correctly, another option mig
afakhry 2016/08/11 17:32:54 This works too, but it exposes a problem that was
154 DBLoadErrorCallback error_callback = error_callbacks_.back();
155 error_callbacks_.pop_back();
149 if (!error_callback.is_null()) 156 if (!error_callback.is_null())
150 error_callback.Run(status, diagnostics); 157 error_callback.Run(status, diagnostics);
151 } 158 }
152
153 error_callbacks_.clear();
154 } 159 }
155 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698