OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sql/mojo/mojo_vfs.h" | 5 #include "sql/mojo/mojo_vfs.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/stringprintf.h" | |
9 #include "components/filesystem/public/interfaces/file.mojom.h" | 10 #include "components/filesystem/public/interfaces/file.mojom.h" |
10 #include "components/filesystem/public/interfaces/file_system.mojom.h" | 11 #include "components/filesystem/public/interfaces/file_system.mojom.h" |
11 #include "components/filesystem/public/interfaces/types.mojom.h" | 12 #include "components/filesystem/public/interfaces/types.mojom.h" |
12 #include "mojo/public/cpp/bindings/lib/template_util.h" | 13 #include "mojo/public/cpp/bindings/lib/template_util.h" |
13 #include "mojo/util/capture_util.h" | 14 #include "mojo/util/capture_util.h" |
14 #include "third_party/sqlite/sqlite3.h" | 15 #include "third_party/sqlite/sqlite3.h" |
15 | 16 |
16 using mojo::Capture; | 17 using mojo::Capture; |
17 | 18 |
18 namespace sql { | 19 namespace sql { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 197 } |
197 | 198 |
198 int MojoVFSSectorSize(sqlite3_file* pFile) { | 199 int MojoVFSSectorSize(sqlite3_file* pFile) { |
199 DVLOG(1) << "MojoVFSSectorSize(*)"; | 200 DVLOG(1) << "MojoVFSSectorSize(*)"; |
200 // Use the default sector size. | 201 // Use the default sector size. |
201 return 0; | 202 return 0; |
202 } | 203 } |
203 | 204 |
204 int MojoVFSDeviceCharacteristics(sqlite3_file* pFile) { | 205 int MojoVFSDeviceCharacteristics(sqlite3_file* pFile) { |
205 DVLOG(1) << "MojoVFSDeviceCharacteristics(*)"; | 206 DVLOG(1) << "MojoVFSDeviceCharacteristics(*)"; |
206 NOTIMPLEMENTED(); | 207 // TODO(erg): Figure out what to return here. (This function is super spammy, |
208 // so not leaving a NOTIMPLEMENTED().) | |
Scott Hess - ex-Googler
2015/07/21 21:55:24
I think "return 0;" is a fine implementation of th
| |
207 return 0; | 209 return 0; |
208 } | 210 } |
209 | 211 |
210 static sqlite3_io_methods mojo_vfs_io_methods = { | 212 static sqlite3_io_methods mojo_vfs_io_methods = { |
211 1, /* iVersion */ | 213 1, /* iVersion */ |
212 MojoVFSClose, /* xClose */ | 214 MojoVFSClose, /* xClose */ |
213 MojoVFSRead, /* xRead */ | 215 MojoVFSRead, /* xRead */ |
214 MojoVFSWrite, /* xWrite */ | 216 MojoVFSWrite, /* xWrite */ |
215 MojoVFSTruncate, /* xTruncate */ | 217 MojoVFSTruncate, /* xTruncate */ |
216 MojoVFSSync, /* xSync */ | 218 MojoVFSSync, /* xSync */ |
(...skipping 21 matching lines...) Expand all Loading... | |
238 open_flags = filesystem::kFlagOpenAlways; | 240 open_flags = filesystem::kFlagOpenAlways; |
239 } else { | 241 } else { |
240 open_flags = filesystem::kFlagOpen; | 242 open_flags = filesystem::kFlagOpen; |
241 } | 243 } |
242 open_flags |= filesystem::kFlagRead; | 244 open_flags |= filesystem::kFlagRead; |
243 if (flags & SQLITE_OPEN_READWRITE) | 245 if (flags & SQLITE_OPEN_READWRITE) |
244 open_flags |= filesystem::kFlagWrite; | 246 open_flags |= filesystem::kFlagWrite; |
245 if (flags & SQLITE_OPEN_DELETEONCLOSE) | 247 if (flags & SQLITE_OPEN_DELETEONCLOSE) |
246 open_flags |= filesystem::kDeleteOnClose; | 248 open_flags |= filesystem::kDeleteOnClose; |
247 | 249 |
250 mojo::String mojo_name; | |
251 if (name) { | |
252 // Don't let callers open the pattern of our temporary databases. When we | |
253 // open with a null name and SQLITE_OPEN_DELETEONCLOSE, we unlink the | |
254 // database after we open it. If we create a database here, close it | |
255 // normally, and then open the same file through the other path, we could | |
256 // delete the database. | |
257 CHECK(strncmp("Temp_", name, 5) != 0); | |
258 mojo_name = name; | |
259 } else { | |
260 DCHECK(flags & SQLITE_OPEN_DELETEONCLOSE); | |
261 static int temp_number = 0; | |
262 mojo_name = base::StringPrintf("Temp_%d.db", temp_number++); | |
263 } | |
264 | |
248 // Grab the incoming file | 265 // Grab the incoming file |
249 filesystem::FilePtr file_ptr; | 266 filesystem::FilePtr file_ptr; |
250 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 267 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
251 GetRootDirectory(mojo_vfs)->OpenFile(mojo::String(name), GetProxy(&file_ptr), | 268 GetRootDirectory(mojo_vfs)->OpenFile(mojo_name, GetProxy(&file_ptr), |
252 open_flags, Capture(&error)); | 269 open_flags, Capture(&error)); |
253 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); | 270 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); |
254 if (error != filesystem::FILE_ERROR_OK) { | 271 if (error != filesystem::FILE_ERROR_OK) { |
255 // TODO(erg): Translate more of the mojo error codes into sqlite error | 272 // TODO(erg): Translate more of the mojo error codes into sqlite error |
256 // codes. | 273 // codes. |
257 return SQLITE_CANTOPEN; | 274 return SQLITE_CANTOPEN; |
258 } | 275 } |
259 | 276 |
260 // Set the method table so we can be closed (and run the manual dtor call to | 277 // Set the method table so we can be closed (and run the manual dtor call to |
261 // match the following placement news). | 278 // match the following placement news). |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 421 |
405 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); | 422 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); |
406 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); | 423 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); |
407 } | 424 } |
408 | 425 |
409 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { | 426 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { |
410 return root_directory_; | 427 return root_directory_; |
411 } | 428 } |
412 | 429 |
413 } // namespace sql | 430 } // namespace sql |
OLD | NEW |