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 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 5 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
11 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
12 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
13 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | 17 #include "base/path_service.h" |
15 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "build/build_config.h" |
18 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
20 #include "chromeos/chromeos_constants.h" | 24 #include "chromeos/chromeos_constants.h" |
21 #include "components/history/core/browser/history_constants.h" | 25 #include "components/history/core/browser/history_constants.h" |
22 #include "components/webdata/common/webdata_constants.h" | 26 #include "components/webdata/common/webdata_constants.h" |
23 #include "content/public/common/content_constants.h" | 27 #include "content/public/common/content_constants.h" |
24 #include "sql/connection.h" | 28 #include "sql/connection.h" |
25 #include "sql/statement.h" | 29 #include "sql/statement.h" |
26 #include "storage/browser/database/database_tracker.h" | 30 #include "storage/browser/database/database_tracker.h" |
27 #include "third_party/sqlite/sqlite3.h" | 31 #include "third_party/sqlite/sqlite3.h" |
28 | 32 |
29 namespace diagnostics { | 33 namespace diagnostics { |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 // Generic diagnostic test class for checking SQLite database integrity. | 37 // Generic diagnostic test class for checking SQLite database integrity. |
34 class SqliteIntegrityTest : public DiagnosticsTest { | 38 class SqliteIntegrityTest : public DiagnosticsTest { |
35 public: | 39 public: |
36 // These are bit flags, so each value should be a power of two. | 40 // These are bit flags, so each value should be a power of two. |
37 enum Flags { | 41 enum Flags { |
38 NO_FLAGS_SET = 0, | 42 NO_FLAGS_SET = 0, |
39 CRITICAL = 0x01, | 43 CRITICAL = 0x01, |
40 REMOVE_IF_CORRUPT = 0x02, | 44 REMOVE_IF_CORRUPT = 0x02, |
41 }; | 45 }; |
42 | 46 |
43 SqliteIntegrityTest(uint32 flags, | 47 SqliteIntegrityTest(uint32_t flags, |
44 DiagnosticsTestId id, | 48 DiagnosticsTestId id, |
45 const base::FilePath& db_path) | 49 const base::FilePath& db_path) |
46 : DiagnosticsTest(id), flags_(flags), db_path_(db_path) {} | 50 : DiagnosticsTest(id), flags_(flags), db_path_(db_path) {} |
47 | 51 |
48 bool RecoveryImpl(DiagnosticsModel::Observer* observer) override { | 52 bool RecoveryImpl(DiagnosticsModel::Observer* observer) override { |
49 int outcome_code = GetOutcomeCode(); | 53 int outcome_code = GetOutcomeCode(); |
50 if (flags_ & REMOVE_IF_CORRUPT) { | 54 if (flags_ & REMOVE_IF_CORRUPT) { |
51 switch (outcome_code) { | 55 switch (outcome_code) { |
52 case DIAG_SQLITE_ERROR_HANDLER_CALLED: | 56 case DIAG_SQLITE_ERROR_HANDLER_CALLED: |
53 case DIAG_SQLITE_CANNOT_OPEN_DB: | 57 case DIAG_SQLITE_CANNOT_OPEN_DB: |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 ~ErrorRecorder() {} | 191 ~ErrorRecorder() {} |
188 | 192 |
189 bool has_error_; | 193 bool has_error_; |
190 int sqlite_error_; | 194 int sqlite_error_; |
191 int last_errno_; | 195 int last_errno_; |
192 std::string message_; | 196 std::string message_; |
193 | 197 |
194 DISALLOW_COPY_AND_ASSIGN(ErrorRecorder); | 198 DISALLOW_COPY_AND_ASSIGN(ErrorRecorder); |
195 }; | 199 }; |
196 | 200 |
197 uint32 flags_; | 201 uint32_t flags_; |
198 base::FilePath db_path_; | 202 base::FilePath db_path_; |
199 DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest); | 203 DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest); |
200 }; | 204 }; |
201 | 205 |
202 } // namespace | 206 } // namespace |
203 | 207 |
204 DiagnosticsTest* MakeSqliteCookiesDbTest() { | 208 DiagnosticsTest* MakeSqliteCookiesDbTest() { |
205 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, | 209 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, |
206 DIAGNOSTICS_SQLITE_INTEGRITY_COOKIE_TEST, | 210 DIAGNOSTICS_SQLITE_INTEGRITY_COOKIE_TEST, |
207 base::FilePath(chrome::kCookieFilename)); | 211 base::FilePath(chrome::kCookieFilename)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 base::FilePath(history::kThumbnailsFilename)); | 251 base::FilePath(history::kThumbnailsFilename)); |
248 } | 252 } |
249 | 253 |
250 DiagnosticsTest* MakeSqliteWebDataDbTest() { | 254 DiagnosticsTest* MakeSqliteWebDataDbTest() { |
251 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, | 255 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, |
252 DIAGNOSTICS_SQLITE_INTEGRITY_WEB_DATA_TEST, | 256 DIAGNOSTICS_SQLITE_INTEGRITY_WEB_DATA_TEST, |
253 base::FilePath(kWebDataFilename)); | 257 base::FilePath(kWebDataFilename)); |
254 } | 258 } |
255 | 259 |
256 } // namespace diagnostics | 260 } // namespace diagnostics |
OLD | NEW |