OLD | NEW |
| (Empty) |
1 From 0a5da8cd79a6b502edc01c40037ae418b2d5c828 Mon Sep 17 00:00:00 2001 | |
2 From: dumi <dumi@chromium.org> | |
3 Date: Mon, 20 Jul 2009 23:40:51 +0000 | |
4 Subject: [PATCH 04/10] Modify default VFS to support WebDatabase. | |
5 | |
6 The renderer WebDatabase implementation needs to broker certain requests | |
7 to the browser. This modifies SQLite to allow monkey-patching the VFS | |
8 to support this. | |
9 | |
10 NOTE(shess): This patch relies on core SQLite implementation details | |
11 remaining unchanged. When importing a new version of SQLite, pay very | |
12 close attention to whether the change is still doing what is intended. | |
13 | |
14 Original review URLs: | |
15 https://codereview.chromium.org/159044 | |
16 https://codereview.chromium.org/384075 | |
17 https://codereview.chromium.org/377039 | |
18 [Possibly not a complete list.] | |
19 --- | |
20 third_party/sqlite/src/src/os_unix.c | 49 ++++++++++++++++++++++++++++++++++ | |
21 third_party/sqlite/src/src/os_win.c | 8 ++++++ | |
22 third_party/sqlite/src/src/sqlite.h.in | 23 ++++++++++++++++ | |
23 3 files changed, 80 insertions(+) | |
24 | |
25 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/o
s_unix.c | |
26 index 791ba5d..fa85638 100644 | |
27 --- a/third_party/sqlite/src/src/os_unix.c | |
28 +++ b/third_party/sqlite/src/src/os_unix.c | |
29 @@ -1297,6 +1297,12 @@ static int fileHasMoved(unixFile *pFile){ | |
30 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; | |
31 #else | |
32 struct stat buf; | |
33 + | |
34 + /* TODO(shess): This check doesn't work when the Chromium's WebDB code is | |
35 + ** running in the sandbox. | |
36 + */ | |
37 + return 0; | |
38 + | |
39 return pFile->pInode!=0 && | |
40 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); | |
41 #endif | |
42 @@ -5554,6 +5560,44 @@ static int findCreateFileMode( | |
43 } | |
44 | |
45 /* | |
46 +** Initialize |unixFile| internals of |file| on behalf of chromiumOpen() in | |
47 +** WebDatabase SQLiteFileSystemPosix.cpp. Function is a subset of unixOpen(), | |
48 +** each duplicated piece is marked by "Duplicated in" comment in unixOpen(). | |
49 +*/ | |
50 +CHROMIUM_SQLITE_API | |
51 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, | |
52 + int fd, | |
53 + sqlite3_file* pFile, | |
54 + const char* zPath, | |
55 + int noLock, | |
56 + int flags) { | |
57 + unixFile *p = (unixFile *)pFile; | |
58 + const int eType = flags&0xFFFFFF00; /* Type of file to open */ | |
59 + const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0); | |
60 + int rc; | |
61 + | |
62 + memset(p, 0, sizeof(unixFile)); | |
63 + | |
64 + /* osStat() will not work in the sandbox, so findReusableFd() will always | |
65 + ** fail, so directly include the failure-case setup then initialize pUnused. | |
66 + */ | |
67 + if( eType==SQLITE_OPEN_MAIN_DB ){ | |
68 + p->pUnused = sqlite3_malloc(sizeof(*p->pUnused)); | |
69 + if (!p->pUnused) { | |
70 + return SQLITE_NOMEM; | |
71 + } | |
72 + p->pUnused->fd = fd; | |
73 + p->pUnused->flags = flags; | |
74 + } | |
75 + | |
76 + rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); | |
77 + if( rc!=SQLITE_OK ){ | |
78 + sqlite3_free(p->pUnused); | |
79 + } | |
80 + return rc; | |
81 +} | |
82 + | |
83 +/* | |
84 ** Open the file zPath. | |
85 ** | |
86 ** Previously, the SQLite OS layer used three functions in place of this | |
87 @@ -5654,6 +5698,7 @@ static int unixOpen( | |
88 sqlite3_randomness(0,0); | |
89 } | |
90 | |
91 + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ | |
92 memset(p, 0, sizeof(unixFile)); | |
93 | |
94 if( eType==SQLITE_OPEN_MAIN_DB ){ | |
95 @@ -5662,6 +5707,7 @@ static int unixOpen( | |
96 if( pUnused ){ | |
97 fd = pUnused->fd; | |
98 }else{ | |
99 + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ | |
100 pUnused = sqlite3_malloc64(sizeof(*pUnused)); | |
101 if( !pUnused ){ | |
102 return SQLITE_NOMEM; | |
103 @@ -5739,6 +5785,7 @@ static int unixOpen( | |
104 } | |
105 | |
106 if( p->pUnused ){ | |
107 + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ | |
108 p->pUnused->fd = fd; | |
109 p->pUnused->flags = flags; | |
110 } | |
111 @@ -5819,10 +5866,12 @@ static int unixOpen( | |
112 } | |
113 #endif | |
114 | |
115 + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ | |
116 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); | |
117 | |
118 open_finished: | |
119 if( rc!=SQLITE_OK ){ | |
120 + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ | |
121 sqlite3_free(p->pUnused); | |
122 } | |
123 return rc; | |
124 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os
_win.c | |
125 index c54bfd6..00ad6fd 100644 | |
126 --- a/third_party/sqlite/src/src/os_win.c | |
127 +++ b/third_party/sqlite/src/src/os_win.c | |
128 @@ -5639,4 +5639,12 @@ int sqlite3_os_end(void){ | |
129 return SQLITE_OK; | |
130 } | |
131 | |
132 +CHROMIUM_SQLITE_API | |
133 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE ha
ndle) { | |
134 + winFile* winSQLite3File = (winFile*)file; | |
135 + memset(file, 0, sizeof(*file)); | |
136 + winSQLite3File->pMethod = &winIoMethod; | |
137 + winSQLite3File->h = handle; | |
138 +} | |
139 + | |
140 #endif /* SQLITE_OS_WIN */ | |
141 diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src
/sqlite.h.in | |
142 index 59b30cd..e5673fd 100644 | |
143 --- a/third_party/sqlite/src/src/sqlite.h.in | |
144 +++ b/third_party/sqlite/src/src/sqlite.h.in | |
145 @@ -7411,6 +7411,29 @@ int sqlite3_strnicmp(const char *, const char *, int); | |
146 */ | |
147 int sqlite3_strglob(const char *zGlob, const char *zStr); | |
148 | |
149 +/* Begin WebDatabase patch for Chromium */ | |
150 +/* Expose some SQLite internals for the WebDatabase vfs. | |
151 +** DO NOT EXTEND THE USE OF THIS. | |
152 +*/ | |
153 +#ifndef CHROMIUM_SQLITE_API | |
154 +#define CHROMIUM_SQLITE_API SQLITE_API | |
155 +#endif | |
156 +#if defined(CHROMIUM_SQLITE_INTERNALS) | |
157 +#ifdef _WIN32 | |
158 +CHROMIUM_SQLITE_API | |
159 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE ha
ndle); | |
160 +#else /* _WIN32 */ | |
161 +CHROMIUM_SQLITE_API | |
162 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, | |
163 + int fd, | |
164 + sqlite3_file* pFile, | |
165 + const char* zPath, | |
166 + int noLock, | |
167 + int flags); | |
168 +#endif /* _WIN32 */ | |
169 +#endif /* CHROMIUM_SQLITE_INTERNALS */ | |
170 +/* End WebDatabase patch for Chromium */ | |
171 + | |
172 /* | |
173 ** CAPI3REF: String LIKE Matching | |
174 * | |
175 -- | |
176 2.7.0 | |
177 | |
OLD | NEW |