Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: sql/mojo/mojo_vfs.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/public/type_converters.cc ('k') | sql/mojo/sql_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <utility>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 }; 60 };
61 61
62 filesystem::FilePtr& GetFSFile(sqlite3_file* vfs_file) { 62 filesystem::FilePtr& GetFSFile(sqlite3_file* vfs_file) {
63 return reinterpret_cast<MojoVFSFile*>(vfs_file)->file_ptr; 63 return reinterpret_cast<MojoVFSFile*>(vfs_file)->file_ptr;
64 } 64 }
65 65
66 int MojoVFSClose(sqlite3_file* file) { 66 int MojoVFSClose(sqlite3_file* file) {
67 DVLOG(1) << "MojoVFSClose(*)"; 67 DVLOG(1) << "MojoVFSClose(*)";
68 TRACE_EVENT0("sql", "MojoVFSClose"); 68 TRACE_EVENT0("sql", "MojoVFSClose");
69 using filesystem::FilePtr; 69 using filesystem::FilePtr;
70 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 70 filesystem::FileError error = filesystem::FileError::FAILED;
71 // Must call File::Close explicitly instead of just deleting the file, since 71 // Must call File::Close explicitly instead of just deleting the file, since
72 // otherwise we wouldn't have an object to wait on. 72 // otherwise we wouldn't have an object to wait on.
73 GetFSFile(file)->Close(mojo::Capture(&error)); 73 GetFSFile(file)->Close(mojo::Capture(&error));
74 GetFSFile(file).WaitForIncomingResponse(); 74 GetFSFile(file).WaitForIncomingResponse();
75 GetFSFile(file).~FilePtr(); 75 GetFSFile(file).~FilePtr();
76 return SQLITE_OK; 76 return SQLITE_OK;
77 } 77 }
78 78
79 int MojoVFSRead(sqlite3_file* sql_file, 79 int MojoVFSRead(sqlite3_file* sql_file,
80 void* buffer, 80 void* buffer,
81 int size, 81 int size,
82 sqlite3_int64 offset) { 82 sqlite3_int64 offset) {
83 DVLOG(1) << "MojoVFSRead (" << size << " @ " << offset << ")"; 83 DVLOG(1) << "MojoVFSRead (" << size << " @ " << offset << ")";
84 TRACE_EVENT0("sql", "MojoVFSRead"); 84 TRACE_EVENT0("sql", "MojoVFSRead");
85 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 85 filesystem::FileError error = filesystem::FileError::FAILED;
86 mojo::Array<uint8_t> mojo_data; 86 mojo::Array<uint8_t> mojo_data;
87 GetFSFile(sql_file)->Read(size, offset, filesystem::WHENCE_FROM_BEGIN, 87 GetFSFile(sql_file)->Read(size, offset, filesystem::Whence::FROM_BEGIN,
88 Capture(&error, &mojo_data)); 88 Capture(&error, &mojo_data));
89 GetFSFile(sql_file).WaitForIncomingResponse(); 89 GetFSFile(sql_file).WaitForIncomingResponse();
90 90
91 if (error != filesystem::FILE_ERROR_OK) { 91 if (error != filesystem::FileError::OK) {
92 // TODO(erg): Better implementation here. 92 // TODO(erg): Better implementation here.
93 NOTIMPLEMENTED(); 93 NOTIMPLEMENTED();
94 return SQLITE_IOERR_READ; 94 return SQLITE_IOERR_READ;
95 } 95 }
96 96
97 if (mojo_data.size()) 97 if (mojo_data.size())
98 memcpy(buffer, &mojo_data.front(), mojo_data.size()); 98 memcpy(buffer, &mojo_data.front(), mojo_data.size());
99 if (mojo_data.size() == static_cast<size_t>(size)) 99 if (mojo_data.size() == static_cast<size_t>(size))
100 return SQLITE_OK; 100 return SQLITE_OK;
101 101
102 // We didn't read the entire buffer. Fill the rest of the buffer with zeros. 102 // We didn't read the entire buffer. Fill the rest of the buffer with zeros.
103 memset(reinterpret_cast<char*>(buffer) + mojo_data.size(), 0, 103 memset(reinterpret_cast<char*>(buffer) + mojo_data.size(), 0,
104 size - mojo_data.size()); 104 size - mojo_data.size());
105 105
106 return SQLITE_IOERR_SHORT_READ; 106 return SQLITE_IOERR_SHORT_READ;
107 } 107 }
108 108
109 int MojoVFSWrite(sqlite3_file* sql_file, 109 int MojoVFSWrite(sqlite3_file* sql_file,
110 const void* buffer, 110 const void* buffer,
111 int size, 111 int size,
112 sqlite_int64 offset) { 112 sqlite_int64 offset) {
113 DVLOG(1) << "MojoVFSWrite(*, " << size << ", " << offset << ")"; 113 DVLOG(1) << "MojoVFSWrite(*, " << size << ", " << offset << ")";
114 TRACE_EVENT0("sql", "MojoVFSWrite"); 114 TRACE_EVENT0("sql", "MojoVFSWrite");
115 mojo::Array<uint8_t> mojo_data(size); 115 mojo::Array<uint8_t> mojo_data(size);
116 memcpy(&mojo_data.front(), buffer, size); 116 memcpy(&mojo_data.front(), buffer, size);
117 117
118 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 118 filesystem::FileError error = filesystem::FileError::FAILED;
119 uint32_t num_bytes_written = 0; 119 uint32_t num_bytes_written = 0;
120 GetFSFile(sql_file)->Write(std::move(mojo_data), offset, 120 GetFSFile(sql_file)->Write(std::move(mojo_data), offset,
121 filesystem::WHENCE_FROM_BEGIN, 121 filesystem::Whence::FROM_BEGIN,
122 Capture(&error, &num_bytes_written)); 122 Capture(&error, &num_bytes_written));
123 GetFSFile(sql_file).WaitForIncomingResponse(); 123 GetFSFile(sql_file).WaitForIncomingResponse();
124 if (error != filesystem::FILE_ERROR_OK) { 124 if (error != filesystem::FileError::OK) {
125 // TODO(erg): Better implementation here. 125 // TODO(erg): Better implementation here.
126 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
127 return SQLITE_IOERR_WRITE; 127 return SQLITE_IOERR_WRITE;
128 } 128 }
129 if (num_bytes_written != static_cast<uint32_t>(size)) { 129 if (num_bytes_written != static_cast<uint32_t>(size)) {
130 NOTIMPLEMENTED(); 130 NOTIMPLEMENTED();
131 return SQLITE_IOERR_WRITE; 131 return SQLITE_IOERR_WRITE;
132 } 132 }
133 133
134 return SQLITE_OK; 134 return SQLITE_OK;
135 } 135 }
136 136
137 int MojoVFSTruncate(sqlite3_file* sql_file, sqlite_int64 size) { 137 int MojoVFSTruncate(sqlite3_file* sql_file, sqlite_int64 size) {
138 DVLOG(1) << "MojoVFSTruncate(*, " << size << ")"; 138 DVLOG(1) << "MojoVFSTruncate(*, " << size << ")";
139 TRACE_EVENT0("sql", "MojoVFSTruncate"); 139 TRACE_EVENT0("sql", "MojoVFSTruncate");
140 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 140 filesystem::FileError error = filesystem::FileError::FAILED;
141 GetFSFile(sql_file)->Truncate(size, Capture(&error)); 141 GetFSFile(sql_file)->Truncate(size, Capture(&error));
142 GetFSFile(sql_file).WaitForIncomingResponse(); 142 GetFSFile(sql_file).WaitForIncomingResponse();
143 if (error != filesystem::FILE_ERROR_OK) { 143 if (error != filesystem::FileError::OK) {
144 // TODO(erg): Better implementation here. 144 // TODO(erg): Better implementation here.
145 NOTIMPLEMENTED(); 145 NOTIMPLEMENTED();
146 return SQLITE_IOERR_TRUNCATE; 146 return SQLITE_IOERR_TRUNCATE;
147 } 147 }
148 148
149 return SQLITE_OK; 149 return SQLITE_OK;
150 } 150 }
151 151
152 int MojoVFSSync(sqlite3_file* sql_file, int flags) { 152 int MojoVFSSync(sqlite3_file* sql_file, int flags) {
153 DVLOG(1) << "MojoVFSSync(*, " << flags << ")"; 153 DVLOG(1) << "MojoVFSSync(*, " << flags << ")";
154 TRACE_EVENT0("sql", "MojoVFSSync"); 154 TRACE_EVENT0("sql", "MojoVFSSync");
155 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 155 filesystem::FileError error = filesystem::FileError::FAILED;
156 GetFSFile(sql_file)->Flush(Capture(&error)); 156 GetFSFile(sql_file)->Flush(Capture(&error));
157 GetFSFile(sql_file).WaitForIncomingResponse(); 157 GetFSFile(sql_file).WaitForIncomingResponse();
158 if (error != filesystem::FILE_ERROR_OK) { 158 if (error != filesystem::FileError::OK) {
159 // TODO(erg): Better implementation here. 159 // TODO(erg): Better implementation here.
160 NOTIMPLEMENTED(); 160 NOTIMPLEMENTED();
161 return SQLITE_IOERR_FSYNC; 161 return SQLITE_IOERR_FSYNC;
162 } 162 }
163 163
164 return SQLITE_OK; 164 return SQLITE_OK;
165 } 165 }
166 166
167 int MojoVFSFileSize(sqlite3_file* sql_file, sqlite_int64* size) { 167 int MojoVFSFileSize(sqlite3_file* sql_file, sqlite_int64* size) {
168 DVLOG(1) << "MojoVFSFileSize(*)"; 168 DVLOG(1) << "MojoVFSFileSize(*)";
169 TRACE_EVENT0("sql", "MojoVFSFileSize"); 169 TRACE_EVENT0("sql", "MojoVFSFileSize");
170 170
171 filesystem::FileError err = filesystem::FILE_ERROR_FAILED; 171 filesystem::FileError err = filesystem::FileError::FAILED;
172 filesystem::FileInformationPtr file_info; 172 filesystem::FileInformationPtr file_info;
173 GetFSFile(sql_file)->Stat(Capture(&err, &file_info)); 173 GetFSFile(sql_file)->Stat(Capture(&err, &file_info));
174 GetFSFile(sql_file).WaitForIncomingResponse(); 174 GetFSFile(sql_file).WaitForIncomingResponse();
175 175
176 if (err != filesystem::FILE_ERROR_OK) { 176 if (err != filesystem::FileError::OK) {
177 // TODO(erg): Better implementation here. 177 // TODO(erg): Better implementation here.
178 NOTIMPLEMENTED(); 178 NOTIMPLEMENTED();
179 return SQLITE_IOERR_FSTAT; 179 return SQLITE_IOERR_FSTAT;
180 } 180 }
181 181
182 *size = file_info->size; 182 *size = file_info->size;
183 return SQLITE_OK; 183 return SQLITE_OK;
184 } 184 }
185 185
186 // TODO(erg): The current base::File interface isn't sufficient to handle 186 // TODO(erg): The current base::File interface isn't sufficient to handle
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 CHECK(strncmp("Temp_", name, 5) != 0); 276 CHECK(strncmp("Temp_", name, 5) != 0);
277 mojo_name = name; 277 mojo_name = name;
278 } else { 278 } else {
279 DCHECK(flags & SQLITE_OPEN_DELETEONCLOSE); 279 DCHECK(flags & SQLITE_OPEN_DELETEONCLOSE);
280 static int temp_number = 0; 280 static int temp_number = 0;
281 mojo_name = base::StringPrintf("Temp_%d.db", temp_number++); 281 mojo_name = base::StringPrintf("Temp_%d.db", temp_number++);
282 } 282 }
283 283
284 // Grab the incoming file 284 // Grab the incoming file
285 filesystem::FilePtr file_ptr; 285 filesystem::FilePtr file_ptr;
286 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 286 filesystem::FileError error = filesystem::FileError::FAILED;
287 GetRootDirectory(mojo_vfs)->OpenFile(mojo_name, GetProxy(&file_ptr), 287 GetRootDirectory(mojo_vfs)->OpenFile(mojo_name, GetProxy(&file_ptr),
288 open_flags, Capture(&error)); 288 open_flags, Capture(&error));
289 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); 289 GetRootDirectory(mojo_vfs).WaitForIncomingResponse();
290 if (error != filesystem::FILE_ERROR_OK) { 290 if (error != filesystem::FileError::OK) {
291 // TODO(erg): Translate more of the mojo error codes into sqlite error 291 // TODO(erg): Translate more of the mojo error codes into sqlite error
292 // codes. 292 // codes.
293 return SQLITE_CANTOPEN; 293 return SQLITE_CANTOPEN;
294 } 294 }
295 295
296 // 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
297 // match the following placement news). 297 // match the following placement news).
298 file->pMethods = &mojo_vfs_io_methods; 298 file->pMethods = &mojo_vfs_io_methods;
299 299
300 // |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
301 // 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
302 // the pipe to our file. 302 // the pipe to our file.
303 new (&GetFSFile(file)) filesystem::FilePtr(std::move(file_ptr)); 303 new (&GetFSFile(file)) filesystem::FilePtr(std::move(file_ptr));
304 304
305 return SQLITE_OK; 305 return SQLITE_OK;
306 } 306 }
307 307
308 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) {
309 DVLOG(1) << "MojoVFSDelete(*, " << filename << ", " << sync_dir << ")"; 309 DVLOG(1) << "MojoVFSDelete(*, " << filename << ", " << sync_dir << ")";
310 TRACE_EVENT2("sql", "MojoVFSDelete", 310 TRACE_EVENT2("sql", "MojoVFSDelete",
311 "name", filename, 311 "name", filename,
312 "sync_dir", sync_dir); 312 "sync_dir", sync_dir);
313 // 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
314 // antivirus software keeping files open. We'll probably have to do something 314 // antivirus software keeping files open. We'll probably have to do something
315 // like that in the far future if we ever support Windows. 315 // like that in the far future if we ever support Windows.
316 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 316 filesystem::FileError error = filesystem::FileError::FAILED;
317 GetRootDirectory(mojo_vfs)->Delete(filename, 0, Capture(&error)); 317 GetRootDirectory(mojo_vfs)->Delete(filename, 0, Capture(&error));
318 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); 318 GetRootDirectory(mojo_vfs).WaitForIncomingResponse();
319 319
320 if (error == filesystem::FILE_ERROR_OK && sync_dir) { 320 if (error == filesystem::FileError::OK && sync_dir) {
321 GetRootDirectory(mojo_vfs)->Flush(Capture(&error)); 321 GetRootDirectory(mojo_vfs)->Flush(Capture(&error));
322 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); 322 GetRootDirectory(mojo_vfs).WaitForIncomingResponse();
323 } 323 }
324 324
325 return error == filesystem::FILE_ERROR_OK ? SQLITE_OK : SQLITE_IOERR_DELETE; 325 return error == filesystem::FileError::OK ? SQLITE_OK : SQLITE_IOERR_DELETE;
326 } 326 }
327 327
328 int MojoVFSAccess(sqlite3_vfs* mojo_vfs, 328 int MojoVFSAccess(sqlite3_vfs* mojo_vfs,
329 const char* filename, 329 const char* filename,
330 int flags, 330 int flags,
331 int* result) { 331 int* result) {
332 DVLOG(1) << "MojoVFSAccess(*, " << filename << ", " << flags << ", *)"; 332 DVLOG(1) << "MojoVFSAccess(*, " << filename << ", " << flags << ", *)";
333 TRACE_EVENT2("sql", "MojoVFSAccess", 333 TRACE_EVENT2("sql", "MojoVFSAccess",
334 "name", filename, 334 "name", filename,
335 "flags", flags); 335 "flags", flags);
336 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 336 filesystem::FileError error = filesystem::FileError::FAILED;
337 337
338 if (flags == SQLITE_ACCESS_READWRITE || flags == SQLITE_ACCESS_READ) { 338 if (flags == SQLITE_ACCESS_READWRITE || flags == SQLITE_ACCESS_READ) {
339 bool is_writable = false; 339 bool is_writable = false;
340 GetRootDirectory(mojo_vfs) 340 GetRootDirectory(mojo_vfs)
341 ->IsWritable(filename, Capture(&error, &is_writable)); 341 ->IsWritable(filename, Capture(&error, &is_writable));
342 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); 342 GetRootDirectory(mojo_vfs).WaitForIncomingResponse();
343 *result = is_writable; 343 *result = is_writable;
344 return SQLITE_OK; 344 return SQLITE_OK;
345 } 345 }
346 346
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); 447 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK);
448 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); 448 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK);
449 } 449 }
450 450
451 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { 451 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() {
452 return root_directory_; 452 return root_directory_;
453 } 453 }
454 454
455 } // namespace sql 455 } // namespace sql
OLDNEW
« no previous file with comments | « skia/public/type_converters.cc ('k') | sql/mojo/sql_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698