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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 open_flags = filesystem::kFlagOpenAlways; | 239 open_flags = filesystem::kFlagOpenAlways; |
239 } else { | 240 } else { |
240 open_flags = filesystem::kFlagOpen; | 241 open_flags = filesystem::kFlagOpen; |
241 } | 242 } |
242 open_flags |= filesystem::kFlagRead; | 243 open_flags |= filesystem::kFlagRead; |
243 if (flags & SQLITE_OPEN_READWRITE) | 244 if (flags & SQLITE_OPEN_READWRITE) |
244 open_flags |= filesystem::kFlagWrite; | 245 open_flags |= filesystem::kFlagWrite; |
245 if (flags & SQLITE_OPEN_DELETEONCLOSE) | 246 if (flags & SQLITE_OPEN_DELETEONCLOSE) |
246 open_flags |= filesystem::kDeleteOnClose; | 247 open_flags |= filesystem::kDeleteOnClose; |
247 | 248 |
249 mojo::String mojo_name; | |
250 if (name) { | |
251 mojo_name = name; | |
252 } else { | |
253 DCHECK(flags & SQLITE_OPEN_DELETEONCLOSE); | |
254 static int temp_number = 0; | |
255 mojo_name = base::StringPrintf("Temp_%d.db", temp_number++); | |
Scott Hess - ex-Googler
2015/07/06 20:47:59
AFAICT this is in the same namespace as other data
| |
256 } | |
257 | |
248 // Grab the incoming file | 258 // Grab the incoming file |
249 filesystem::FilePtr file_ptr; | 259 filesystem::FilePtr file_ptr; |
250 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 260 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
251 GetRootDirectory(mojo_vfs)->OpenFile(mojo::String(name), GetProxy(&file_ptr), | 261 GetRootDirectory(mojo_vfs)->OpenFile(mojo_name, GetProxy(&file_ptr), |
252 open_flags, Capture(&error)); | 262 open_flags, Capture(&error)); |
253 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); | 263 GetRootDirectory(mojo_vfs).WaitForIncomingResponse(); |
254 if (error != filesystem::FILE_ERROR_OK) { | 264 if (error != filesystem::FILE_ERROR_OK) { |
255 // TODO(erg): Translate more of the mojo error codes into sqlite error | 265 // TODO(erg): Translate more of the mojo error codes into sqlite error |
256 // codes. | 266 // codes. |
257 return SQLITE_CANTOPEN; | 267 return SQLITE_CANTOPEN; |
258 } | 268 } |
259 | 269 |
260 // Set the method table so we can be closed (and run the manual dtor call to | 270 // Set the method table so we can be closed (and run the manual dtor call to |
261 // match the following placement news). | 271 // match the following placement news). |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 414 |
405 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); | 415 CHECK(sqlite3_vfs_register(parent_, 1) == SQLITE_OK); |
406 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); | 416 CHECK(sqlite3_vfs_unregister(&mojo_vfs) == SQLITE_OK); |
407 } | 417 } |
408 | 418 |
409 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { | 419 filesystem::DirectoryPtr& ScopedMojoFilesystemVFS::GetDirectory() { |
410 return root_directory_; | 420 return root_directory_; |
411 } | 421 } |
412 | 422 |
413 } // namespace sql | 423 } // namespace sql |
OLD | NEW |