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

Side by Side Diff: webkit/database/database_tracker.cc

Issue 9371008: Nuke from orbit corrupt websql databases. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « webkit/database/database_tracker.h ('k') | webkit/database/database_tracker_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/database/database_tracker.h" 5 #include "webkit/database/database_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "sql/connection.h" 18 #include "sql/connection.h"
19 #include "sql/diagnostic_error_delegate.h" 19 #include "sql/diagnostic_error_delegate.h"
20 #include "sql/meta_table.h" 20 #include "sql/meta_table.h"
21 #include "sql/transaction.h" 21 #include "sql/transaction.h"
22 #include "third_party/sqlite/sqlite3.h"
22 #include "webkit/database/database_quota_client.h" 23 #include "webkit/database/database_quota_client.h"
23 #include "webkit/database/database_util.h" 24 #include "webkit/database/database_util.h"
24 #include "webkit/database/databases_table.h" 25 #include "webkit/database/databases_table.h"
25 #include "webkit/quota/quota_manager.h" 26 #include "webkit/quota/quota_manager.h"
26 #include "webkit/quota/special_storage_policy.h" 27 #include "webkit/quota/special_storage_policy.h"
27 28
28 namespace { 29 namespace {
29 30
30 class HistogramUniquifier { 31 class HistogramUniquifier {
31 public: 32 public:
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 quota_manager_proxy_->NotifyStorageAccessed( 173 quota_manager_proxy_->NotifyStorageAccessed(
173 quota::QuotaClient::kDatabase, 174 quota::QuotaClient::kDatabase,
174 DatabaseUtil::GetOriginFromIdentifier(origin_identifier), 175 DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
175 quota::kStorageTypeTemporary); 176 quota::kStorageTypeTemporary);
176 177
177 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name); 178 UpdateOpenDatabaseSizeAndNotify(origin_identifier, database_name);
178 if (database_connections_.RemoveConnection(origin_identifier, database_name)) 179 if (database_connections_.RemoveConnection(origin_identifier, database_name))
179 DeleteDatabaseIfNeeded(origin_identifier, database_name); 180 DeleteDatabaseIfNeeded(origin_identifier, database_name);
180 } 181 }
181 182
183 void DatabaseTracker::HandleSqliteError(
184 const string16& origin_identifier,
185 const string16& database_name,
186 int error) {
187 // We only handle errors that indicate corruption and we
188 // do so with a heavy hand, we delete it. Any renderers/workers
189 // with this database open will receive a message to close it
190 // immediately, once all have closed, the files will be deleted.
191 // In the interim, all attempts to open a new connection to that
192 // database will fail.
193 // Note: the client-side filters out all but these two errors as
194 // a small optimization, see WebDatabaseObserverImpl::HandleSqliteError.
195 if (error == SQLITE_CORRUPT || error == SQLITE_NOTADB) {
196 DeleteDatabase(origin_identifier, database_name,
197 net::CompletionCallback());
198 }
199 }
200
182 void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) { 201 void DatabaseTracker::CloseDatabases(const DatabaseConnections& connections) {
183 if (database_connections_.IsEmpty()) { 202 if (database_connections_.IsEmpty()) {
184 DCHECK(!is_initialized_ || connections.IsEmpty()); 203 DCHECK(!is_initialized_ || connections.IsEmpty());
185 return; 204 return;
186 } 205 }
187 206
188 // When being closed by this route, there's a chance that 207 // When being closed by this route, there's a chance that
189 // the tracker missed some DatabseModified calls. This method is used 208 // the tracker missed some DatabseModified calls. This method is used
190 // when a renderer crashes to cleanup it's open resources. 209 // when a renderer crashes to cleanup it's open resources.
191 // We need to examine what we have in connections for the 210 // We need to examine what we have in connections for the
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 if (!db_tracker_thread_->BelongsToCurrentThread()) { 895 if (!db_tracker_thread_->BelongsToCurrentThread()) {
877 db_tracker_thread_->PostTask( 896 db_tracker_thread_->PostTask(
878 FROM_HERE, 897 FROM_HERE,
879 base::Bind(&DatabaseTracker::SaveSessionState, this)); 898 base::Bind(&DatabaseTracker::SaveSessionState, this));
880 return; 899 return;
881 } 900 }
882 save_session_state_ = true; 901 save_session_state_ = true;
883 } 902 }
884 903
885 } // namespace webkit_database 904 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_tracker.h ('k') | webkit/database/database_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698