| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "components/filesystem/public/interfaces/file.mojom.h" | 15 #include "components/filesystem/public/interfaces/file.mojom.h" |
| 15 #include "components/filesystem/public/interfaces/file_system.mojom.h" | 16 #include "components/filesystem/public/interfaces/file_system.mojom.h" |
| 16 #include "components/filesystem/public/interfaces/types.mojom.h" | 17 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/lib/template_util.h" | 18 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 18 #include "mojo/util/capture_util.h" | 19 #include "mojo/util/capture_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const void* buffer, | 110 const void* buffer, |
| 110 int size, | 111 int size, |
| 111 sqlite_int64 offset) { | 112 sqlite_int64 offset) { |
| 112 DVLOG(1) << "MojoVFSWrite(*, " << size << ", " << offset << ")"; | 113 DVLOG(1) << "MojoVFSWrite(*, " << size << ", " << offset << ")"; |
| 113 TRACE_EVENT0("sql", "MojoVFSWrite"); | 114 TRACE_EVENT0("sql", "MojoVFSWrite"); |
| 114 mojo::Array<uint8_t> mojo_data(size); | 115 mojo::Array<uint8_t> mojo_data(size); |
| 115 memcpy(&mojo_data.front(), buffer, size); | 116 memcpy(&mojo_data.front(), buffer, size); |
| 116 | 117 |
| 117 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 118 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
| 118 uint32_t num_bytes_written = 0; | 119 uint32_t num_bytes_written = 0; |
| 119 GetFSFile(sql_file)->Write(mojo_data.Pass(), offset, | 120 GetFSFile(sql_file)->Write(std::move(mojo_data), offset, |
| 120 filesystem::WHENCE_FROM_BEGIN, | 121 filesystem::WHENCE_FROM_BEGIN, |
| 121 Capture(&error, &num_bytes_written)); | 122 Capture(&error, &num_bytes_written)); |
| 122 GetFSFile(sql_file).WaitForIncomingResponse(); | 123 GetFSFile(sql_file).WaitForIncomingResponse(); |
| 123 if (error != filesystem::FILE_ERROR_OK) { | 124 if (error != filesystem::FILE_ERROR_OK) { |
| 124 // TODO(erg): Better implementation here. | 125 // TODO(erg): Better implementation here. |
| 125 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
| 126 return SQLITE_IOERR_WRITE; | 127 return SQLITE_IOERR_WRITE; |
| 127 } | 128 } |
| 128 if (num_bytes_written != static_cast<uint32_t>(size)) { | 129 if (num_bytes_written != static_cast<uint32_t>(size)) { |
| 129 NOTIMPLEMENTED(); | 130 NOTIMPLEMENTED(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return SQLITE_CANTOPEN; | 293 return SQLITE_CANTOPEN; |
| 293 } | 294 } |
| 294 | 295 |
| 295 // Set the method table so we can be closed (and run the manual dtor call to | 296 // Set the method table so we can be closed (and run the manual dtor call to |
| 296 // match the following placement news). | 297 // match the following placement news). |
| 297 file->pMethods = &mojo_vfs_io_methods; | 298 file->pMethods = &mojo_vfs_io_methods; |
| 298 | 299 |
| 299 // |file| is actually a malloced buffer of size szOsFile. This means that we | 300 // |file| is actually a malloced buffer of size szOsFile. This means that we |
| 300 // need to manually use placement new to construct the C++ object which owns | 301 // need to manually use placement new to construct the C++ object which owns |
| 301 // the pipe to our file. | 302 // the pipe to our file. |
| 302 new (&GetFSFile(file)) filesystem::FilePtr(file_ptr.Pass()); | 303 new (&GetFSFile(file)) filesystem::FilePtr(std::move(file_ptr)); |
| 303 | 304 |
| 304 return SQLITE_OK; | 305 return SQLITE_OK; |
| 305 } | 306 } |
| 306 | 307 |
| 307 int MojoVFSDelete(sqlite3_vfs* mojo_vfs, const char* filename, int sync_dir) { | 308 int MojoVFSDelete(sqlite3_vfs* mojo_vfs, const char* filename, int sync_dir) { |
| 308 DVLOG(1) << "MojoVFSDelete(*, " << filename << ", " << sync_dir << ")"; | 309 DVLOG(1) << "MojoVFSDelete(*, " << filename << ", " << sync_dir << ")"; |
| 309 TRACE_EVENT2("sql", "MojoVFSDelete", | 310 TRACE_EVENT2("sql", "MojoVFSDelete", |
| 310 "name", filename, | 311 "name", filename, |
| 311 "sync_dir", sync_dir); | 312 "sync_dir", sync_dir); |
| 312 // TODO(erg): The default windows sqlite VFS has retry code to work around | 313 // TODO(erg): The default windows sqlite VFS has retry code to work around |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 MojoVFSCurrentTime, /* xCurrentTime */ | 425 MojoVFSCurrentTime, /* xCurrentTime */ |
| 425 MojoVFSGetLastError, /* xGetLastError */ | 426 MojoVFSGetLastError, /* xGetLastError */ |
| 426 MojoVFSCurrentTimeInt64 /* xCurrentTimeInt64 */ | 427 MojoVFSCurrentTimeInt64 /* xCurrentTimeInt64 */ |
| 427 }; | 428 }; |
| 428 | 429 |
| 429 } // namespace | 430 } // namespace |
| 430 | 431 |
| 431 ScopedMojoFilesystemVFS::ScopedMojoFilesystemVFS( | 432 ScopedMojoFilesystemVFS::ScopedMojoFilesystemVFS( |
| 432 filesystem::DirectoryPtr root_directory) | 433 filesystem::DirectoryPtr root_directory) |
| 433 : parent_(sqlite3_vfs_find(NULL)), | 434 : parent_(sqlite3_vfs_find(NULL)), |
| 434 root_directory_(root_directory.Pass()) { | 435 root_directory_(std::move(root_directory)) { |
| 435 CHECK(!mojo_vfs.pAppData); | 436 CHECK(!mojo_vfs.pAppData); |
| 436 mojo_vfs.pAppData = this; | 437 mojo_vfs.pAppData = this; |
| 437 mojo_vfs.mxPathname = parent_->mxPathname; | 438 mojo_vfs.mxPathname = parent_->mxPathname; |
| 438 | 439 |
| 439 CHECK(sqlite3_vfs_register(&mojo_vfs, 1) == SQLITE_OK); | 440 CHECK(sqlite3_vfs_register(&mojo_vfs, 1) == SQLITE_OK); |
| 440 } | 441 } |
| 441 | 442 |
| 442 ScopedMojoFilesystemVFS::~ScopedMojoFilesystemVFS() { | 443 ScopedMojoFilesystemVFS::~ScopedMojoFilesystemVFS() { |
| 443 CHECK(mojo_vfs.pAppData); | 444 CHECK(mojo_vfs.pAppData); |
| 444 mojo_vfs.pAppData = nullptr; | 445 mojo_vfs.pAppData = nullptr; |
| 445 | 446 |
| 446 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); | 447 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); |
| 447 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); | 448 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); |
| 448 } | 449 } |
| 449 | 450 |
| 450 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { | 451 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { |
| 451 return root_directory_; | 452 return root_directory_; |
| 452 } | 453 } |
| 453 | 454 |
| 454 } // namespace sql | 455 } // namespace sql |
| OLD | NEW |