summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc66
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.h13
-rw-r--r--chrome/browser/history/history_database.cc4
-rw-r--r--chrome/browser/history/text_database.cc24
-rw-r--r--chrome/browser/history/thumbnail_database.cc4
-rw-r--r--chrome/browser/net/sqlite_persistent_cookie_store.cc24
-rw-r--r--chrome/browser/webdata/web_database.cc4
7 files changed, 95 insertions, 44 deletions
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index 1f6b978..f3ca31d 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -4,3 +4,69 @@
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
+#include "app/sql/connection.h"
+#include "base/histogram.h"
+#include "base/logging.h"
+#include "base/singleton.h"
+
+namespace {
+
+const char* kHistogramNames[] = {
+ "Sqlite.Cookie.Error",
+ "Sqlite.History.Error",
+ "Sqlite.Thumbnail.Error",
+ "Sqlite.Text.Error",
+ "Sqlite.Web.Error"
+};
+
+// This class handles the exceptional sqlite errors that we might encounter
+// if for example the db is corrupted. Right now we just generate a UMA
+// histogram for release and an assert for debug builds.
+//
+// Why is it a template you ask? well, that is a funny story. The histograms
+// need to be singletons that is why they are always static at the function
+// scope, but we cannot use the Singleton class because they are not default
+// constructible. The template parameter makes the compiler to create unique
+// classes that don't share the same static variable.
+template <size_t unique>
+class BasicSqliteErrrorHandler : public sql::ErrorDelegate {
+ public:
+
+ virtual int OnError(int error, sql::Connection* connection,
+ sql::Statement* stmt) {
+ NOTREACHED() << "sqlite error " << error;
+ RecordErrorInHistogram(error);
+ return error;
+ }
+
+ private:
+ static void RecordErrorInHistogram(int error) {
+ // The histogram values from sqlite result codes go currently from 1 to
+ // 26 currently but 50 gives them room to grow.
+ static LinearHistogram histogram(kHistogramNames[unique], 1, 50, 51);
+ histogram.SetFlags(kUmaTargetedHistogramFlag);
+ histogram.Add(error);
+ }
+};
+
+} // namespace
+
+sql::ErrorDelegate* GetErrorHandlerForCookieDb() {
+ return new BasicSqliteErrrorHandler<0>();
+}
+
+sql::ErrorDelegate* GetErrorHandlerForHistoryDb() {
+ return new BasicSqliteErrrorHandler<1>();
+}
+
+sql::ErrorDelegate* GetErrorHandlerForThumbnailDb() {
+ return new BasicSqliteErrrorHandler<2>();
+}
+
+sql::ErrorDelegate* GetErrorHandlerForTextDb() {
+ return new BasicSqliteErrrorHandler<3>();
+}
+
+sql::ErrorDelegate* GetErrorHandlerForWebDb() {
+ return new BasicSqliteErrrorHandler<4>();
+}
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.h b/chrome/browser/diagnostics/sqlite_diagnostics.h
index f082fe8..ee1a7f1 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.h
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.h
@@ -5,5 +5,18 @@
#ifndef CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
#define CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
+namespace sql {
+ class ErrorDelegate;
+}
+
+sql::ErrorDelegate* GetErrorHandlerForCookieDb();
+
+sql::ErrorDelegate* GetErrorHandlerForHistoryDb();
+
+sql::ErrorDelegate* GetErrorHandlerForThumbnailDb();
+
+sql::ErrorDelegate* GetErrorHandlerForTextDb();
+
+sql::ErrorDelegate* GetErrorHandlerForWebDb();
#endif // CHROME_BROWSER_DIAGNOSTICS_SQLITE_DIAGNOSTICS_H_
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index ee0b179..87367a4 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -13,6 +13,7 @@
#include "base/histogram.h"
#include "base/rand_util.h"
#include "base/string_util.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
namespace history {
@@ -59,6 +60,9 @@ HistoryDatabase::~HistoryDatabase() {
InitStatus HistoryDatabase::Init(const FilePath& history_name,
const FilePath& bookmarks_path) {
+ // Set the exceptional sqlite error handler.
+ db_.set_error_delegate(GetErrorHandlerForHistoryDb());
+
// Set the database page size to something a little larger to give us
// better performance (we're typically seek rather than bandwidth limited).
// This only has an effect before any tables have been created, otherwise
diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc
index fa46853..27d8e6b 100644
--- a/chrome/browser/history/text_database.cc
+++ b/chrome/browser/history/text_database.cc
@@ -14,6 +14,7 @@
#include "base/histogram.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
// There are two tables in each database, one full-text search (FTS) table which
// indexes the contents and title of the pages. The other is a regular SQLITE
@@ -53,27 +54,6 @@ const FilePath::CharType kFilePrefix[] = FILE_PATH_LITERAL("History Index ");
} // namespace
-// This class handles the exceptional sqlite errors that we might encounter
-// if for example the db is corrupted. Right now we just generate a UMA
-// histogram for release and an assert for debug builds.
-class TextDbSqliteErrrorHandler : public sql::ErrorDelegate {
- public:
- virtual int OnError(int error, sql::Connection* connection,
- sql::Statement* stmt) {
- NOTREACHED() << "history db sqlite error " << error;
- RecordErrorInHistogram(error);
- return error;
- }
- private:
- static void RecordErrorInHistogram(int error) {
- // The histogram values from sqlite result codes go currently from 1 to
- // 26 currently but 100 gives them room to grow.
- static LinearHistogram histogram("Sqlite.History.Error", 1, 50, 51);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(error);
- }
-};
-
TextDatabase::TextDatabase(const FilePath& path,
DBIdent id,
bool allow_create)
@@ -137,7 +117,7 @@ bool TextDatabase::Init() {
}
// Set the exceptional sqlite error handler.
- db_.set_error_delegate(new TextDbSqliteErrrorHandler());
+ db_.set_error_delegate(GetErrorHandlerForTextDb());
// Set the database page size to something a little larger to give us
// better performance (we're typically seek rather than bandwidth limited).
diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc
index ac06464..96aebf7 100644
--- a/chrome/browser/history/thumbnail_database.cc
+++ b/chrome/browser/history/thumbnail_database.cc
@@ -10,6 +10,7 @@
#include "base/file_util.h"
#include "base/time.h"
#include "base/string_util.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "chrome/browser/history/history_publisher.h"
#include "chrome/browser/history/url_database.h"
#include "chrome/common/thumbnail_score.h"
@@ -32,6 +33,9 @@ InitStatus ThumbnailDatabase::Init(const FilePath& db_name,
const HistoryPublisher* history_publisher) {
history_publisher_ = history_publisher;
+ // Set the exceptional sqlite error handler.
+ db_.set_error_delegate(GetErrorHandlerForThumbnailDb());
+
// Set the database page size to something larger to give us
// better performance (we're typically seek rather than bandwidth limited).
// This only has an effect before any tables have been created, otherwise
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc
index 700caac..7f19610 100644
--- a/chrome/browser/net/sqlite_persistent_cookie_store.cc
+++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc
@@ -14,6 +14,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
using base::Time;
@@ -281,27 +282,6 @@ static const int kCompatibleVersionNumber = 3;
namespace {
-// This class handles the exceptional sqlite errors that we might encounter
-// if for example the db is corrupted. Right now we just generate a UMA
-// histogram for release and an assert for debug builds.
-class CookieDbSqliteErrrorHandler : public sql::ErrorDelegate {
- public:
- virtual int OnError(int error, sql::Connection* connection,
- sql::Statement* stmt) {
- NOTREACHED() << "cookie db sqlite error " << error;
- RecordErrorInHistogram(error);
- return error;
- }
- private:
- static void RecordErrorInHistogram(int error) {
- // The histogram values from sqlite result codes go currently from 1 to
- // 26 currently but 50 gives them room to grow.
- static LinearHistogram histogram("Sqlite.Cookie.Error", 1, 50, 51);
- histogram.SetFlags(kUmaTargetedHistogramFlag);
- histogram.Add(error);
- }
-};
-
// Initializes the cookies table, returning true on success.
bool InitTable(sql::Connection* db) {
if (!db->DoesTableExist("cookies")) {
@@ -335,7 +315,7 @@ bool SQLitePersistentCookieStore::Load(
return false;
}
- db->set_error_delegate(new CookieDbSqliteErrrorHandler());
+ db->set_error_delegate(GetErrorHandlerForCookieDb());
if (!EnsureDatabaseVersion(db.get()) || !InitTable(db.get())) {
NOTREACHED() << "Unable to initialize cookie DB.";
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index e796979..98bc76c 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -14,6 +14,7 @@
#include "app/sql/transaction.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
#include "chrome/browser/history/history_database.h"
#include "chrome/browser/search_engines/template_url.h"
#include "webkit/glue/password_form.h"
@@ -133,6 +134,9 @@ void WebDatabase::CommitTransaction() {
}
bool WebDatabase::Init(const FilePath& db_name) {
+ // Set the exceptional sqlite error handler.
+ db_.set_error_delegate(GetErrorHandlerForWebDb());
+
// We don't store that much data in the tables so use a small page size.
// This provides a large benefit for empty tables (which is very likely with
// the tables we create).