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