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

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

Issue 104593010: AppCache: Run a quick integrity check on the sqlite database when opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 if (use_in_memory_db) { 1012 if (use_in_memory_db) {
1013 opened = db_->OpenInMemory(); 1013 opened = db_->OpenInMemory();
1014 } else if (!base::CreateDirectory(db_file_path_.DirName())) { 1014 } else if (!base::CreateDirectory(db_file_path_.DirName())) {
1015 LOG(ERROR) << "Failed to create appcache directory."; 1015 LOG(ERROR) << "Failed to create appcache directory.";
1016 } else { 1016 } else {
1017 opened = db_->Open(db_file_path_); 1017 opened = db_->Open(db_file_path_);
1018 if (opened) 1018 if (opened)
1019 db_->Preload(); 1019 db_->Preload();
1020 } 1020 }
1021 1021
1022 if (!opened || !EnsureDatabaseVersion()) { 1022 if (!opened || !QuickIntegrityCheck() || !EnsureDatabaseVersion()) {
1023 LOG(ERROR) << "Failed to open the appcache database."; 1023 LOG(ERROR) << "Failed to open the appcache database.";
1024 AppCacheHistograms::CountInitResult( 1024 AppCacheHistograms::CountInitResult(
1025 AppCacheHistograms::SQL_DATABASE_ERROR); 1025 AppCacheHistograms::SQL_DATABASE_ERROR);
1026 1026
1027 // We're unable to open the database. This is a fatal error 1027 // We're unable to open the database. This is a fatal error
1028 // which we can't recover from. We try to handle it by deleting 1028 // which we can't recover from. We try to handle it by deleting
1029 // the existing appcache data and starting with a clean slate in 1029 // the existing appcache data and starting with a clean slate in
1030 // this browser session. 1030 // this browser session.
1031 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase()) 1031 if (!use_in_memory_db && DeleteExistingAndCreateNewDatabase())
1032 return true; 1032 return true;
1033 1033
1034 Disable(); 1034 Disable();
1035 return false; 1035 return false;
1036 } 1036 }
1037 1037
1038 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK); 1038 AppCacheHistograms::CountInitResult(AppCacheHistograms::INIT_OK);
1039 return true; 1039 return true;
1040 } 1040 }
1041 1041
1042 bool AppCacheDatabase::QuickIntegrityCheck() {
1043 DCHECK(db_.get());
1044 std::vector<std::string> messages;
1045 if (!db_->QuickIntegrityCheck(&messages))
1046 return false;
1047 return messages.size() == 1 && messages[0] == "ok";
1048 }
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
1049 if (meta_table_->GetCompatibleVersionNumber() > kCurrentVersion) { 1057 if (meta_table_->GetCompatibleVersionNumber() > kCurrentVersion) {
1050 LOG(WARNING) << "AppCache database is too new."; 1058 LOG(WARNING) << "AppCache database is too new.";
1051 return false; 1059 return false;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
1215 } // namespace appcache 1223 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698