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

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: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 loaded_callbacks_.push_back(callback); 127 loaded_callbacks_.push_back(callback);
128 } 128 }
129 129
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 // The INIT_OK_WITH_DATA_LOSS status is an initialization success but with
138 // suspected data loss, so we also run the error callbacks.
139 if (status != sql::INIT_OK) {
140 // Notify that the database load failed.
141 while (!error_callbacks_.empty()) {
142 // The profile error callback is a message box that runs in a nested run
143 // loop. While it's being displayed, other OnDatabaseLoadDone() will run
144 // (posted from WebDatabaseBackend::Delegate::DBLoaded()). We need to make
145 // sure that after the callback running the message box returns, it checks
146 // |error_callbacks_| before it accesses it.
147 DBLoadErrorCallback error_callback = error_callbacks_.back();
148 error_callbacks_.pop_back();
149 if (!error_callback.is_null())
150 error_callback.Run(status, diagnostics);
151 }
152 }
153
154 if (status == sql::INIT_OK || status == sql::INIT_OK_WITH_DATA_LOSS) {
138 db_loaded_ = true; 155 db_loaded_ = true;
139 156
140 for (const auto& loaded_callback : loaded_callbacks_) { 157 while (!loaded_callbacks_.empty()) {
158 DBLoadedCallback loaded_callback = loaded_callbacks_.back();
159 loaded_callbacks_.pop_back();
141 if (!loaded_callback.is_null()) 160 if (!loaded_callback.is_null())
142 loaded_callback.Run(); 161 loaded_callback.Run();
143 } 162 }
144
145 loaded_callbacks_.clear();
146 } else {
147 // Notify that the database load failed.
148 for (const auto& error_callback : error_callbacks_) {
149 if (!error_callback.is_null())
150 error_callback.Run(status, diagnostics);
151 }
152
153 error_callbacks_.clear();
154 } 163 }
155 } 164 }
OLDNEW
« 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