OLD | NEW |
1 // Copyright (c) 2009 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/hash_tables.h" | 16 #include "base/hash_tables.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
18 #include "chrome/browser/sync/protocol/service_constants.h" | 19 #include "chrome/browser/sync/protocol/service_constants.h" |
19 #include "chrome/browser/sync/protocol/sync.pb.h" | 20 #include "chrome/browser/sync/protocol/sync.pb.h" |
20 #include "chrome/browser/sync/syncable/syncable-inl.h" | 21 #include "chrome/browser/sync/syncable/syncable-inl.h" |
21 #include "chrome/browser/sync/syncable/syncable_columns.h" | 22 #include "chrome/browser/sync/syncable/syncable_columns.h" |
22 #include "chrome/browser/sync/util/crypto_helpers.h" | 23 #include "chrome/browser/sync/util/crypto_helpers.h" |
23 #include "chrome/common/sqlite_utils.h" | 24 #include "chrome/common/sqlite_utils.h" |
24 #include "third_party/sqlite/preprocessed/sqlite3.h" | 25 #include "third_party/sqlite/preprocessed/sqlite3.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 177 } |
177 | 178 |
178 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( | 179 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( |
179 sqlite3** handle) const { | 180 sqlite3** handle) const { |
180 if (SQLITE_OK == OpenSqliteDb(backing_filepath_, handle)) { | 181 if (SQLITE_OK == OpenSqliteDb(backing_filepath_, handle)) { |
181 sqlite3_busy_timeout(*handle, std::numeric_limits<int>::max()); | 182 sqlite3_busy_timeout(*handle, std::numeric_limits<int>::max()); |
182 { | 183 { |
183 SQLStatement statement; | 184 SQLStatement statement; |
184 statement.prepare(*handle, "PRAGMA fullfsync = 1"); | 185 statement.prepare(*handle, "PRAGMA fullfsync = 1"); |
185 if (SQLITE_DONE != statement.step()) { | 186 if (SQLITE_DONE != statement.step()) { |
186 LOG(FATAL) << sqlite3_errmsg(*handle); | 187 LOG(ERROR) << sqlite3_errmsg(*handle); |
| 188 return false; |
187 } | 189 } |
188 } | 190 } |
189 { | 191 { |
190 SQLStatement statement; | 192 SQLStatement statement; |
191 statement.prepare(*handle, "PRAGMA synchronous = 2"); | 193 statement.prepare(*handle, "PRAGMA synchronous = 2"); |
192 if (SQLITE_DONE != statement.step()) { | 194 if (SQLITE_DONE != statement.step()) { |
193 LOG(FATAL) << sqlite3_errmsg(*handle); | 195 LOG(ERROR) << sqlite3_errmsg(*handle); |
| 196 return false; |
194 } | 197 } |
195 } | 198 } |
196 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); | 199 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); |
197 #if defined(OS_WIN) | 200 #if defined(OS_WIN) |
198 // Do not index this file. Scanning can occur every time we close the file, | 201 // Do not index this file. Scanning can occur every time we close the file, |
199 // which causes long delays in SQLite's file locking. | 202 // which causes long delays in SQLite's file locking. |
200 const DWORD attrs = GetFileAttributes(backing_filepath_.value().c_str()); | 203 const DWORD attrs = GetFileAttributes(backing_filepath_.value().c_str()); |
201 const BOOL attrs_set = | 204 const BOOL attrs_set = |
202 SetFileAttributes(backing_filepath_.value().c_str(), | 205 SetFileAttributes(backing_filepath_.value().c_str(), |
203 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); | 206 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); |
(...skipping 18 matching lines...) Expand all Loading... |
222 LoadEntries(entry_bucket); | 225 LoadEntries(entry_bucket); |
223 LoadExtendedAttributes(xattrs_bucket); | 226 LoadExtendedAttributes(xattrs_bucket); |
224 LoadInfo(kernel_load_info); | 227 LoadInfo(kernel_load_info); |
225 | 228 |
226 EndLoad(); | 229 EndLoad(); |
227 return OPENED; | 230 return OPENED; |
228 } | 231 } |
229 | 232 |
230 bool DirectoryBackingStore::BeginLoad() { | 233 bool DirectoryBackingStore::BeginLoad() { |
231 DCHECK(load_dbhandle_ == NULL); | 234 DCHECK(load_dbhandle_ == NULL); |
| 235 bool ret = OpenAndConfigureHandleHelper(&load_dbhandle_); |
| 236 if (ret) |
| 237 return ret; |
| 238 // Something's gone wrong. Nuke the database and try again. |
| 239 LOG(ERROR) << "Sync database " << backing_filepath_.value() |
| 240 << " corrupt. Deleting and recreating."; |
| 241 file_util::Delete(backing_filepath_, false); |
232 return OpenAndConfigureHandleHelper(&load_dbhandle_); | 242 return OpenAndConfigureHandleHelper(&load_dbhandle_); |
233 } | 243 } |
234 | 244 |
235 void DirectoryBackingStore::EndLoad() { | 245 void DirectoryBackingStore::EndLoad() { |
236 sqlite3_close(load_dbhandle_); | 246 sqlite3_close(load_dbhandle_); |
237 load_dbhandle_ = NULL; // No longer used. | 247 load_dbhandle_ = NULL; // No longer used. |
238 } | 248 } |
239 | 249 |
240 bool DirectoryBackingStore::SaveChanges( | 250 bool DirectoryBackingStore::SaveChanges( |
241 const Directory::SaveChangesSnapshot& snapshot) { | 251 const Directory::SaveChangesSnapshot& snapshot) { |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 "name TEXT, " | 979 "name TEXT, " |
970 "store_birthday TEXT, " | 980 "store_birthday TEXT, " |
971 "db_create_version TEXT, " | 981 "db_create_version TEXT, " |
972 "db_create_time INT, " | 982 "db_create_time INT, " |
973 "next_id INT default -2, " | 983 "next_id INT default -2, " |
974 "cache_guid TEXT)"); | 984 "cache_guid TEXT)"); |
975 return ExecQuery(load_dbhandle_, query.c_str()); | 985 return ExecQuery(load_dbhandle_, query.c_str()); |
976 } | 986 } |
977 | 987 |
978 } // namespace syncable | 988 } // namespace syncable |
OLD | NEW |