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

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, 11 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
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), is_disabled_(false),
207 is_recreating_(false), was_corruption_detected_(false) {
jsbell 2014/01/24 21:13:44 nit: one per line if they don't all git on one lin
michaeln 2014/01/28 22:12:16 Done.
204 } 208 }
205 209
206 AppCacheDatabase::~AppCacheDatabase() { 210 AppCacheDatabase::~AppCacheDatabase() {
207 } 211 }
208 212
209 void AppCacheDatabase::CloseConnection() { 213 void AppCacheDatabase::CloseConnection() {
210 // We can't close the connection for an in-memory database w/o 214 // 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. 215 // losing all of the data, so we don't do that.
212 if (!db_file_path_.empty()) 216 if (!db_file_path_.empty())
213 ResetConnectionAndTables(); 217 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 1033 // the existing appcache data and starting with a clean slate in
1030 // this browser session. 1034 // this browser session.
1031 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase()) 1035 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase())
1032 return true; 1036 return true;
1033 1037
1034 Disable(); 1038 Disable();
1035 return false; 1039 return false;
1036 } 1040 }
1037 1041
1038 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK); 1042 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK);
1043 was_corruption_detected_ = false;
1044 db_->set_error_callback(
1045 base::Bind(&AppCacheDatabase::OnDatabaseError, base::Unretained(this)));
1039 return true; 1046 return true;
1040 } 1047 }
1041 1048
1042 bool AppCacheDatabase::EnsureDatabaseVersion() { 1049 bool AppCacheDatabase::EnsureDatabaseVersion() {
1043 if (!sql::MetaTable::DoesTableExist(db_.get())) 1050 if (!sql::MetaTable::DoesTableExist(db_.get()))
1044 return CreateSchema(); 1051 return CreateSchema();
1045 1052
1046 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion)) 1053 if (!meta_table_->Init(db_.get(), kCurrentVersion, kCompatibleVersion))
1047 return false; 1054 return false;
1048 1055
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 1195
1189 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() { 1196 bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() {
1190 DCHECK(!db_file_path_.empty()); 1197 DCHECK(!db_file_path_.empty());
1191 DCHECK(base::PathExists(db_file_path_)); 1198 DCHECK(base::PathExists(db_file_path_));
1192 VLOG(1) << "Deleting existing appcache data and starting over."; 1199 VLOG(1) << "Deleting existing appcache data and starting over.";
1193 1200
1194 ResetConnectionAndTables(); 1201 ResetConnectionAndTables();
1195 1202
1196 // This also deletes the disk cache data. 1203 // This also deletes the disk cache data.
1197 base::FilePath directory = db_file_path_.DirName(); 1204 base::FilePath directory = db_file_path_.DirName();
1198 if (!base::DeleteFile(directory, true) || 1205 if (!base::DeleteFile(directory, true))
1199 !base::CreateDirectory(directory)) {
1200 return false; 1206 return false;
1201 }
1202 1207
1203 // Make sure the steps above actually deleted things. 1208 // Make sure the steps above actually deleted things.
1204 if (base::PathExists(db_file_path_)) 1209 if (base::PathExists(directory))
1210 return false;
1211
1212 if (!base::CreateDirectory(directory))
1205 return false; 1213 return false;
1206 1214
1207 // So we can't go recursive. 1215 // So we can't go recursive.
1208 if (is_recreating_) 1216 if (is_recreating_)
1209 return false; 1217 return false;
1210 1218
1211 base::AutoReset<bool> auto_reset(&is_recreating_, true); 1219 base::AutoReset<bool> auto_reset(&is_recreating_, true);
1212 return LazyOpen(true); 1220 return LazyOpen(true);
1213 } 1221 }
1214 1222
1223 void AppCacheDatabase::OnDatabaseError(int err, sql::Statement* stmt) {
1224 was_corruption_detected_ |= sql::IsErrorCatastrophic(err);
1225 if (!db_->ShouldIgnoreSqliteError(err))
1226 DLOG(ERROR) << db_->GetErrorMessage();
1227 // TODO: Maybe use non-catostrophic errors to trigger a full integrity check?
1228 }
1229
1230 bool AppCacheDatabase::was_corruption_detected() {
1231 // For local testing, inject spurious errors and see wha' happens.
michaeln 2014/01/24 01:48:27 I'll remove this and have the inline method, but f
michaeln 2014/01/28 22:12:16 Done.
1232 //uint64 kSynthesizedErrorRate = 10; // percent
1233 //was_corruption_detected_ |=
1234 // (base::RandGenerator(100) < kSynthesizedErrorRate);
1235 return was_corruption_detected_;
1236 }
1237
1215 } // namespace appcache 1238 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698