From 3f1828a7c18c45910d5ea938fe476d1a60bb272c Mon Sep 17 00:00:00 2001
From: "cpu@chromium.org"
 <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 2 Oct 2009 00:44:16 +0000
Subject: Add UMA histograms for sqlite errors - cookies - history db

TEST=none
BUG=none


Review URL: http://codereview.chromium.org/243055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27810 0039d316-1c4b-4281-b951-d872f2087c98
---
 chrome/browser/history/text_database.cc | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'chrome/browser/history')

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
-- 
cgit v1.1