diff options
| author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 00:56:41 +0000 |
|---|---|---|
| committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 00:56:41 +0000 |
| commit | ed655b77ca7f838078b20ca030c8456818eafe70 (patch) | |
| tree | 8d1e92706f0e556a4a280c2b9195a52f837fa678 /chrome/browser/diagnostics/sqlite_diagnostics.cc | |
| parent | 4a00221ac7fab87ea4da95af07f079c650694806 (diff) | |
| download | chromium_src-ed655b77ca7f838078b20ca030c8456818eafe70.zip chromium_src-ed655b77ca7f838078b20ca030c8456818eafe70.tar.gz chromium_src-ed655b77ca7f838078b20ca030c8456818eafe70.tar.bz2 | |
Move the sqlite error handler to a single location
- Eliminate code duplication
- Cover other 3 databases
- Still doing the same as before, sending UMA histograms
BUG=11908
TEST=none
Review URL: http://codereview.chromium.org/270101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29073 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/diagnostics/sqlite_diagnostics.cc')
| -rw-r--r-- | chrome/browser/diagnostics/sqlite_diagnostics.cc | 66 |
1 files changed, 66 insertions, 0 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>(); +} |
