summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 02:22:54 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 02:22:54 +0000
commit0ee84fc076751138ff80f6c8a253a06e24fe5ef8 (patch)
tree2f0316bec33c5a933ed2bba05a1975c6c8638aa8
parentada5b89cd996a1540b1399baf329df250bc7a54c (diff)
downloadchromium_src-0ee84fc076751138ff80f6c8a253a06e24fe5ef8.zip
chromium_src-0ee84fc076751138ff80f6c8a253a06e24fe5ef8.tar.gz
chromium_src-0ee84fc076751138ff80f6c8a253a06e24fe5ef8.tar.bz2
Re-land sqlite diagnostics
- Forgot to update a stupid number in the tests See http://codereview.chromium.org/1548005 BUG=27885 TEST=included Review URL: http://codereview.chromium.org/1543006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43169 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/diagnostics/diagnostics_model.cc16
-rw-r--r--chrome/browser/diagnostics/diagnostics_model_unittest.cc4
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc96
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.h15
4 files changed, 125 insertions, 6 deletions
diff --git a/chrome/browser/diagnostics/diagnostics_model.cc b/chrome/browser/diagnostics/diagnostics_model.cc
index 0fb53fc..b7a1bc3 100644
--- a/chrome/browser/diagnostics/diagnostics_model.cc
+++ b/chrome/browser/diagnostics/diagnostics_model.cc
@@ -14,6 +14,7 @@
#include "base/path_service.h"
#include "chrome/browser/diagnostics/diagnostics_test.h"
#include "chrome/browser/diagnostics/recon_diagnostics.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "chrome/common/chrome_paths.h"
namespace {
@@ -86,6 +87,11 @@ class DiagnosticsModelWin : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakeSqliteWebDbTest());
+ tests_.push_back(MakeSqliteCookiesDbTest());
+ tests_.push_back(MakeSqliteHistoryDbTest());
+ tests_.push_back(MakeSqliteArchivedHistoryDbTest());
+ tests_.push_back(MakeSqliteThumbnailsDbTest());
}
private:
@@ -102,6 +108,11 @@ class DiagnosticsModelMac : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakeSqliteWebDbTest());
+ tests_.push_back(MakeSqliteCookiesDbTest());
+ tests_.push_back(MakeSqliteHistoryDbTest());
+ tests_.push_back(MakeSqliteArchivedHistoryDbTest());
+ tests_.push_back(MakeSqliteThumbnailsDbTest());
}
private:
@@ -118,6 +129,11 @@ class DiagnosticsModelPosix : public DiagnosticsModelImpl {
tests_.push_back(MakeDictonaryDirTest());
tests_.push_back(MakeInspectorDirTest());
tests_.push_back(MakeDiskSpaceTest());
+ tests_.push_back(MakeSqliteWebDbTest());
+ tests_.push_back(MakeSqliteCookiesDbTest());
+ tests_.push_back(MakeSqliteHistoryDbTest());
+ tests_.push_back(MakeSqliteArchivedHistoryDbTest());
+ tests_.push_back(MakeSqliteThumbnailsDbTest());
}
private:
diff --git a/chrome/browser/diagnostics/diagnostics_model_unittest.cc b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
index 535ee57..3db4912 100644
--- a/chrome/browser/diagnostics/diagnostics_model_unittest.cc
+++ b/chrome/browser/diagnostics/diagnostics_model_unittest.cc
@@ -72,9 +72,9 @@ class UTObserver: public DiagnosticsModel::Observer {
// We currently have more tests operational on windows.
#if defined(OS_WIN)
-const int kDiagnosticsTestCount = 8;
+const int kDiagnosticsTestCount = 13;
#else
-const int kDiagnosticsTestCount = 6;
+const int kDiagnosticsTestCount = 11;
#endif
// Test that the initial state is correct.
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index fbefc33..e0eeab3 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -5,9 +5,16 @@
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "app/sql/connection.h"
+#include "app/sql/init_status.h"
+#include "app/sql/statement.h"
+#include "base/file_util.h"
#include "base/histogram.h"
#include "base/logging.h"
+#include "base/path_service.h"
#include "base/singleton.h"
+#include "base/string_util.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
namespace {
@@ -47,6 +54,74 @@ class BasicSqliteErrrorHandler : public sql::ErrorDelegate {
}
};
+struct DbTestInfo {
+ const char* test_name;
+ const FilePath::CharType* db_name;
+};
+
+static const DbTestInfo kTestInfo[] = {
+ {"Web Database", chrome::kWebDataFilename},
+ {"Cookies Database", chrome::kCookieFilename},
+ {"History Database", chrome::kHistoryFilename},
+ {"Archived history Database", chrome::kArchivedHistoryFilename},
+ {"Thumbnails Database", chrome::kThumbnailsFilename}
+};
+
+// Generic diagnostic test class for checking sqlite db integrity.
+class SqliteIntegrityTest : public DiagnosticTest {
+ public:
+ explicit SqliteIntegrityTest(int index)
+ : DiagnosticTest(ASCIIToUTF16(kTestInfo[index].test_name)),
+ index_(index) {
+ }
+
+ virtual int GetId() { return 0; }
+
+ virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) {
+ FilePath path;
+ PathService::Get(chrome::DIR_USER_DATA, &path);
+ path = path.Append(FilePath::FromWStringHack(chrome::kNotSignedInProfile));
+ path = path.Append(kTestInfo[index_].db_name);
+ if (!file_util::PathExists(path)) {
+ RecordFailure(ASCIIToUTF16("File not found"));
+ return true;
+ }
+
+ int errors = 0;
+ { // This block scopes the lifetime of the db objects.
+ sql::Connection db;
+ db.set_exclusive_locking();
+ if (!db.Open(path)) {
+ RecordFailure(ASCIIToUTF16("Cannot open db. Possibly corrupted"));
+ return true;
+ }
+ sql::Statement s(db.GetUniqueStatement("PRAGMA integrity_check;"));
+ if (!s) {
+ RecordFailure(ASCIIToUTF16("Statement failed"));
+ return false;
+ }
+ while (s.Step()) {
+ std::string result(s.ColumnString(0));
+ if ("ok" != result)
+ ++errors;
+ }
+ }
+ // All done. Report to the user.
+ if (errors != 0) {
+ string16 str(ASCIIToUTF16("Database corruption detected :"));
+ str += IntToString16(errors) + ASCIIToUTF16(" errors");
+ RecordFailure(str);
+ return true;
+ }
+ RecordSuccess(ASCIIToUTF16("no corruption detected"));
+ return true;
+ }
+
+ private:
+ int index_;
+ DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest);
+};
+
} // namespace
sql::ErrorDelegate* GetErrorHandlerForCookieDb() {
@@ -68,3 +143,24 @@ sql::ErrorDelegate* GetErrorHandlerForTextDb() {
sql::ErrorDelegate* GetErrorHandlerForWebDb() {
return new BasicSqliteErrrorHandler<4>();
}
+
+DiagnosticTest* MakeSqliteWebDbTest() {
+ return new SqliteIntegrityTest(0);
+}
+
+DiagnosticTest* MakeSqliteCookiesDbTest() {
+ return new SqliteIntegrityTest(1);
+}
+
+DiagnosticTest* MakeSqliteHistoryDbTest() {
+ return new SqliteIntegrityTest(2);
+}
+
+DiagnosticTest* MakeSqliteArchivedHistoryDbTest() {
+ return new SqliteIntegrityTest(3);
+}
+
+DiagnosticTest* MakeSqliteThumbnailsDbTest() {
+ return new SqliteIntegrityTest(4);
+}
+
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.h b/chrome/browser/diagnostics/sqlite_diagnostics.h
index ee1a7f1..1618a07 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.h
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.h
@@ -5,18 +5,25 @@
#ifndef CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
#define CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
+#include "chrome/browser/diagnostics/diagnostics_test.h"
+
namespace sql {
class ErrorDelegate;
}
+// The following five factories create the error handlers that we use when
+// issuing sqlite commands during normal browser operation.
sql::ErrorDelegate* GetErrorHandlerForCookieDb();
-
sql::ErrorDelegate* GetErrorHandlerForHistoryDb();
-
sql::ErrorDelegate* GetErrorHandlerForThumbnailDb();
-
sql::ErrorDelegate* GetErrorHandlerForTextDb();
-
sql::ErrorDelegate* GetErrorHandlerForWebDb();
+// Factories for the db integrity tests we run in diagnostic mode.
+DiagnosticTest* MakeSqliteWebDbTest();
+DiagnosticTest* MakeSqliteCookiesDbTest();
+DiagnosticTest* MakeSqliteHistoryDbTest();
+DiagnosticTest* MakeSqliteArchivedHistoryDbTest();
+DiagnosticTest* MakeSqliteThumbnailsDbTest();
+
#endif // CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_