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

Side by Side Diff: webkit/browser/appcache/appcache_database.cc

Issue 137493003: Appcache::OnCorruptionDetected handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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/browser/appcache/appcache_database.h" 5 #include "webkit/browser/appcache/appcache_database.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/file_util.h" 10 #include "base/file_util.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/rand_util.h" // just for local testing, not for commit
kinuko 2014/02/03 05:36:50 This should go away before submit?
michaeln 2014/02/03 21:03:02 Done.
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "sql/connection.h" 14 #include "sql/connection.h"
15 #include "sql/error_delegate_util.h"
13 #include "sql/meta_table.h" 16 #include "sql/meta_table.h"
14 #include "sql/statement.h" 17 #include "sql/statement.h"
15 #include "sql/transaction.h" 18 #include "sql/transaction.h"
16 #include "webkit/browser/appcache/appcache_entry.h" 19 #include "webkit/browser/appcache/appcache_entry.h"
17 #include "webkit/browser/appcache/appcache_histograms.h" 20 #include "webkit/browser/appcache/appcache_histograms.h"
18 21
19 namespace appcache { 22 namespace appcache {
20 23
21 // Schema ------------------------------------------------------------------- 24 // Schema -------------------------------------------------------------------
22 namespace { 25 namespace {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 AppCacheDatabase::NamespaceRecord::NamespaceRecord() 197 AppCacheDatabase::NamespaceRecord::NamespaceRecord()
195 : cache_id(0) { 198 : cache_id(0) {
196 } 199 }
197 200
198 AppCacheDatabase::NamespaceRecord::~NamespaceRecord() { 201 AppCacheDatabase::NamespaceRecord::~NamespaceRecord() {
199 } 202 }
200 203
201 204
202 AppCacheDatabase::AppCacheDatabase(const base::FilePath& path) 205 AppCacheDatabase::AppCacheDatabase(const base::FilePath& path)
203 : db_file_path_(path), is_disabled_(false), is_recreating_(false) { 206 : db_file_path_(path),
207 is_disabled_(false),
208 is_recreating_(false),
209 was_corruption_detected_(false) {
204 } 210 }
205 211
206 AppCacheDatabase::~AppCacheDatabase() { 212 AppCacheDatabase::~AppCacheDatabase() {
207 } 213 }
208 214
209 void AppCacheDatabase::CloseConnection() { 215 void AppCacheDatabase::CloseConnection() {
210 // We can't close the connection for an in-memory database w/o 216 // We can't close the connection for an in-memory database w/o
211 // losing all of the data, so we don't do that. 217 // losing all of the data, so we don't do that.
212 if (!db_file_path_.empty()) 218 if (!db_file_path_.empty())
213 ResetConnectionAndTables(); 219 ResetConnectionAndTables();
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 // the existing appcache data and starting with a clean slate in 1035 // the existing appcache data and starting with a clean slate in
1030 // this browser session. 1036 // this browser session.
1031 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase()) 1037 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase())
1032 return true; 1038 return true;
1033 1039
1034 Disable(); 1040 Disable();
1035 return false; 1041 return false;
1036 } 1042 }
1037 1043
1038 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK); 1044 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK);
1045 was_corruption_detected_ = false;
1046 db_->set_error_callback(
1047 base::Bind(&AppCacheDatabase::OnDatabaseError, base::Unretained(this)));
1039 return true; 1048 return true;
1040 } 1049 }
1041 1050
1042 bool AppCacheDatabase::EnsureDatabaseVersion() { 1051 bool AppCacheDatabase::EnsureDatabaseVersion() {
1043 if (!sql::MetaTable::DoesTableExist(db_.get())) 1052 if (!sql::MetaTable::DoesTableExist(db_.get()))
1044 return CreateSchema(); 1053 return CreateSchema();
1045 1054
1046 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion)) 1055 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion))
1047 return false; 1056 return false;
1048 1057
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 1197
1189 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { 1198 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() {
1190 DCHECK(!db_file_path_.empty()); 1199 DCHECK(!db_file_path_.empty());
1191 DCHECK(base::PathExists(db_file_path_)); 1200 DCHECK(base::PathExists(db_file_path_));
1192 VLOG(1) << "Deleting existing appcache data and starting over."; 1201 VLOG(1) << "Deleting existing appcache data and starting over.";
1193 1202
1194 ResetConnectionAndTables(); 1203 ResetConnectionAndTables();
1195 1204
1196 // This also deletes the disk cache data. 1205 // This also deletes the disk cache data.
1197 base::FilePath directory = db_file_path_.DirName(); 1206 base::FilePath directory = db_file_path_.DirName();
1198 if (!base::DeleteFile(directory, true) || 1207 if (!base::DeleteFile(directory, true))
1199 !base::CreateDirectory(directory)) {
1200 return false; 1208 return false;
1201 }
1202 1209
1203 // Make sure the steps above actually deleted things. 1210 // Make sure the steps above actually deleted things.
1204 if (base::PathExists(db_file_path_)) 1211 if (base::PathExists(directory))
1212 return false;
1213
1214 if (!base::CreateDirectory(directory))
1205 return false; 1215 return false;
1206 1216
1207 // So we can't go recursive. 1217 // So we can't go recursive.
1208 if (is_recreating_) 1218 if (is_recreating_)
1209 return false; 1219 return false;
1210 1220
1211 base::AutoReset<bool> auto_reset(&is_recreating_, true); 1221 base::AutoReset<bool> auto_reset(&is_recreating_, true);
1212 return LazyOpen(true); 1222 return LazyOpen(true);
1213 } 1223 }
1214 1224
1225 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) {
1226 was_corruption_detected_ |= sql::IsErrorCatastrophic(err);
1227 if (!db_->ShouldIgnoreSqliteError(err))
1228 DLOG(ERROR) << db_->GetErrorMessage();
1229 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check?
1230 }
1231
1215 } // namespace appcache 1232 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698