summaryrefslogtreecommitdiffstats
path: root/sql/error_delegate_util.h
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 04:31:53 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 04:31:53 +0000
commit0d04ede3f14d8c248b5f91687694673df8c145b5 (patch)
tree3c2ea2c08726dd0424cb295c790308280289c890 /sql/error_delegate_util.h
parentb50b6edf3dee383cae64c39e4b101c848b7ebc74 (diff)
downloadchromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.zip
chromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.tar.gz
chromium_src-0d04ede3f14d8c248b5f91687694673df8c145b5.tar.bz2
Move ErrorDelegate to its own file and add static utility functions to ErrorDelegate
BUG=151841 Test=None R=shess, erikwright TBR=cpu Review URL: https://chromiumcodereview.appspot.com/11141012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/error_delegate_util.h')
-rw-r--r--sql/error_delegate_util.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/sql/error_delegate_util.h b/sql/error_delegate_util.h
new file mode 100644
index 0000000..6b90ccf
--- /dev/null
+++ b/sql/error_delegate_util.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SQL_ERROR_DELEGATE_UTIL_H_
+#define SQL_ERROR_DELEGATE_UTIL_H_
+
+#include "base/metrics/histogram.h"
+#include "sql/connection.h"
+#include "sql/sql_export.h"
+
+namespace sql {
+
+// Returns true if it is highly unlikely that the database can recover from
+// |error|.
+SQL_EXPORT bool IsErrorCatastrophic(int error);
+
+// Log error in console in debug mode and generate a UMA histogram in release
+// mode for |error| for |UniqueT::name()|.
+// This function is templated because histograms need to be singletons. That is
+// why they are always static at the function scope. The template parameter
+// makes the compiler create unique functions that don't share the same static
+// variable.
+template <class UniqueT>
+void LogAndRecordErrorInHistogram(int error,
+ sql::Connection* connection) {
+ LOG(ERROR) << "sqlite error " << error
+ << ", errno " << connection->GetLastErrno()
+ << ": " << connection->GetErrorMessage();
+
+ // Trim off the extended error codes.
+ error &= 0xff;
+
+ // The histogram values from sqlite result codes currently go from 1 to 26
+ // but 50 gives them room to grow.
+ UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50);
+}
+
+} // namespace sql
+
+#endif // SQL_ERROR_DELEGATE_UTIL_H_