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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 NO_FLAGS_SET = 0, | 37 NO_FLAGS_SET = 0, |
38 CRITICAL = 0x01, | 38 CRITICAL = 0x01, |
39 REMOVE_IF_CORRUPT = 0x02, | 39 REMOVE_IF_CORRUPT = 0x02, |
40 }; | 40 }; |
41 | 41 |
42 SqliteIntegrityTest(uint32 flags, | 42 SqliteIntegrityTest(uint32 flags, |
43 DiagnosticsTestId id, | 43 DiagnosticsTestId id, |
44 const base::FilePath& db_path) | 44 const base::FilePath& db_path) |
45 : DiagnosticsTest(id), flags_(flags), db_path_(db_path) {} | 45 : DiagnosticsTest(id), flags_(flags), db_path_(db_path) {} |
46 | 46 |
47 virtual bool RecoveryImpl(DiagnosticsModel::Observer* observer) OVERRIDE { | 47 virtual bool RecoveryImpl(DiagnosticsModel::Observer* observer) override { |
48 int outcome_code = GetOutcomeCode(); | 48 int outcome_code = GetOutcomeCode(); |
49 if (flags_ & REMOVE_IF_CORRUPT) { | 49 if (flags_ & REMOVE_IF_CORRUPT) { |
50 switch (outcome_code) { | 50 switch (outcome_code) { |
51 case DIAG_SQLITE_ERROR_HANDLER_CALLED: | 51 case DIAG_SQLITE_ERROR_HANDLER_CALLED: |
52 case DIAG_SQLITE_CANNOT_OPEN_DB: | 52 case DIAG_SQLITE_CANNOT_OPEN_DB: |
53 case DIAG_SQLITE_DB_LOCKED: | 53 case DIAG_SQLITE_DB_LOCKED: |
54 case DIAG_SQLITE_PRAGMA_FAILED: | 54 case DIAG_SQLITE_PRAGMA_FAILED: |
55 case DIAG_SQLITE_DB_CORRUPTED: | 55 case DIAG_SQLITE_DB_CORRUPTED: |
56 LOG(WARNING) << "Removing broken SQLite database: " | 56 LOG(WARNING) << "Removing broken SQLite database: " |
57 << db_path_.value(); | 57 << db_path_.value(); |
58 base::DeleteFile(db_path_, false); | 58 base::DeleteFile(db_path_, false); |
59 break; | 59 break; |
60 case DIAG_SQLITE_SUCCESS: | 60 case DIAG_SQLITE_SUCCESS: |
61 case DIAG_SQLITE_FILE_NOT_FOUND_OK: | 61 case DIAG_SQLITE_FILE_NOT_FOUND_OK: |
62 case DIAG_SQLITE_FILE_NOT_FOUND: | 62 case DIAG_SQLITE_FILE_NOT_FOUND: |
63 break; | 63 break; |
64 default: | 64 default: |
65 DCHECK(false) << "Invalid outcome code: " << outcome_code; | 65 DCHECK(false) << "Invalid outcome code: " << outcome_code; |
66 break; | 66 break; |
67 } | 67 } |
68 } | 68 } |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) OVERRIDE { | 72 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) override { |
73 // If we're given an absolute path, use it. If not, then assume it's under | 73 // If we're given an absolute path, use it. If not, then assume it's under |
74 // the profile directory. | 74 // the profile directory. |
75 base::FilePath path; | 75 base::FilePath path; |
76 if (!db_path_.IsAbsolute()) | 76 if (!db_path_.IsAbsolute()) |
77 path = GetUserDefaultProfileDir().Append(db_path_); | 77 path = GetUserDefaultProfileDir().Append(db_path_); |
78 else | 78 else |
79 path = db_path_; | 79 path = db_path_; |
80 | 80 |
81 if (!base::PathExists(path)) { | 81 if (!base::PathExists(path)) { |
82 if (flags_ & CRITICAL) { | 82 if (flags_ & CRITICAL) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 base::FilePath(chrome::kThumbnailsFilename)); | 246 base::FilePath(chrome::kThumbnailsFilename)); |
247 } | 247 } |
248 | 248 |
249 DiagnosticsTest* MakeSqliteWebDataDbTest() { | 249 DiagnosticsTest* MakeSqliteWebDataDbTest() { |
250 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, | 250 return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, |
251 DIAGNOSTICS_SQLITE_INTEGRITY_WEB_DATA_TEST, | 251 DIAGNOSTICS_SQLITE_INTEGRITY_WEB_DATA_TEST, |
252 base::FilePath(kWebDataFilename)); | 252 base::FilePath(kWebDataFilename)); |
253 } | 253 } |
254 | 254 |
255 } // namespace diagnostics | 255 } // namespace diagnostics |
OLD | NEW |