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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 const char kSQLiteIntegrityNSSKeyTest[] = "SQLiteIntegrityNSSKey"; | 42 const char kSQLiteIntegrityNSSKeyTest[] = "SQLiteIntegrityNSSKey"; |
43 #endif | 43 #endif |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // Generic diagnostic test class for checking SQLite database integrity. | 47 // Generic diagnostic test class for checking SQLite database integrity. |
48 class SqliteIntegrityTest : public DiagnosticsTest { | 48 class SqliteIntegrityTest : public DiagnosticsTest { |
49 public: | 49 public: |
50 | 50 |
51 SqliteIntegrityTest(bool critical, | 51 SqliteIntegrityTest(bool critical, |
52 bool remove_if_corrupt, | |
52 const std::string& id, | 53 const std::string& id, |
53 const std::string& title, | 54 const std::string& title, |
54 const base::FilePath& db_path) | 55 const base::FilePath& db_path) |
55 : DiagnosticsTest(id, title), critical_(critical), db_path_(db_path) {} | 56 : DiagnosticsTest(id, title), |
57 critical_(critical), | |
58 remove_if_corrupt_(remove_if_corrupt), | |
59 db_path_(db_path) {} | |
60 | |
61 virtual bool RecoveryImpl(DiagnosticsModel::Observer* observer) OVERRIDE { | |
62 int outcome_code = GetOutcomeCode(); | |
63 if (remove_if_corrupt_) { | |
64 switch (outcome_code) { | |
65 case DIAG_SQLITE_ERROR_HANDLER_CALLED: | |
66 case DIAG_SQLITE_CANNOT_OPEN_DB: | |
67 case DIAG_SQLITE_DB_LOCKED: | |
68 case DIAG_SQLITE_PRAGMA_FAILED: | |
69 case DIAG_SQLITE_DB_CORRUPTED: | |
70 LOG(WARNING) << "Removing broken SQLite database: " | |
71 << db_path_.value(); | |
72 base::DeleteFile(db_path_, false); | |
73 break; | |
74 case DIAG_SQLITE_SUCCESS: | |
75 case DIAG_SQLITE_FILE_NOT_FOUND_OK: | |
76 case DIAG_SQLITE_FILE_NOT_FOUND: | |
77 break; | |
78 default: | |
79 DCHECK(false) << "Invalid outcome code: " << outcome_code; | |
80 break; | |
81 } | |
82 } | |
83 return true; | |
84 } | |
56 | 85 |
57 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) OVERRIDE { | 86 virtual bool ExecuteImpl(DiagnosticsModel::Observer* observer) OVERRIDE { |
58 // If we're given an absolute path, use it. If not, then assume it's under | 87 // If we're given an absolute path, use it. If not, then assume it's under |
59 // the profile directory. | 88 // the profile directory. |
60 base::FilePath path; | 89 base::FilePath path; |
61 if (!db_path_.IsAbsolute()) | 90 if (!db_path_.IsAbsolute()) |
62 path = GetUserDefaultProfileDir().Append(db_path_); | 91 path = GetUserDefaultProfileDir().Append(db_path_); |
63 else | 92 else |
64 path = db_path_; | 93 path = db_path_; |
65 | 94 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 201 |
173 bool has_error_; | 202 bool has_error_; |
174 int sqlite_error_; | 203 int sqlite_error_; |
175 int last_errno_; | 204 int last_errno_; |
176 std::string message_; | 205 std::string message_; |
177 | 206 |
178 DISALLOW_COPY_AND_ASSIGN(ErrorRecorder); | 207 DISALLOW_COPY_AND_ASSIGN(ErrorRecorder); |
179 }; | 208 }; |
180 | 209 |
181 bool critical_; | 210 bool critical_; |
211 bool remove_if_corrupt_; | |
182 base::FilePath db_path_; | 212 base::FilePath db_path_; |
183 DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest); | 213 DISALLOW_COPY_AND_ASSIGN(SqliteIntegrityTest); |
184 }; | 214 }; |
185 | 215 |
186 } // namespace | 216 } // namespace |
187 | 217 |
188 DiagnosticsTest* MakeSqliteWebDbTest() { | 218 DiagnosticsTest* MakeSqliteWebDbTest() { |
189 return new SqliteIntegrityTest(true, | 219 return new SqliteIntegrityTest(true, // critical |
cpu_(ooo_6.6-7.5)
2013/07/25 19:40:56
same with these, either gone or switch to enums.
Greg Spencer (Chromium)
2013/07/26 18:51:30
Done.
| |
220 false, // remove_if_corrupt | |
190 kSQLiteIntegrityWebTest, | 221 kSQLiteIntegrityWebTest, |
191 "Web Database", | 222 "Web Database", |
192 base::FilePath(kWebDataFilename)); | 223 base::FilePath(kWebDataFilename)); |
193 } | 224 } |
194 | 225 |
195 DiagnosticsTest* MakeSqliteCookiesDbTest() { | 226 DiagnosticsTest* MakeSqliteCookiesDbTest() { |
196 return new SqliteIntegrityTest(true, | 227 return new SqliteIntegrityTest(true, // critical |
228 false, // remove_if_corrupt | |
197 kSQLiteIntegrityCookieTest, | 229 kSQLiteIntegrityCookieTest, |
198 "Cookies Database", | 230 "Cookies Database", |
199 base::FilePath(chrome::kCookieFilename)); | 231 base::FilePath(chrome::kCookieFilename)); |
200 } | 232 } |
201 | 233 |
202 DiagnosticsTest* MakeSqliteHistoryDbTest() { | 234 DiagnosticsTest* MakeSqliteHistoryDbTest() { |
203 return new SqliteIntegrityTest(true, | 235 return new SqliteIntegrityTest(true, // critical |
236 false, // remove_if_corrupt | |
204 kSQLiteIntegrityHistoryTest, | 237 kSQLiteIntegrityHistoryTest, |
205 "History Database", | 238 "History Database", |
206 base::FilePath(chrome::kHistoryFilename)); | 239 base::FilePath(chrome::kHistoryFilename)); |
207 } | 240 } |
208 | 241 |
209 DiagnosticsTest* MakeSqliteArchivedHistoryDbTest() { | 242 DiagnosticsTest* MakeSqliteArchivedHistoryDbTest() { |
210 return new SqliteIntegrityTest( | 243 return new SqliteIntegrityTest( |
211 false, | 244 false, // critical |
245 false, // remove_if_corrupt | |
212 kSQLiteIntegrityArchivedHistoryTest, | 246 kSQLiteIntegrityArchivedHistoryTest, |
213 "Archived History Database", | 247 "Archived History Database", |
214 base::FilePath(chrome::kArchivedHistoryFilename)); | 248 base::FilePath(chrome::kArchivedHistoryFilename)); |
215 } | 249 } |
216 | 250 |
217 DiagnosticsTest* MakeSqliteThumbnailsDbTest() { | 251 DiagnosticsTest* MakeSqliteThumbnailsDbTest() { |
218 return new SqliteIntegrityTest(false, | 252 return new SqliteIntegrityTest(false, // critical |
253 false, // remove_if_corrupt | |
219 kSQLiteIntegrityThumbnailsTest, | 254 kSQLiteIntegrityThumbnailsTest, |
220 "Thumbnails Database", | 255 "Thumbnails Database", |
221 base::FilePath(chrome::kThumbnailsFilename)); | 256 base::FilePath(chrome::kThumbnailsFilename)); |
222 } | 257 } |
223 | 258 |
224 DiagnosticsTest* MakeSqliteAppCacheDbTest() { | 259 DiagnosticsTest* MakeSqliteAppCacheDbTest() { |
225 base::FilePath appcache_dir(content::kAppCacheDirname); | 260 base::FilePath appcache_dir(content::kAppCacheDirname); |
226 base::FilePath appcache_db = | 261 base::FilePath appcache_db = |
227 appcache_dir.Append(appcache::kAppCacheDatabaseName); | 262 appcache_dir.Append(appcache::kAppCacheDatabaseName); |
228 return new SqliteIntegrityTest(false, | 263 return new SqliteIntegrityTest(false, // critical |
264 false, // remove_if_corrupt | |
229 kSQLiteIntegrityAppCacheTest, | 265 kSQLiteIntegrityAppCacheTest, |
230 "Application Cache Database", | 266 "Application Cache Database", |
231 appcache_db); | 267 appcache_db); |
232 } | 268 } |
233 | 269 |
234 DiagnosticsTest* MakeSqliteWebDatabaseTrackerDbTest() { | 270 DiagnosticsTest* MakeSqliteWebDatabaseTrackerDbTest() { |
235 base::FilePath databases_dir(webkit_database::kDatabaseDirectoryName); | 271 base::FilePath databases_dir(webkit_database::kDatabaseDirectoryName); |
236 base::FilePath tracker_db = | 272 base::FilePath tracker_db = |
237 databases_dir.Append(webkit_database::kTrackerDatabaseFileName); | 273 databases_dir.Append(webkit_database::kTrackerDatabaseFileName); |
238 return new SqliteIntegrityTest(false, | 274 return new SqliteIntegrityTest(false, // critical |
275 false, // remove_if_corrupt | |
239 kSQLiteIntegrityDatabaseTrackerTest, | 276 kSQLiteIntegrityDatabaseTrackerTest, |
240 "Database Tracker Database", | 277 "Database Tracker Database", |
241 tracker_db); | 278 tracker_db); |
242 } | 279 } |
243 | 280 |
244 #if defined(OS_CHROMEOS) | 281 #if defined(OS_CHROMEOS) |
245 DiagnosticsTest* MakeSqliteNssCertDbTest() { | 282 DiagnosticsTest* MakeSqliteNssCertDbTest() { |
246 base::FilePath home_dir = file_util::GetHomeDir(); | 283 base::FilePath home_dir = file_util::GetHomeDir(); |
247 return new SqliteIntegrityTest(false, | 284 return new SqliteIntegrityTest(false, // critical |
285 true, // remove_if_corrupt | |
248 kSQLiteIntegrityNSSCertTest, | 286 kSQLiteIntegrityNSSCertTest, |
249 "NSS Certificate Database", | 287 "NSS Certificate Database", |
250 home_dir.Append(chromeos::kNssCertDbPath)); | 288 home_dir.Append(chromeos::kNssCertDbPath)); |
251 } | 289 } |
252 | 290 |
253 DiagnosticsTest* MakeSqliteNssKeyDbTest() { | 291 DiagnosticsTest* MakeSqliteNssKeyDbTest() { |
254 base::FilePath home_dir = file_util::GetHomeDir(); | 292 base::FilePath home_dir = file_util::GetHomeDir(); |
255 return new SqliteIntegrityTest(false, | 293 return new SqliteIntegrityTest(false, // critical |
294 true, // remove_if_corrupt | |
256 kSQLiteIntegrityNSSKeyTest, | 295 kSQLiteIntegrityNSSKeyTest, |
257 "NSS Key Database", | 296 "NSS Key Database", |
258 home_dir.Append(chromeos::kNssKeyDbPath)); | 297 home_dir.Append(chromeos::kNssKeyDbPath)); |
259 } | 298 } |
260 #endif // defined(OS_CHROMEOS) | 299 #endif // defined(OS_CHROMEOS) |
261 } // namespace diagnostics | 300 } // namespace diagnostics |
OLD | NEW |