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

Unified Diff: chrome/browser/diagnostics/sqlite_diagnostics.cc

Issue 270101: Move the sqlite error handler to a single location... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/diagnostics/sqlite_diagnostics.h ('k') | chrome/browser/history/history_database.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/diagnostics/sqlite_diagnostics.cc
===================================================================
--- chrome/browser/diagnostics/sqlite_diagnostics.cc (revision 28908)
+++ chrome/browser/diagnostics/sqlite_diagnostics.cc (working copy)
@@ -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"
jar (doing other things) 2009/10/15 06:44:28 Not a big deal... but... Given these will be sorte
+};
+
+// 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>();
+}
« no previous file with comments | « chrome/browser/diagnostics/sqlite_diagnostics.h ('k') | chrome/browser/history/history_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698