OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
10 #include <CoreFoundation/CoreFoundation.h> | 10 #include <CoreFoundation/CoreFoundation.h> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 | 14 |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/stl_util-inl.h" | |
18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
19 #include "chrome/browser/sync/protocol/service_constants.h" | 20 #include "chrome/browser/sync/protocol/service_constants.h" |
20 #include "chrome/browser/sync/protocol/sync.pb.h" | 21 #include "chrome/browser/sync/protocol/sync.pb.h" |
21 #include "chrome/browser/sync/syncable/syncable-inl.h" | 22 #include "chrome/browser/sync/syncable/syncable-inl.h" |
22 #include "chrome/browser/sync/syncable/syncable_columns.h" | 23 #include "chrome/browser/sync/syncable/syncable_columns.h" |
23 #include "chrome/browser/sync/util/crypto_helpers.h" | 24 #include "chrome/browser/sync/util/crypto_helpers.h" |
24 #include "chrome/common/sqlite_utils.h" | 25 #include "chrome/common/sqlite_utils.h" |
25 #include "third_party/sqlite/preprocessed/sqlite3.h" | 26 #include "third_party/sqlite/preprocessed/sqlite3.h" |
26 | 27 |
27 // Sometimes threads contend on the DB lock itself, especially when one thread | 28 // Sometimes threads contend on the DB lock itself, especially when one thread |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 const BOOL attrs_set = | 208 const BOOL attrs_set = |
208 SetFileAttributes(backing_filepath_.value().c_str(), | 209 SetFileAttributes(backing_filepath_.value().c_str(), |
209 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); | 210 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); |
210 #endif | 211 #endif |
211 | 212 |
212 return true; | 213 return true; |
213 } | 214 } |
214 return false; | 215 return false; |
215 } | 216 } |
216 | 217 |
218 DirOpenResult DirectoryBackingStore::DoLoad(MetahandlesIndex* entry_bucket, | |
219 Directory::KernelLoadInfo* kernel_load_info) { | |
220 { | |
221 DirOpenResult result = InitializeTables(); | |
222 if (result != OPENED) | |
223 return result; | |
224 } | |
225 | |
226 if (!DropDeletedEntries()) | |
227 return FAILED_DATABASE_CORRUPT; | |
228 if (!LoadEntries(entry_bucket)) | |
tim (not reviewing)
2010/07/28 19:00:54
I don't think this is what you were suggesting bef
ncarter (slow)
2010/07/28 19:17:19
It's a clever technique, but we need to handle the
| |
229 return FAILED_DATABASE_CORRUPT; | |
230 if (!LoadInfo(kernel_load_info)) | |
231 return FAILED_DATABASE_CORRUPT; | |
232 | |
233 return OPENED; | |
234 } | |
235 | |
217 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, | 236 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, |
218 Directory::KernelLoadInfo* kernel_load_info) { | 237 Directory::KernelLoadInfo* kernel_load_info) { |
238 | |
239 // Open database handle. | |
219 if (!BeginLoad()) | 240 if (!BeginLoad()) |
220 return FAILED_OPEN_DATABASE; | 241 return FAILED_OPEN_DATABASE; |
221 | 242 |
222 DirOpenResult result = InitializeTables(); | 243 // Load data from the database. |
223 if (OPENED != result) | 244 DirOpenResult result = DoLoad(entry_bucket, kernel_load_info); |
224 return result; | |
225 | 245 |
226 if (!DropDeletedEntries() || | 246 // Clean up partial results after failure. |
227 !LoadEntries(entry_bucket) || | 247 if (result != OPENED) |
228 !LoadInfo(kernel_load_info)) { | 248 STLDeleteElements(entry_bucket); |
229 return FAILED_DATABASE_CORRUPT; | |
230 } | |
231 | 249 |
250 // Close database handle. | |
232 EndLoad(); | 251 EndLoad(); |
233 return OPENED; | 252 |
253 return result; | |
234 } | 254 } |
235 | 255 |
236 bool DirectoryBackingStore::BeginLoad() { | 256 bool DirectoryBackingStore::BeginLoad() { |
237 DCHECK(load_dbhandle_ == NULL); | 257 DCHECK(load_dbhandle_ == NULL); |
238 bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_); | 258 bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_); |
239 if (ret) | 259 if (ret) |
240 return ret; | 260 return ret; |
241 // Something's gone wrong. Nuke the database and try again. | 261 // Something's gone wrong. Nuke the database and try again. |
242 LOG(ERROR) << "Sync database " << backing_filepath_.value() | 262 LOG(ERROR) << "Sync database " << backing_filepath_.value() |
243 << " corrupt. Deleting and recreating."; | 263 << " corrupt. Deleting and recreating."; |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 "name TEXT, " | 960 "name TEXT, " |
941 "store_birthday TEXT, " | 961 "store_birthday TEXT, " |
942 "db_create_version TEXT, " | 962 "db_create_version TEXT, " |
943 "db_create_time INT, " | 963 "db_create_time INT, " |
944 "next_id INT default -2, " | 964 "next_id INT default -2, " |
945 "cache_guid TEXT)"); | 965 "cache_guid TEXT)"); |
946 return ExecQuery(load_dbhandle_, query.c_str()); | 966 return ExecQuery(load_dbhandle_, query.c_str()); |
947 } | 967 } |
948 | 968 |
949 } // namespace syncable | 969 } // namespace syncable |
OLD | NEW |