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 "sync/syncable/on_disk_directory_backing_store.h" | 5 #include "sync/syncable/on_disk_directory_backing_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "sync/syncable/syncable-inl.h" | 10 #include "sync/syncable/syncable-inl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 allow_failure_for_test_(false), | 29 allow_failure_for_test_(false), |
30 backing_filepath_(backing_filepath) { | 30 backing_filepath_(backing_filepath) { |
31 db_->set_exclusive_locking(); | 31 db_->set_exclusive_locking(); |
32 db_->set_page_size(4096); | 32 db_->set_page_size(4096); |
33 } | 33 } |
34 | 34 |
35 OnDiskDirectoryBackingStore::~OnDiskDirectoryBackingStore() { } | 35 OnDiskDirectoryBackingStore::~OnDiskDirectoryBackingStore() { } |
36 | 36 |
37 DirOpenResult OnDiskDirectoryBackingStore::TryLoad( | 37 DirOpenResult OnDiskDirectoryBackingStore::TryLoad( |
38 MetahandlesIndex* entry_bucket, | 38 MetahandlesIndex* entry_bucket, |
| 39 JournalIndex* delete_journals, |
39 Directory::KernelLoadInfo* kernel_load_info) { | 40 Directory::KernelLoadInfo* kernel_load_info) { |
40 DCHECK(CalledOnValidThread()); | 41 DCHECK(CalledOnValidThread()); |
41 if (!db_->is_open()) { | 42 if (!db_->is_open()) { |
42 if (!db_->Open(backing_filepath_)) | 43 if (!db_->Open(backing_filepath_)) |
43 return FAILED_OPEN_DATABASE; | 44 return FAILED_OPEN_DATABASE; |
44 } | 45 } |
45 | 46 |
46 if (!InitializeTables()) | 47 if (!InitializeTables()) |
47 return FAILED_OPEN_DATABASE; | 48 return FAILED_OPEN_DATABASE; |
48 | 49 |
49 if (!DropDeletedEntries()) | 50 if (!DropDeletedEntries()) |
50 return FAILED_DATABASE_CORRUPT; | 51 return FAILED_DATABASE_CORRUPT; |
51 if (!LoadEntries(entry_bucket)) | 52 if (!LoadEntries(entry_bucket)) |
52 return FAILED_DATABASE_CORRUPT; | 53 return FAILED_DATABASE_CORRUPT; |
| 54 if (!LoadDeleteJournals(delete_journals)) |
| 55 return FAILED_DATABASE_CORRUPT; |
53 if (!LoadInfo(kernel_load_info)) | 56 if (!LoadInfo(kernel_load_info)) |
54 return FAILED_DATABASE_CORRUPT; | 57 return FAILED_DATABASE_CORRUPT; |
55 if (!VerifyReferenceIntegrity(*entry_bucket)) | 58 if (!VerifyReferenceIntegrity(*entry_bucket)) |
56 return FAILED_DATABASE_CORRUPT; | 59 return FAILED_DATABASE_CORRUPT; |
57 | 60 |
58 return OPENED; | 61 return OPENED; |
59 | 62 |
60 } | 63 } |
61 | 64 |
62 DirOpenResult OnDiskDirectoryBackingStore::Load( | 65 DirOpenResult OnDiskDirectoryBackingStore::Load( |
63 MetahandlesIndex* entry_bucket, | 66 MetahandlesIndex* entry_bucket, |
| 67 JournalIndex* delete_journals, |
64 Directory::KernelLoadInfo* kernel_load_info) { | 68 Directory::KernelLoadInfo* kernel_load_info) { |
65 DirOpenResult result = TryLoad(entry_bucket, kernel_load_info); | 69 DirOpenResult result = TryLoad(entry_bucket, delete_journals, |
| 70 kernel_load_info); |
66 if (result == OPENED) { | 71 if (result == OPENED) { |
67 UMA_HISTOGRAM_ENUMERATION( | 72 UMA_HISTOGRAM_ENUMERATION( |
68 "Sync.DirectoryOpenResult", FIRST_TRY_SUCCESS, RESULT_COUNT); | 73 "Sync.DirectoryOpenResult", FIRST_TRY_SUCCESS, RESULT_COUNT); |
69 return OPENED; | 74 return OPENED; |
70 } | 75 } |
71 | 76 |
72 ReportFirstTryOpenFailure(); | 77 ReportFirstTryOpenFailure(); |
73 | 78 |
74 // The fallback: delete the current database and return a fresh one. We can | 79 // The fallback: delete the current database and return a fresh one. We can |
75 // fetch the user's data from the could. | 80 // fetch the user's data from the cloud. |
76 STLDeleteElements(entry_bucket); | 81 STLDeleteElements(entry_bucket); |
| 82 STLDeleteElements(delete_journals); |
77 db_.reset(new sql::Connection); | 83 db_.reset(new sql::Connection); |
78 file_util::Delete(backing_filepath_, false); | 84 file_util::Delete(backing_filepath_, false); |
79 | 85 |
80 result = TryLoad(entry_bucket, kernel_load_info); | 86 result = TryLoad(entry_bucket, delete_journals, kernel_load_info); |
81 if (result == OPENED) { | 87 if (result == OPENED) { |
82 UMA_HISTOGRAM_ENUMERATION( | 88 UMA_HISTOGRAM_ENUMERATION( |
83 "Sync.DirectoryOpenResult", SECOND_TRY_SUCCESS, RESULT_COUNT); | 89 "Sync.DirectoryOpenResult", SECOND_TRY_SUCCESS, RESULT_COUNT); |
84 } else { | 90 } else { |
85 UMA_HISTOGRAM_ENUMERATION( | 91 UMA_HISTOGRAM_ENUMERATION( |
86 "Sync.DirectoryOpenResult", SECOND_TRY_FAILURE, RESULT_COUNT); | 92 "Sync.DirectoryOpenResult", SECOND_TRY_FAILURE, RESULT_COUNT); |
87 } | 93 } |
88 | 94 |
89 return result; | 95 return result; |
90 } | 96 } |
91 | 97 |
92 void OnDiskDirectoryBackingStore::ReportFirstTryOpenFailure() { | 98 void OnDiskDirectoryBackingStore::ReportFirstTryOpenFailure() { |
93 // In debug builds, the last thing we want is to silently clear the database. | 99 // In debug builds, the last thing we want is to silently clear the database. |
94 // It's full of evidence that might help us determine what went wrong. It | 100 // It's full of evidence that might help us determine what went wrong. It |
95 // might be sqlite's fault, but it could also be a bug in sync. We crash | 101 // might be sqlite's fault, but it could also be a bug in sync. We crash |
96 // immediately so a developer can investigate. | 102 // immediately so a developer can investigate. |
97 // | 103 // |
98 // Developers: If you're not interested in debugging this right now, just move | 104 // Developers: If you're not interested in debugging this right now, just move |
99 // aside the 'Sync Data' directory in your profile. This is similar to what | 105 // aside the 'Sync Data' directory in your profile. This is similar to what |
100 // the code would do if this DCHECK were disabled. | 106 // the code would do if this DCHECK were disabled. |
101 NOTREACHED() << "Crashing to preserve corrupt sync database"; | 107 NOTREACHED() << "Crashing to preserve corrupt sync database"; |
102 } | 108 } |
103 | 109 |
104 } // namespace syncable | 110 } // namespace syncable |
105 } // namespace syncer | 111 } // namespace syncer |
OLD | NEW |