diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 08:39:46 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 08:39:46 +0000 |
commit | c3881b37c9dba1b0e72c586ba9ec5f411bb407c0 (patch) | |
tree | aa5c179c244a1be3322318e5e0e0299fb5d69251 /sql | |
parent | 6d595ee53cc83225b1d62dc591abe78eb9492ce9 (diff) | |
download | chromium_src-c3881b37c9dba1b0e72c586ba9ec5f411bb407c0.zip chromium_src-c3881b37c9dba1b0e72c586ba9ec5f411bb407c0.tar.gz chromium_src-c3881b37c9dba1b0e72c586ba9ec5f411bb407c0.tar.bz2 |
Dump additional error info for thumbnail database.
The union of SQLite error messages and platform errno is a potentially
large space which may not be reasonable to histogram. Instead,
randomly dump a crash report with diagnostic information which can be
correlated with histograms.
BUG=240396
Review URL: https://chromiumcodereview.appspot.com/15131008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/connection.cc | 7 | ||||
-rw-r--r-- | sql/connection.h | 25 |
2 files changed, 32 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc index 54aeb89..701a129 100644 --- a/sql/connection.cc +++ b/sql/connection.cc @@ -736,6 +736,13 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) { << ", errno " << GetLastErrno() << ": " << GetErrorMessage(); + if (!error_callback_.is_null()) { + error_callback_.Run(err, stmt); + return err; + } + + // TODO(shess): Remove |error_delegate_| once everything is + // converted to |error_callback_|. if (error_delegate_.get()) return error_delegate_->OnError(err, this, stmt); diff --git a/sql/connection.h b/sql/connection.h index 44b97f6..96312c4 100644 --- a/sql/connection.h +++ b/sql/connection.h @@ -10,6 +10,7 @@ #include <string> #include "base/basictypes.h" +#include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -138,10 +139,32 @@ class SQL_EXPORT Connection { // This must be called before Open() to have an effect. void set_exclusive_locking() { exclusive_locking_ = true; } + // Set an error-handling callback. On errors, the error number (and + // statement, if available) will be passed to the callback. + // + // If no callback is set, the default action is to crash in debug + // mode or return failure in release mode. + // + // TODO(shess): ErrorDelegate allowed for returning a different + // error. Determine if this is necessary for the callback. In my + // experience, this is not well-tested and probably not safe, and + // current clients always return the same error passed. + // Additionally, most errors don't admit to a clean way to retry the + // failed operation, so converting an error to SQLITE_OK is probably + // not feasible. + typedef base::Callback<void(int, Statement*)> ErrorCallback; + void set_error_callback(const ErrorCallback& callback) { + error_callback_ = callback; + } + void reset_error_callback() { + error_callback_.Reset(); + } + // Sets the object that will handle errors. Recomended that it should be set // before calling Open(). If not set, the default is to ignore errors on // release and assert on debug builds. // Takes ownership of |delegate|. + // NOTE(shess): Deprecated, use set_error_callback(). void set_error_delegate(ErrorDelegate* delegate) { error_delegate_.reset(delegate); } @@ -497,6 +520,8 @@ class SQL_EXPORT Connection { // databases. bool poisoned_; + ErrorCallback error_callback_; + // This object handles errors resulting from all forms of executing sqlite // commands or statements. It can be null which means default handling. scoped_ptr<ErrorDelegate> error_delegate_; |