OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/syncable/directory_backing_store.h" | 5 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 #endif | 229 #endif |
230 | 230 |
231 return true; | 231 return true; |
232 } | 232 } |
233 return false; | 233 return false; |
234 } | 234 } |
235 | 235 |
236 bool DirectoryBackingStore::CheckIntegrity(sqlite3* handle, string* error) | 236 bool DirectoryBackingStore::CheckIntegrity(sqlite3* handle, string* error) |
237 const { | 237 const { |
238 sqlite_utils::SQLStatement statement; | 238 sqlite_utils::SQLStatement statement; |
239 if (SQLITE_OK != | 239 statement.prepare(handle, "PRAGMA integrity_check(1)"); |
240 statement.prepare(handle, "PRAGMA integrity_check(1)")) { | |
241 *error = sqlite3_errmsg(handle); | |
242 return false; | |
243 } | |
244 if (SQLITE_ROW != statement.step()) { | 240 if (SQLITE_ROW != statement.step()) { |
245 *error = sqlite3_errmsg(handle); | 241 *error = sqlite3_errmsg(handle); |
246 return false; | 242 return false; |
247 } | 243 } |
248 string integrity_result = statement.column_text(0); | 244 string integrity_result = statement.column_text(0); |
249 if (integrity_result != "ok") { | 245 if (integrity_result != "ok") { |
250 *error = integrity_result; | 246 *error = integrity_result; |
251 return false; | 247 return false; |
252 } | 248 } |
253 return true; | 249 return true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 STLDeleteElements(entry_bucket); | 282 STLDeleteElements(entry_bucket); |
287 | 283 |
288 // Close database handle. | 284 // Close database handle. |
289 EndLoad(); | 285 EndLoad(); |
290 | 286 |
291 return result; | 287 return result; |
292 } | 288 } |
293 | 289 |
294 bool DirectoryBackingStore::BeginLoad() { | 290 bool DirectoryBackingStore::BeginLoad() { |
295 DCHECK(load_dbhandle_ == NULL); | 291 DCHECK(load_dbhandle_ == NULL); |
296 return OpenAndConfigureHandleHelper(&load_dbhandle_); | 292 bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_); |
| 293 if (ret) |
| 294 return true; |
| 295 // Something's gone wrong. Nuke the database and try again. |
| 296 using ::operator<<; // For string16. |
| 297 LOG(ERROR) << "Sync database " << backing_filepath_.value() |
| 298 << " corrupt. Deleting and recreating."; |
| 299 file_util::Delete(backing_filepath_, false); |
| 300 bool failed_again = !OpenAndConfigureHandleHelper(&load_dbhandle_); |
| 301 |
| 302 // Using failed_again here lets us distinguish from cases where corruption |
| 303 // occurred even when re-opening a fresh directory (they'll go in a separate |
| 304 // double weight histogram bucket). Failing twice in a row means we disable |
| 305 // sync, so it's useful to see this number separately. |
| 306 int bucket = failed_again ? 2 : 1; |
| 307 #if defined(OS_WIN) |
| 308 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedWin", bucket); |
| 309 #elif defined(OS_MACOSX) |
| 310 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedMac", bucket); |
| 311 #else |
| 312 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedNotWinMac", bucket); |
| 313 |
| 314 #if defined(OS_CHROMEOS) |
| 315 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedCros", bucket); |
| 316 #elif defined(OS_LINUX) |
| 317 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedLinux", bucket); |
| 318 #else |
| 319 UMA_HISTOGRAM_COUNTS_100("Sync.DirectoryOpenFailedOther", bucket); |
| 320 #endif // OS_LINUX && !OS_CHROMEOS |
| 321 #endif // OS_WIN |
| 322 return !failed_again; |
297 } | 323 } |
298 | 324 |
299 void DirectoryBackingStore::EndLoad() { | 325 void DirectoryBackingStore::EndLoad() { |
300 sqlite3_close(load_dbhandle_); | 326 sqlite3_close(load_dbhandle_); |
301 load_dbhandle_ = NULL; // No longer used. | 327 load_dbhandle_ = NULL; // No longer used. |
302 } | 328 } |
303 | 329 |
304 void DirectoryBackingStore::EndSave() { | 330 void DirectoryBackingStore::EndSave() { |
305 sqlite3_close(save_dbhandle_); | 331 sqlite3_close(save_dbhandle_); |
306 save_dbhandle_ = NULL; | 332 save_dbhandle_ = NULL; |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 "id TEXT primary key, " | 1270 "id TEXT primary key, " |
1245 "name TEXT, " | 1271 "name TEXT, " |
1246 "store_birthday TEXT, " | 1272 "store_birthday TEXT, " |
1247 "db_create_version TEXT, " | 1273 "db_create_version TEXT, " |
1248 "db_create_time INT, " | 1274 "db_create_time INT, " |
1249 "next_id INT default -2, " | 1275 "next_id INT default -2, " |
1250 "cache_guid TEXT )"); | 1276 "cache_guid TEXT )"); |
1251 return ExecQuery(load_dbhandle_, query.c_str()); | 1277 return ExecQuery(load_dbhandle_, query.c_str()); |
1252 } | 1278 } |
1253 } // namespace syncable | 1279 } // namespace syncable |
OLD | NEW |