diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 18:40:21 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 18:40:21 +0000 |
commit | f0a54b2f3f5afcf13f3ff981837e290c44e66680 (patch) | |
tree | 2c19b6aa7217deeb55bfeb6212ff11fbc0ddf813 /sql/diagnostic_error_delegate.h | |
parent | 737402392b58715c71ed52b210ee62124f06b18c (diff) | |
download | chromium_src-f0a54b2f3f5afcf13f3ff981837e290c44e66680.zip chromium_src-f0a54b2f3f5afcf13f3ff981837e290c44e66680.tar.gz chromium_src-f0a54b2f3f5afcf13f3ff981837e290c44e66680.tar.bz2 |
Move app/sql/* files to sql/ directory.
I can't remove app/app.gyp and app/app_base.gypi yet because they are referenced
by third_party gyp files :(
BUG=72317
TEST=None
R=rsesek@chromium.org
move app/sql to sql
Review URL: http://codereview.chromium.org/7353026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/diagnostic_error_delegate.h')
-rw-r--r-- | sql/diagnostic_error_delegate.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sql/diagnostic_error_delegate.h b/sql/diagnostic_error_delegate.h new file mode 100644 index 0000000..70677bd --- /dev/null +++ b/sql/diagnostic_error_delegate.h @@ -0,0 +1,50 @@ +// Copyright (c) 2011 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_DIAGNOSTIC_ERROR_DELEGATE_H_ +#define SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ +#pragma once + +#include "base/logging.h" +#include "base/metrics/histogram.h" +#include "sql/connection.h" + +namespace sql { + +// 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 <class UniqueT> +class DiagnosticErrorDelegate : public ErrorDelegate { + public: + + virtual int OnError(int error, Connection* connection, + Statement* stmt) { + NOTREACHED() << "sqlite error " << error + << ", errno " << connection->GetLastErrno() + << ": " << connection->GetErrorMessage(); + RecordErrorInHistogram(error); + return error; + } + + private: + static void RecordErrorInHistogram(int error) { + // Trim off the extended error codes. + error &= 0xff; + + // The histogram values from sqlite result codes go currently from 1 to + // 26 currently but 50 gives them room to grow. + UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50); + } +}; + +} // namespace sql + +#endif // SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ |