OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" | 7 #include "app/sql/connection.h" |
8 #include "app/sql/diagnostic_error_delegate.h" | 8 #include "app/sql/diagnostic_error_delegate.h" |
9 #include "app/sql/statement.h" | 9 #include "app/sql/statement.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/string_util.h" | 15 #include "base/string_number_conversions.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "third_party/sqlite/preprocessed/sqlite3.h" | 18 #include "third_party/sqlite/preprocessed/sqlite3.h" |
19 #include "webkit/appcache/appcache_interfaces.h" | 19 #include "webkit/appcache/appcache_interfaces.h" |
20 #include "webkit/database/database_tracker.h" | 20 #include "webkit/database/database_tracker.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Generic diagnostic test class for checking sqlite db integrity. | 24 // Generic diagnostic test class for checking sqlite db integrity. |
25 class SqliteIntegrityTest : public DiagnosticTest { | 25 class SqliteIntegrityTest : public DiagnosticTest { |
(...skipping 25 matching lines...) Expand all Loading... |
51 RecordFailure(ASCIIToUTF16("Cannot open DB. Possibly corrupted")); | 51 RecordFailure(ASCIIToUTF16("Cannot open DB. Possibly corrupted")); |
52 return true; | 52 return true; |
53 } | 53 } |
54 sql::Statement s(db.GetUniqueStatement("PRAGMA integrity_check;")); | 54 sql::Statement s(db.GetUniqueStatement("PRAGMA integrity_check;")); |
55 if (!s) { | 55 if (!s) { |
56 int error = db.GetErrorCode(); | 56 int error = db.GetErrorCode(); |
57 if (SQLITE_BUSY == error) { | 57 if (SQLITE_BUSY == error) { |
58 RecordFailure(ASCIIToUTF16("DB locked by another process")); | 58 RecordFailure(ASCIIToUTF16("DB locked by another process")); |
59 } else { | 59 } else { |
60 string16 str(ASCIIToUTF16("Pragma failed. Error: ")); | 60 string16 str(ASCIIToUTF16("Pragma failed. Error: ")); |
61 str += IntToString16(error); | 61 str += base::IntToString16(error); |
62 RecordFailure(str); | 62 RecordFailure(str); |
63 } | 63 } |
64 return false; | 64 return false; |
65 } | 65 } |
66 while (s.Step()) { | 66 while (s.Step()) { |
67 std::string result(s.ColumnString(0)); | 67 std::string result(s.ColumnString(0)); |
68 if ("ok" != result) | 68 if ("ok" != result) |
69 ++errors; | 69 ++errors; |
70 } | 70 } |
71 } | 71 } |
72 // All done. Report to the user. | 72 // All done. Report to the user. |
73 if (errors != 0) { | 73 if (errors != 0) { |
74 string16 str(ASCIIToUTF16("Database corruption detected :")); | 74 string16 str(ASCIIToUTF16("Database corruption detected :")); |
75 str += IntToString16(errors) + ASCIIToUTF16(" errors"); | 75 str += base::IntToString16(errors) + ASCIIToUTF16(" errors"); |
76 RecordFailure(str); | 76 RecordFailure(str); |
77 return true; | 77 return true; |
78 } | 78 } |
79 RecordSuccess(ASCIIToUTF16("no corruption detected")); | 79 RecordSuccess(ASCIIToUTF16("no corruption detected")); |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 bool critical_; | 84 bool critical_; |
85 FilePath db_path_; | 85 FilePath db_path_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 appcache_db); | 157 appcache_db); |
158 } | 158 } |
159 | 159 |
160 DiagnosticTest* MakeSqliteWebDatabaseTrackerDbTest() { | 160 DiagnosticTest* MakeSqliteWebDatabaseTrackerDbTest() { |
161 FilePath databases_dir(webkit_database::kDatabaseDirectoryName); | 161 FilePath databases_dir(webkit_database::kDatabaseDirectoryName); |
162 FilePath tracker_db = | 162 FilePath tracker_db = |
163 databases_dir.Append(webkit_database::kTrackerDatabaseFileName); | 163 databases_dir.Append(webkit_database::kTrackerDatabaseFileName); |
164 return new SqliteIntegrityTest(false, ASCIIToUTF16("DatabaseTracker DB"), | 164 return new SqliteIntegrityTest(false, ASCIIToUTF16("DatabaseTracker DB"), |
165 tracker_db); | 165 tracker_db); |
166 } | 166 } |
OLD | NEW |