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" |
| 8 |
7 #ifdef OS_MACOSX | 9 #ifdef OS_MACOSX |
8 #include <CoreFoundation/CoreFoundation.h> | 10 #include <CoreFoundation/CoreFoundation.h> |
9 #elif defined(OS_LINUX) | 11 #elif defined(OS_LINUX) |
10 #include <glib.h> | 12 #include <glib.h> |
11 #endif | 13 #endif |
12 | 14 |
13 #include <string> | 15 #include <string> |
14 | 16 |
15 #include "base/hash_tables.h" | 17 #include "base/hash_tables.h" |
16 #include "base/logging.h" | 18 #include "base/logging.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Sqlite allows setting of the escape character in an ESCAPE clause and | 62 // Sqlite allows setting of the escape character in an ESCAPE clause and |
61 // this character is passed in as a third character to the like function. | 63 // this character is passed in as a third character to the like function. |
62 // See: http://www.sqlite.org/lang_expr.html | 64 // See: http://www.sqlite.org/lang_expr.html |
63 static void PathNameMatch16WithEscape(sqlite3_context* context, | 65 static void PathNameMatch16WithEscape(sqlite3_context* context, |
64 int argc, sqlite3_value** argv) { | 66 int argc, sqlite3_value** argv) { |
65 // Never seen this called, but just in case. | 67 // Never seen this called, but just in case. |
66 LOG(FATAL) << "PathNameMatch16WithEscape() not implemented"; | 68 LOG(FATAL) << "PathNameMatch16WithEscape() not implemented"; |
67 } | 69 } |
68 | 70 |
69 static void RegisterPathNameCollate(sqlite3* dbhandle) { | 71 static void RegisterPathNameCollate(sqlite3* dbhandle) { |
70 #ifdef OS_WINDOWS | 72 #ifdef OS_WIN |
71 const int collate = SQLITE_UTF16; | 73 const int collate = SQLITE_UTF16; |
72 #else | 74 #else |
73 const int collate = SQLITE_UTF8; | 75 const int collate = SQLITE_UTF8; |
74 #endif | 76 #endif |
75 CHECK(SQLITE_OK == sqlite3_create_collation(dbhandle, "PATHNAME", collate, | 77 CHECK(SQLITE_OK == sqlite3_create_collation(dbhandle, "PATHNAME", collate, |
76 NULL, &ComparePathNames16)); | 78 NULL, &ComparePathNames16)); |
77 } | 79 } |
78 | 80 |
79 // Replace the LIKE operator with our own implementation that does file spec | 81 // Replace the LIKE operator with our own implementation that does file spec |
80 // matching like "*.txt". | 82 // matching like "*.txt". |
81 static void RegisterPathNameMatch(sqlite3* dbhandle) { | 83 static void RegisterPathNameMatch(sqlite3* dbhandle) { |
82 // We only register this on Windows. We use the normal sqlite | 84 // We only register this on Windows. We use the normal sqlite |
83 // matching function on mac/linux. | 85 // matching function on mac/linux. |
84 // note that the function PathNameMatch() does a simple == | 86 // note that the function PathNameMatch() does a simple == |
85 // comparison on mac, so that would have to be fixed if | 87 // comparison on mac, so that would have to be fixed if |
86 // we really wanted to use PathNameMatch on mac/linux w/ the | 88 // we really wanted to use PathNameMatch on mac/linux w/ the |
87 // same pattern strings as we do on windows. | 89 // same pattern strings as we do on windows. |
88 #ifdef OS_WINDOWS | 90 #ifdef OS_WIN |
89 CHECK(SQLITE_OK == sqlite3_create_function(dbhandle, "like", | 91 CHECK(SQLITE_OK == sqlite3_create_function(dbhandle, "like", |
90 2, SQLITE_ANY, NULL, &PathNameMatch16, NULL, NULL)); | 92 2, SQLITE_ANY, NULL, &PathNameMatch16, NULL, NULL)); |
91 CHECK(SQLITE_OK == sqlite3_create_function(dbhandle, "like", | 93 CHECK(SQLITE_OK == sqlite3_create_function(dbhandle, "like", |
92 3, SQLITE_ANY, NULL, &PathNameMatch16WithEscape, NULL, NULL)); | 94 3, SQLITE_ANY, NULL, &PathNameMatch16WithEscape, NULL, NULL)); |
93 #endif // OS_WINDOWS | 95 #endif // OS_WIN |
94 } | 96 } |
95 | 97 |
96 static inline bool IsSqliteErrorOurFault(int result) { | 98 static inline bool IsSqliteErrorOurFault(int result) { |
97 switch (result) { | 99 switch (result) { |
98 case SQLITE_MISMATCH: | 100 case SQLITE_MISMATCH: |
99 case SQLITE_CONSTRAINT: | 101 case SQLITE_CONSTRAINT: |
100 case SQLITE_MISUSE: | 102 case SQLITE_MISUSE: |
101 case SQLITE_RANGE: | 103 case SQLITE_RANGE: |
102 return true; | 104 return true; |
103 default: | 105 default: |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 651 |
650 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { | 652 sqlite3* DirectoryBackingStore::LazyGetSaveHandle() { |
651 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { | 653 if (!save_dbhandle_ && !OpenAndConfigureHandleHelper(&save_dbhandle_)) { |
652 DCHECK(FALSE) << "Unable to open handle for saving"; | 654 DCHECK(FALSE) << "Unable to open handle for saving"; |
653 return NULL; | 655 return NULL; |
654 } | 656 } |
655 return save_dbhandle_; | 657 return save_dbhandle_; |
656 } | 658 } |
657 | 659 |
658 } // namespace syncable | 660 } // namespace syncable |
OLD | NEW |