OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ | 5 #ifndef SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ |
6 #define SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ | 6 #define SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "sql/connection.h" | 10 #include "sql/connection.h" |
11 #include "sql/sql_export.h" | 11 #include "sql/sql_export.h" |
12 | 12 |
13 namespace sql { | 13 namespace sql { |
14 | 14 |
15 // The histogram values from sqlite result codes currently range from 1 to 26 | |
16 // but 50 gives them room to grow. | |
17 static const int kMaxSqliteError = 50; | |
18 | |
19 // This class handles the exceptional sqlite errors that we might encounter | 15 // This class handles the exceptional sqlite errors that we might encounter |
20 // if for example the db is corrupted. Right now we just generate a UMA | 16 // if for example the db is corrupted. Right now we just generate a UMA |
21 // histogram for release and an assert for debug builds. | 17 // histogram for release and an assert for debug builds. |
22 // | 18 // |
23 // Why is it a template you ask? well, that is a funny story. The histograms | 19 // Why is it a template you ask? well, that is a funny story. The histograms |
24 // need to be singletons that is why they are always static at the function | 20 // need to be singletons that is why they are always static at the function |
25 // scope, but we cannot use the Singleton class because they are not default | 21 // scope, but we cannot use the Singleton class because they are not default |
26 // constructible. The template parameter makes the compiler to create unique | 22 // constructible. The template parameter makes the compiler to create unique |
27 // classes that don't share the same static variable. | 23 // classes that don't share the same static variable. |
28 template <class UniqueT> | 24 template <class UniqueT> |
29 class DiagnosticErrorDelegate : public ErrorDelegate { | 25 class DiagnosticErrorDelegate : public ErrorDelegate { |
30 public: | 26 public: |
31 | 27 |
32 virtual int OnError(int error, Connection* connection, | 28 virtual int OnError(int error, Connection* connection, |
33 Statement* stmt) { | 29 Statement* stmt) { |
34 LOG(ERROR) << "sqlite error " << error | 30 LOG(ERROR) << "sqlite error " << error |
35 << ", errno " << connection->GetLastErrno() | 31 << ", errno " << connection->GetLastErrno() |
36 << ": " << connection->GetErrorMessage(); | 32 << ": " << connection->GetErrorMessage(); |
37 RecordErrorInHistogram(error); | 33 RecordErrorInHistogram(error); |
38 return error; | 34 return error; |
39 } | 35 } |
40 | 36 |
41 private: | 37 private: |
42 static void RecordErrorInHistogram(int error) { | 38 static void RecordErrorInHistogram(int error) { |
43 // Trim off the extended error codes. | 39 // Trim off the extended error codes. |
44 error &= 0xff; | 40 error &= 0xff; |
45 | 41 |
46 UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, kMaxSqliteError); | 42 // The histogram values from sqlite result codes go currently from 1 to |
| 43 // 26 currently but 50 gives them room to grow. |
| 44 UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error, 50); |
47 } | 45 } |
48 }; | 46 }; |
49 | 47 |
50 } // namespace sql | 48 } // namespace sql |
51 | 49 |
52 #endif // SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ | 50 #endif // SQL_DIAGNOSTIC_ERROR_DELEGATE_H_ |
OLD | NEW |