| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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> |
| 14 |
| 13 #include "base/hash_tables.h" | 15 #include "base/hash_tables.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "chrome/browser/sync/protocol/service_constants.h" | 17 #include "chrome/browser/sync/protocol/service_constants.h" |
| 16 #include "chrome/browser/sync/syncable/syncable-inl.h" | 18 #include "chrome/browser/sync/syncable/syncable-inl.h" |
| 17 #include "chrome/browser/sync/syncable/syncable_columns.h" | 19 #include "chrome/browser/sync/syncable/syncable_columns.h" |
| 18 #include "chrome/browser/sync/util/crypto_helpers.h" | 20 #include "chrome/browser/sync/util/crypto_helpers.h" |
| 19 #include "chrome/browser/sync/util/query_helpers.h" | |
| 20 #include "chrome/common/sqlite_utils.h" | 21 #include "chrome/common/sqlite_utils.h" |
| 21 #include "third_party/sqlite/preprocessed/sqlite3.h" | 22 #include "third_party/sqlite/preprocessed/sqlite3.h" |
| 22 | 23 |
| 23 // Sometimes threads contend on the DB lock itself, especially when one thread | 24 // Sometimes threads contend on the DB lock itself, especially when one thread |
| 24 // is calling SaveChanges. In the worst case scenario, the user can put his | 25 // is calling SaveChanges. In the worst case scenario, the user can put his |
| 25 // laptop to sleep during db contention, and wake up the laptop days later, so | 26 // laptop to sleep during db contention, and wake up the laptop days later, so |
| 26 // infinity seems like the best choice here. | 27 // infinity seems like the best choice here. |
| 27 const int kDirectoryBackingStoreBusyTimeoutMs = std::numeric_limits<int>::max(); | 28 const int kDirectoryBackingStoreBusyTimeoutMs = std::numeric_limits<int>::max(); |
| 28 | 29 |
| 29 using std::string; | 30 using std::string; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 load_dbhandle_ = NULL; | 158 load_dbhandle_ = NULL; |
| 158 } | 159 } |
| 159 if (NULL != save_dbhandle_) { | 160 if (NULL != save_dbhandle_) { |
| 160 sqlite3_close(save_dbhandle_); | 161 sqlite3_close(save_dbhandle_); |
| 161 save_dbhandle_ = NULL; | 162 save_dbhandle_ = NULL; |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( | 166 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( |
| 166 sqlite3** handle) const { | 167 sqlite3** handle) const { |
| 167 if (SQLITE_OK == SqliteOpen(backing_filepath_, handle)) { | 168 if (SQLITE_OK == OpenSqliteDb(backing_filepath_, handle)) { |
| 169 sqlite3_busy_timeout(*handle, std::numeric_limits<int>::max()); |
| 170 { |
| 171 SQLStatement statement; |
| 172 statement.prepare(*handle, "PRAGMA fullfsync = 1"); |
| 173 if (SQLITE_DONE != statement.step()) { |
| 174 LOG(FATAL) << sqlite3_errmsg(*handle); |
| 175 } |
| 176 } |
| 177 { |
| 178 SQLStatement statement; |
| 179 statement.prepare(*handle, "PRAGMA synchronous = 2"); |
| 180 if (SQLITE_DONE != statement.step()) { |
| 181 LOG(FATAL) << sqlite3_errmsg(*handle); |
| 182 } |
| 183 } |
| 168 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); | 184 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); |
| 169 RegisterPathNameCollate(*handle); | 185 RegisterPathNameCollate(*handle); |
| 186 #if defined(OS_WIN) |
| 187 // Do not index this file. Scanning can occur every time we close the file, |
| 188 // which causes long delays in SQLite's file locking. |
| 189 const DWORD attrs = GetFileAttributes(backing_filepath_.value().c_str()); |
| 190 const BOOL attrs_set = |
| 191 SetFileAttributes(backing_filepath_.value().c_str(), |
| 192 attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); |
| 193 #endif |
| 170 | 194 |
| 171 return true; | 195 return true; |
| 172 } | 196 } |
| 173 return false; | 197 return false; |
| 174 } | 198 } |
| 175 | 199 |
| 176 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, | 200 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, |
| 177 ExtendedAttributes* xattrs_bucket, | 201 ExtendedAttributes* xattrs_bucket, |
| 178 Directory::KernelLoadInfo* kernel_load_info) { | 202 Directory::KernelLoadInfo* kernel_load_info) { |
| 179 DCHECK(load_dbhandle_ == NULL); | 203 DCHECK(load_dbhandle_ == NULL); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 604 |
| 581 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { | 605 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { |
| 582 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { | 606 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { |
| 583 DCHECK(FALSE) << "Unable to open handle for saving"; | 607 DCHECK(FALSE) << "Unable to open handle for saving"; |
| 584 return NULL; | 608 return NULL; |
| 585 } | 609 } |
| 586 return save_dbhandle_; | 610 return save_dbhandle_; |
| 587 } | 611 } |
| 588 | 612 |
| 589 } // namespace syncable | 613 } // namespace syncable |
| OLD | NEW |