OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 5 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
6 | 6 |
7 #include "app/sql/connection.h" | |
8 #include "base/histogram.h" | |
9 #include "base/logging.h" | |
10 #include "base/singleton.h" | |
11 | |
12 namespace { | |
13 | |
14 const char* kHistogramNames[] = { | |
15 "Sqlite.Cookie.Error", | |
16 "Sqlite.History.Error", | |
17 "Sqlite.Thumbnail.Error", | |
18 "Sqlite.Text.Error", | |
19 "Sqlite.Web.Error" | |
jar (doing other things)
2009/10/15 06:44:28
Not a big deal... but... Given these will be sorte
| |
20 }; | |
21 | |
22 // This class handles the exceptional sqlite errors that we might encounter | |
23 // if for example the db is corrupted. Right now we just generate a UMA | |
24 // histogram for release and an assert for debug builds. | |
25 // | |
26 // Why is it a template you ask? well, that is a funny story. The histograms | |
27 // need to be singletons that is why they are always static at the function | |
28 // scope, but we cannot use the Singleton class because they are not default | |
29 // constructible. The template parameter makes the compiler to create unique | |
30 // classes that don't share the same static variable. | |
31 template <size_t unique> | |
32 class BasicSqliteErrrorHandler : public sql::ErrorDelegate { | |
33 public: | |
34 | |
35 virtual int OnError(int error, sql::Connection* connection, | |
36 sql::Statement* stmt) { | |
37 NOTREACHED() << "sqlite error " << error; | |
38 RecordErrorInHistogram(error); | |
39 return error; | |
40 } | |
41 | |
42 private: | |
43 static void RecordErrorInHistogram(int error) { | |
44 // The histogram values from sqlite result codes go currently from 1 to | |
45 // 26 currently but 50 gives them room to grow. | |
46 static LinearHistogram histogram(kHistogramNames[unique], 1, 50, 51); | |
47 histogram.SetFlags(kUmaTargetedHistogramFlag); | |
48 histogram.Add(error); | |
49 } | |
50 }; | |
51 | |
52 } // namespace | |
53 | |
54 sql::ErrorDelegate* GetErrorHandlerForCookieDb() { | |
55 return new BasicSqliteErrrorHandler<0>(); | |
56 } | |
57 | |
58 sql::ErrorDelegate* GetErrorHandlerForHistoryDb() { | |
59 return new BasicSqliteErrrorHandler<1>(); | |
60 } | |
61 | |
62 sql::ErrorDelegate* GetErrorHandlerForThumbnailDb() { | |
63 return new BasicSqliteErrrorHandler<2>(); | |
64 } | |
65 | |
66 sql::ErrorDelegate* GetErrorHandlerForTextDb() { | |
67 return new BasicSqliteErrrorHandler<3>(); | |
68 } | |
69 | |
70 sql::ErrorDelegate* GetErrorHandlerForWebDb() { | |
71 return new BasicSqliteErrrorHandler<4>(); | |
72 } | |
OLD | NEW |