diff options
-rw-r--r-- | chrome/browser/history/text_database.cc | 25 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 23 |
2 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc index d56788ca..e9b37eb 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -11,6 +11,7 @@ #include "app/sql/statement.h" #include "app/sql/transaction.h" #include "base/file_util.h" +#include "base/histogram.h" #include "base/logging.h" #include "base/string_util.h" @@ -54,6 +55,27 @@ 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) @@ -116,6 +138,9 @@ bool TextDatabase::Init() { return false; } + // Set the exceptional sqlite error handler. + db_.set_error_delegate(new TextDbSqliteErrrorHandler()); + // 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/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc index ce371f5..d8ec074 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc @@ -281,6 +281,27 @@ 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")) { @@ -314,6 +335,8 @@ bool SQLitePersistentCookieStore::Load( return false; } + db->set_error_delegate(new CookieDbSqliteErrrorHandler()); + if (!EnsureDatabaseVersion(db.get()) || !InitTable(db.get())) { NOTREACHED() << "Unable to initialize cookie DB."; return false; |