| 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> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // this character is passed in as a third character to the like function. | 64 // this character is passed in as a third character to the like function. |
| 65 // See: http://www.sqlite.org/lang_expr.html | 65 // See: http://www.sqlite.org/lang_expr.html |
| 66 static void PathNameMatch16WithEscape(sqlite3_context* context, | 66 static void PathNameMatch16WithEscape(sqlite3_context* context, |
| 67 int argc, sqlite3_value** argv) { | 67 int argc, sqlite3_value** argv) { |
| 68 // Never seen this called, but just in case. | 68 // Never seen this called, but just in case. |
| 69 LOG(FATAL) << "PathNameMatch16WithEscape() not implemented"; | 69 LOG(FATAL) << "PathNameMatch16WithEscape() not implemented"; |
| 70 } | 70 } |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 static void RegisterPathNameCollate(sqlite3* dbhandle) { | 73 static void RegisterPathNameCollate(sqlite3* dbhandle) { |
| 74 #if defined(OS_WIN) | |
| 75 const int collate = SQLITE_UTF16; | |
| 76 #else | |
| 77 const int collate = SQLITE_UTF8; | 74 const int collate = SQLITE_UTF8; |
| 78 #endif | |
| 79 CHECK(SQLITE_OK == sqlite3_create_collation(dbhandle, "PATHNAME", collate, | 75 CHECK(SQLITE_OK == sqlite3_create_collation(dbhandle, "PATHNAME", collate, |
| 80 NULL, &ComparePathNames16)); | 76 NULL, &ComparePathNames16)); |
| 81 } | 77 } |
| 82 | 78 |
| 83 // Replace the LIKE operator with our own implementation that does file spec | 79 // Replace the LIKE operator with our own implementation that does file spec |
| 84 // matching like "*.txt". | 80 // matching like "*.txt". |
| 85 static void RegisterPathNameMatch(sqlite3* dbhandle) { | 81 static void RegisterPathNameMatch(sqlite3* dbhandle) { |
| 86 // We only register this on Windows. We use the normal sqlite | 82 // We only register this on Windows. We use the normal sqlite |
| 87 // matching function on mac/linux. | 83 // matching function on mac/linux. |
| 88 // note that the function PathNameMatch() does a simple == | 84 // note that the function PathNameMatch() does a simple == |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 query.append(column->spec); | 235 query.append(column->spec); |
| 240 } | 236 } |
| 241 query.push_back(')'); | 237 query.push_back(')'); |
| 242 return query; | 238 return query; |
| 243 } | 239 } |
| 244 | 240 |
| 245 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
| 246 // DirectoryBackingStore implementation. | 242 // DirectoryBackingStore implementation. |
| 247 | 243 |
| 248 DirectoryBackingStore::DirectoryBackingStore(const PathString& dir_name, | 244 DirectoryBackingStore::DirectoryBackingStore(const PathString& dir_name, |
| 249 const PathString& backing_filepath) | 245 const FilePath& backing_filepath) |
| 250 : load_dbhandle_(NULL), | 246 : load_dbhandle_(NULL), |
| 251 save_dbhandle_(NULL), | 247 save_dbhandle_(NULL), |
| 252 dir_name_(dir_name), | 248 dir_name_(dir_name), |
| 253 backing_filepath_(backing_filepath) { | 249 backing_filepath_(backing_filepath) { |
| 254 } | 250 } |
| 255 | 251 |
| 256 DirectoryBackingStore::~DirectoryBackingStore() { | 252 DirectoryBackingStore::~DirectoryBackingStore() { |
| 257 if (NULL != load_dbhandle_) { | 253 if (NULL != load_dbhandle_) { |
| 258 sqlite3_close(load_dbhandle_); | 254 sqlite3_close(load_dbhandle_); |
| 259 load_dbhandle_ = NULL; | 255 load_dbhandle_ = NULL; |
| 260 } | 256 } |
| 261 if (NULL != save_dbhandle_) { | 257 if (NULL != save_dbhandle_) { |
| 262 sqlite3_close(save_dbhandle_); | 258 sqlite3_close(save_dbhandle_); |
| 263 save_dbhandle_ = NULL; | 259 save_dbhandle_ = NULL; |
| 264 } | 260 } |
| 265 } | 261 } |
| 266 | 262 |
| 267 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( | 263 bool DirectoryBackingStore::OpenAndConfigureHandleHelper( |
| 268 sqlite3** handle) const { | 264 sqlite3** handle) const { |
| 269 if (SQLITE_OK == SqliteOpen(backing_filepath_.c_str(), handle)) { | 265 if (SQLITE_OK == SqliteOpen(backing_filepath_, handle)) { |
| 270 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); | 266 sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs); |
| 271 RegisterPathNameCollate(*handle); | 267 RegisterPathNameCollate(*handle); |
| 272 RegisterPathNameMatch(*handle); | 268 RegisterPathNameMatch(*handle); |
| 273 return true; | 269 return true; |
| 274 } | 270 } |
| 275 return false; | 271 return false; |
| 276 } | 272 } |
| 277 | 273 |
| 278 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, | 274 DirOpenResult DirectoryBackingStore::Load(MetahandlesIndex* entry_bucket, |
| 279 ExtendedAttributes* xattrs_bucket, | 275 ExtendedAttributes* xattrs_bucket, |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 651 |
| 656 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { | 652 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { |
| 657 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { | 653 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { |
| 658 DCHECK(FALSE) << "Unable to open handle for saving"; | 654 DCHECK(FALSE) << "Unable to open handle for saving"; |
| 659 return NULL; | 655 return NULL; |
| 660 } | 656 } |
| 661 return save_dbhandle_; | 657 return save_dbhandle_; |
| 662 } | 658 } |
| 663 | 659 |
| 664 } // namespace syncable | 660 } // namespace syncable |
| OLD | NEW |