| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/leveldb/leveldb_mojo_proxy.h" | 5 #include "components/leveldb/leveldb_mojo_proxy.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "mojo/platform_handle/platform_handle_functions.h" | 11 #include "mojo/platform_handle/platform_handle_functions.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 | 13 |
| 14 namespace leveldb { | 14 namespace leveldb { |
| 15 | 15 |
| 16 struct LevelDBMojoProxy::OpaqueLock { | 16 struct LevelDBMojoProxy::OpaqueLock { |
| 17 filesystem::FilePtr lock_file; | 17 filesystem::mojom::FilePtr lock_file; |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 struct LevelDBMojoProxy::OpaqueDir { | 20 struct LevelDBMojoProxy::OpaqueDir { |
| 21 explicit OpaqueDir( | 21 explicit OpaqueDir( |
| 22 mojo::InterfacePtrInfo<filesystem::Directory> directory_info) { | 22 mojo::InterfacePtrInfo<filesystem::mojom::Directory> directory_info) { |
| 23 directory.Bind(std::move(directory_info)); | 23 directory.Bind(std::move(directory_info)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 filesystem::DirectoryPtr directory; | 26 filesystem::mojom::DirectoryPtr directory; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 LevelDBMojoProxy::LevelDBMojoProxy( | 29 LevelDBMojoProxy::LevelDBMojoProxy( |
| 30 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 30 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 31 : task_runner_(std::move(task_runner)), outstanding_opaque_dirs_(0) {} | 31 : task_runner_(std::move(task_runner)), outstanding_opaque_dirs_(0) {} |
| 32 | 32 |
| 33 LevelDBMojoProxy::OpaqueDir* LevelDBMojoProxy::RegisterDirectory( | 33 LevelDBMojoProxy::OpaqueDir* LevelDBMojoProxy::RegisterDirectory( |
| 34 filesystem::DirectoryPtr directory) { | 34 filesystem::mojom::DirectoryPtr directory) { |
| 35 OpaqueDir* out_dir = nullptr; | 35 OpaqueDir* out_dir = nullptr; |
| 36 RunInternal(base::Bind(&LevelDBMojoProxy::RegisterDirectoryImpl, this, | 36 RunInternal(base::Bind(&LevelDBMojoProxy::RegisterDirectoryImpl, this, |
| 37 base::Passed(directory.PassInterface()), | 37 base::Passed(directory.PassInterface()), |
| 38 &out_dir)); | 38 &out_dir)); |
| 39 | 39 |
| 40 return out_dir; | 40 return out_dir; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void LevelDBMojoProxy::UnregisterDirectory(OpaqueDir* dir) { | 43 void LevelDBMojoProxy::UnregisterDirectory(OpaqueDir* dir) { |
| 44 RunInternal(base::Bind(&LevelDBMojoProxy::UnregisterDirectoryImpl, | 44 RunInternal(base::Bind(&LevelDBMojoProxy::UnregisterDirectoryImpl, |
| 45 this, dir)); | 45 this, dir)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 base::File LevelDBMojoProxy::OpenFileHandle(OpaqueDir* dir, | 48 base::File LevelDBMojoProxy::OpenFileHandle(OpaqueDir* dir, |
| 49 const std::string& name, | 49 const std::string& name, |
| 50 uint32_t open_flags) { | 50 uint32_t open_flags) { |
| 51 base::File file; | 51 base::File file; |
| 52 RunInternal(base::Bind(&LevelDBMojoProxy::OpenFileHandleImpl, this, dir, | 52 RunInternal(base::Bind(&LevelDBMojoProxy::OpenFileHandleImpl, this, dir, |
| 53 name, open_flags, &file)); | 53 name, open_flags, &file)); |
| 54 return file; | 54 return file; |
| 55 } | 55 } |
| 56 | 56 |
| 57 filesystem::FileError LevelDBMojoProxy::SyncDirectory(OpaqueDir* dir, | 57 filesystem::mojom::FileError LevelDBMojoProxy::SyncDirectory( |
| 58 const std::string& name) { | 58 OpaqueDir* dir, |
| 59 filesystem::FileError error = filesystem::FileError::FAILED; | 59 const std::string& name) { |
| 60 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 60 RunInternal(base::Bind(&LevelDBMojoProxy::SyncDirectoryImpl, this, dir, | 61 RunInternal(base::Bind(&LevelDBMojoProxy::SyncDirectoryImpl, this, dir, |
| 61 name, &error)); | 62 name, &error)); |
| 62 return error; | 63 return error; |
| 63 } | 64 } |
| 64 | 65 |
| 65 bool LevelDBMojoProxy::FileExists(OpaqueDir* dir, const std::string& name) { | 66 bool LevelDBMojoProxy::FileExists(OpaqueDir* dir, const std::string& name) { |
| 66 bool exists = false; | 67 bool exists = false; |
| 67 RunInternal(base::Bind(&LevelDBMojoProxy::FileExistsImpl, this, dir, | 68 RunInternal(base::Bind(&LevelDBMojoProxy::FileExistsImpl, this, dir, |
| 68 name, &exists)); | 69 name, &exists)); |
| 69 return exists; | 70 return exists; |
| 70 } | 71 } |
| 71 | 72 |
| 72 filesystem::FileError LevelDBMojoProxy::GetChildren( | 73 filesystem::mojom::FileError LevelDBMojoProxy::GetChildren( |
| 73 OpaqueDir* dir, | 74 OpaqueDir* dir, |
| 74 const std::string& path, | 75 const std::string& path, |
| 75 std::vector<std::string>* result) { | 76 std::vector<std::string>* result) { |
| 76 filesystem::FileError error = filesystem::FileError::FAILED; | 77 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 77 RunInternal(base::Bind(&LevelDBMojoProxy::GetChildrenImpl, this, dir, | 78 RunInternal(base::Bind(&LevelDBMojoProxy::GetChildrenImpl, this, dir, |
| 78 path, result, &error)); | 79 path, result, &error)); |
| 79 return error; | 80 return error; |
| 80 } | 81 } |
| 81 | 82 |
| 82 filesystem::FileError LevelDBMojoProxy::Delete(OpaqueDir* dir, | 83 filesystem::mojom::FileError LevelDBMojoProxy::Delete(OpaqueDir* dir, |
| 83 const std::string& path, | 84 const std::string& path, |
| 84 uint32_t delete_flags) { | 85 uint32_t delete_flags) { |
| 85 filesystem::FileError error = filesystem::FileError::FAILED; | 86 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 86 RunInternal(base::Bind(&LevelDBMojoProxy::DeleteImpl, this, dir, path, | 87 RunInternal(base::Bind(&LevelDBMojoProxy::DeleteImpl, this, dir, path, |
| 87 delete_flags, &error)); | 88 delete_flags, &error)); |
| 88 return error; | 89 return error; |
| 89 } | 90 } |
| 90 | 91 |
| 91 filesystem::FileError LevelDBMojoProxy::CreateDir(OpaqueDir* dir, | 92 filesystem::mojom::FileError LevelDBMojoProxy::CreateDir( |
| 92 const std::string& path) { | 93 OpaqueDir* dir, |
| 93 filesystem::FileError error = filesystem::FileError::FAILED; | 94 const std::string& path) { |
| 95 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 94 RunInternal(base::Bind(&LevelDBMojoProxy::CreateDirImpl, this, dir, path, | 96 RunInternal(base::Bind(&LevelDBMojoProxy::CreateDirImpl, this, dir, path, |
| 95 &error)); | 97 &error)); |
| 96 return error; | 98 return error; |
| 97 } | 99 } |
| 98 | 100 |
| 99 filesystem::FileError LevelDBMojoProxy::GetFileSize(OpaqueDir* dir, | 101 filesystem::mojom::FileError LevelDBMojoProxy::GetFileSize( |
| 100 const std::string& path, | 102 OpaqueDir* dir, |
| 101 uint64_t* file_size) { | 103 const std::string& path, |
| 102 filesystem::FileError error = filesystem::FileError::FAILED; | 104 uint64_t* file_size) { |
| 105 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 103 RunInternal(base::Bind(&LevelDBMojoProxy::GetFileSizeImpl, this, dir, | 106 RunInternal(base::Bind(&LevelDBMojoProxy::GetFileSizeImpl, this, dir, |
| 104 path, file_size, &error)); | 107 path, file_size, &error)); |
| 105 return error; | 108 return error; |
| 106 } | 109 } |
| 107 | 110 |
| 108 filesystem::FileError LevelDBMojoProxy::RenameFile( | 111 filesystem::mojom::FileError LevelDBMojoProxy::RenameFile( |
| 109 OpaqueDir* dir, | 112 OpaqueDir* dir, |
| 110 const std::string& old_path, | 113 const std::string& old_path, |
| 111 const std::string& new_path) { | 114 const std::string& new_path) { |
| 112 filesystem::FileError error = filesystem::FileError::FAILED; | 115 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 113 RunInternal(base::Bind(&LevelDBMojoProxy::RenameFileImpl, this, dir, | 116 RunInternal(base::Bind(&LevelDBMojoProxy::RenameFileImpl, this, dir, |
| 114 old_path, new_path, &error)); | 117 old_path, new_path, &error)); |
| 115 return error; | 118 return error; |
| 116 } | 119 } |
| 117 | 120 |
| 118 std::pair<filesystem::FileError, LevelDBMojoProxy::OpaqueLock*> | 121 std::pair<filesystem::mojom::FileError, LevelDBMojoProxy::OpaqueLock*> |
| 119 LevelDBMojoProxy::LockFile(OpaqueDir* dir, const std::string& path) { | 122 LevelDBMojoProxy::LockFile(OpaqueDir* dir, const std::string& path) { |
| 120 filesystem::FileError error = filesystem::FileError::FAILED; | 123 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 121 OpaqueLock* out_lock = nullptr; | 124 OpaqueLock* out_lock = nullptr; |
| 122 RunInternal(base::Bind(&LevelDBMojoProxy::LockFileImpl, this, dir, path, | 125 RunInternal(base::Bind(&LevelDBMojoProxy::LockFileImpl, this, dir, path, |
| 123 &error, &out_lock)); | 126 &error, &out_lock)); |
| 124 return std::make_pair(error, out_lock); | 127 return std::make_pair(error, out_lock); |
| 125 } | 128 } |
| 126 | 129 |
| 127 filesystem::FileError LevelDBMojoProxy::UnlockFile(OpaqueLock* lock) { | 130 filesystem::mojom::FileError LevelDBMojoProxy::UnlockFile(OpaqueLock* lock) { |
| 128 // Take ownership of the incoming lock so it gets destroyed whatever happens. | 131 // Take ownership of the incoming lock so it gets destroyed whatever happens. |
| 129 std::unique_ptr<OpaqueLock> scoped_lock(lock); | 132 std::unique_ptr<OpaqueLock> scoped_lock(lock); |
| 130 filesystem::FileError error = filesystem::FileError::FAILED; | 133 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 131 RunInternal(base::Bind(&LevelDBMojoProxy::UnlockFileImpl, this, | 134 RunInternal(base::Bind(&LevelDBMojoProxy::UnlockFileImpl, this, |
| 132 base::Passed(&scoped_lock), &error)); | 135 base::Passed(&scoped_lock), &error)); |
| 133 return error; | 136 return error; |
| 134 } | 137 } |
| 135 | 138 |
| 136 LevelDBMojoProxy::~LevelDBMojoProxy() { | 139 LevelDBMojoProxy::~LevelDBMojoProxy() { |
| 137 DCHECK_EQ(0, outstanding_opaque_dirs_); | 140 DCHECK_EQ(0, outstanding_opaque_dirs_); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void LevelDBMojoProxy::RunInternal(const base::Closure& task) { | 143 void LevelDBMojoProxy::RunInternal(const base::Closure& task) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 152 } | 155 } |
| 153 } | 156 } |
| 154 | 157 |
| 155 void LevelDBMojoProxy::DoOnOtherThread(const base::Closure& c, | 158 void LevelDBMojoProxy::DoOnOtherThread(const base::Closure& c, |
| 156 base::WaitableEvent* event) { | 159 base::WaitableEvent* event) { |
| 157 c.Run(); | 160 c.Run(); |
| 158 event->Signal(); | 161 event->Signal(); |
| 159 } | 162 } |
| 160 | 163 |
| 161 void LevelDBMojoProxy::RegisterDirectoryImpl( | 164 void LevelDBMojoProxy::RegisterDirectoryImpl( |
| 162 mojo::InterfacePtrInfo<filesystem::Directory> directory_info, | 165 mojo::InterfacePtrInfo<filesystem::mojom::Directory> directory_info, |
| 163 OpaqueDir** out_dir) { | 166 OpaqueDir** out_dir) { |
| 164 // Take the Directory pipe and bind it on this thread. | 167 // Take the Directory pipe and bind it on this thread. |
| 165 *out_dir = new OpaqueDir(std::move(directory_info)); | 168 *out_dir = new OpaqueDir(std::move(directory_info)); |
| 166 outstanding_opaque_dirs_++; | 169 outstanding_opaque_dirs_++; |
| 167 } | 170 } |
| 168 | 171 |
| 169 void LevelDBMojoProxy::UnregisterDirectoryImpl( | 172 void LevelDBMojoProxy::UnregisterDirectoryImpl( |
| 170 OpaqueDir* dir) { | 173 OpaqueDir* dir) { |
| 171 // Only delete the directories on the thread that owns them. | 174 // Only delete the directories on the thread that owns them. |
| 172 delete dir; | 175 delete dir; |
| 173 outstanding_opaque_dirs_--; | 176 outstanding_opaque_dirs_--; |
| 174 } | 177 } |
| 175 | 178 |
| 176 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir, | 179 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir, |
| 177 std::string name, | 180 std::string name, |
| 178 uint32_t open_flags, | 181 uint32_t open_flags, |
| 179 base::File* output_file) { | 182 base::File* output_file) { |
| 180 mojo::ScopedHandle handle; | 183 mojo::ScopedHandle handle; |
| 181 filesystem::FileError error = filesystem::FileError::FAILED; | 184 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 182 bool completed = dir->directory->OpenFileHandle(mojo::String::From(name), | 185 bool completed = dir->directory->OpenFileHandle(mojo::String::From(name), |
| 183 open_flags, &error, &handle); | 186 open_flags, &error, &handle); |
| 184 DCHECK(completed); | 187 DCHECK(completed); |
| 185 | 188 |
| 186 if (error != filesystem::FileError::OK) { | 189 if (error != filesystem::mojom::FileError::OK) { |
| 187 *output_file = base::File(static_cast<base::File::Error>(error)); | 190 *output_file = base::File(static_cast<base::File::Error>(error)); |
| 188 } else { | 191 } else { |
| 189 MojoPlatformHandle platform_handle; | 192 MojoPlatformHandle platform_handle; |
| 190 MojoResult extract_result = | 193 MojoResult extract_result = |
| 191 MojoExtractPlatformHandle(handle.release().value(), &platform_handle); | 194 MojoExtractPlatformHandle(handle.release().value(), &platform_handle); |
| 192 | 195 |
| 193 if (extract_result == MOJO_RESULT_OK) { | 196 if (extract_result == MOJO_RESULT_OK) { |
| 194 *output_file = base::File(platform_handle); | 197 *output_file = base::File(platform_handle); |
| 195 } else { | 198 } else { |
| 196 NOTREACHED(); | 199 NOTREACHED(); |
| 197 *output_file = base::File(base::File::Error::FILE_ERROR_FAILED); | 200 *output_file = base::File(base::File::Error::FILE_ERROR_FAILED); |
| 198 } | 201 } |
| 199 } | 202 } |
| 200 } | 203 } |
| 201 | 204 |
| 202 void LevelDBMojoProxy::SyncDirectoryImpl(OpaqueDir* dir, | 205 void LevelDBMojoProxy::SyncDirectoryImpl( |
| 203 std::string name, | 206 OpaqueDir* dir, |
| 204 filesystem::FileError* out_error) { | 207 std::string name, |
| 205 filesystem::DirectoryPtr target; | 208 filesystem::mojom::FileError* out_error) { |
| 209 filesystem::mojom::DirectoryPtr target; |
| 206 bool completed = dir->directory->OpenDirectory( | 210 bool completed = dir->directory->OpenDirectory( |
| 207 name, GetProxy(&target), filesystem::kFlagRead | filesystem::kFlagWrite, | 211 name, GetProxy(&target), |
| 208 out_error); | 212 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error); |
| 209 DCHECK(completed); | 213 DCHECK(completed); |
| 210 | 214 |
| 211 if (*out_error != filesystem::FileError::OK) | 215 if (*out_error != filesystem::mojom::FileError::OK) |
| 212 return; | 216 return; |
| 213 | 217 |
| 214 completed = target->Flush(out_error); | 218 completed = target->Flush(out_error); |
| 215 DCHECK(completed); | 219 DCHECK(completed); |
| 216 } | 220 } |
| 217 | 221 |
| 218 void LevelDBMojoProxy::FileExistsImpl(OpaqueDir* dir, | 222 void LevelDBMojoProxy::FileExistsImpl(OpaqueDir* dir, |
| 219 std::string name, | 223 std::string name, |
| 220 bool* exists) { | 224 bool* exists) { |
| 221 filesystem::FileError error = filesystem::FileError::FAILED; | 225 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 222 bool completed = | 226 bool completed = |
| 223 dir->directory->Exists(mojo::String::From(name), &error, exists); | 227 dir->directory->Exists(mojo::String::From(name), &error, exists); |
| 224 DCHECK(completed); | 228 DCHECK(completed); |
| 225 } | 229 } |
| 226 | 230 |
| 227 void LevelDBMojoProxy::GetChildrenImpl(OpaqueDir* dir, | 231 void LevelDBMojoProxy::GetChildrenImpl( |
| 228 std::string name, | 232 OpaqueDir* dir, |
| 229 std::vector<std::string>* out_contents, | 233 std::string name, |
| 230 filesystem::FileError* out_error) { | 234 std::vector<std::string>* out_contents, |
| 231 filesystem::DirectoryPtr target; | 235 filesystem::mojom::FileError* out_error) { |
| 232 filesystem::DirectoryRequest proxy = GetProxy(&target); | 236 filesystem::mojom::DirectoryPtr target; |
| 237 filesystem::mojom::DirectoryRequest proxy = GetProxy(&target); |
| 233 bool completed = dir->directory->OpenDirectory( | 238 bool completed = dir->directory->OpenDirectory( |
| 234 name, std::move(proxy), filesystem::kFlagRead | filesystem::kFlagWrite, | 239 name, std::move(proxy), |
| 235 out_error); | 240 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error); |
| 236 DCHECK(completed); | 241 DCHECK(completed); |
| 237 | 242 |
| 238 if (*out_error != filesystem::FileError::OK) | 243 if (*out_error != filesystem::mojom::FileError::OK) |
| 239 return; | 244 return; |
| 240 | 245 |
| 241 mojo::Array<filesystem::DirectoryEntryPtr> directory_contents; | 246 mojo::Array<filesystem::mojom::DirectoryEntryPtr> directory_contents; |
| 242 completed = target->Read(out_error, &directory_contents); | 247 completed = target->Read(out_error, &directory_contents); |
| 243 DCHECK(completed); | 248 DCHECK(completed); |
| 244 | 249 |
| 245 if (!directory_contents.is_null()) { | 250 if (!directory_contents.is_null()) { |
| 246 for (size_t i = 0; i < directory_contents.size(); ++i) | 251 for (size_t i = 0; i < directory_contents.size(); ++i) |
| 247 out_contents->push_back(directory_contents[i]->name.To<std::string>()); | 252 out_contents->push_back(directory_contents[i]->name.To<std::string>()); |
| 248 } | 253 } |
| 249 } | 254 } |
| 250 | 255 |
| 251 void LevelDBMojoProxy::DeleteImpl(OpaqueDir* dir, | 256 void LevelDBMojoProxy::DeleteImpl(OpaqueDir* dir, |
| 252 std::string name, | 257 std::string name, |
| 253 uint32_t delete_flags, | 258 uint32_t delete_flags, |
| 254 filesystem::FileError* out_error) { | 259 filesystem::mojom::FileError* out_error) { |
| 255 bool completed = | 260 bool completed = |
| 256 dir->directory->Delete(mojo::String::From(name), delete_flags, out_error); | 261 dir->directory->Delete(mojo::String::From(name), delete_flags, out_error); |
| 257 DCHECK(completed); | 262 DCHECK(completed); |
| 258 } | 263 } |
| 259 | 264 |
| 260 void LevelDBMojoProxy::CreateDirImpl(OpaqueDir* dir, | 265 void LevelDBMojoProxy::CreateDirImpl(OpaqueDir* dir, |
| 261 std::string name, | 266 std::string name, |
| 262 filesystem::FileError* out_error) { | 267 filesystem::mojom::FileError* out_error) { |
| 263 bool completed = dir->directory->OpenDirectory( | 268 bool completed = dir->directory->OpenDirectory( |
| 264 name, nullptr, | 269 name, nullptr, |
| 265 filesystem::kFlagRead | filesystem::kFlagWrite | filesystem::kFlagCreate, | 270 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite | |
| 271 filesystem::mojom::kFlagCreate, |
| 266 out_error); | 272 out_error); |
| 267 DCHECK(completed); | 273 DCHECK(completed); |
| 268 } | 274 } |
| 269 | 275 |
| 270 void LevelDBMojoProxy::GetFileSizeImpl(OpaqueDir* dir, | 276 void LevelDBMojoProxy::GetFileSizeImpl( |
| 271 const std::string& path, | 277 OpaqueDir* dir, |
| 272 uint64_t* file_size, | 278 const std::string& path, |
| 273 filesystem::FileError* out_error) { | 279 uint64_t* file_size, |
| 274 filesystem::FileInformationPtr info; | 280 filesystem::mojom::FileError* out_error) { |
| 281 filesystem::mojom::FileInformationPtr info; |
| 275 bool completed = dir->directory->StatFile(path, out_error, &info); | 282 bool completed = dir->directory->StatFile(path, out_error, &info); |
| 276 DCHECK(completed); | 283 DCHECK(completed); |
| 277 if (info) | 284 if (info) |
| 278 *file_size = info->size; | 285 *file_size = info->size; |
| 279 } | 286 } |
| 280 | 287 |
| 281 void LevelDBMojoProxy::RenameFileImpl(OpaqueDir* dir, | 288 void LevelDBMojoProxy::RenameFileImpl(OpaqueDir* dir, |
| 282 const std::string& old_path, | 289 const std::string& old_path, |
| 283 const std::string& new_path, | 290 const std::string& new_path, |
| 284 filesystem::FileError* out_error) { | 291 filesystem::mojom::FileError* out_error) { |
| 285 bool completed = dir->directory->Rename( | 292 bool completed = dir->directory->Rename( |
| 286 mojo::String::From(old_path), mojo::String::From(new_path), out_error); | 293 mojo::String::From(old_path), mojo::String::From(new_path), out_error); |
| 287 DCHECK(completed); | 294 DCHECK(completed); |
| 288 } | 295 } |
| 289 | 296 |
| 290 void LevelDBMojoProxy::LockFileImpl(OpaqueDir* dir, | 297 void LevelDBMojoProxy::LockFileImpl(OpaqueDir* dir, |
| 291 const std::string& path, | 298 const std::string& path, |
| 292 filesystem::FileError* out_error, | 299 filesystem::mojom::FileError* out_error, |
| 293 OpaqueLock** out_lock) { | 300 OpaqueLock** out_lock) { |
| 294 // Since a lock is associated with a file descriptor, we need to open and | 301 // Since a lock is associated with a file descriptor, we need to open and |
| 295 // have a persistent file on the other side of the connection. | 302 // have a persistent file on the other side of the connection. |
| 296 filesystem::FilePtr target; | 303 filesystem::mojom::FilePtr target; |
| 297 filesystem::FileRequest proxy = GetProxy(&target); | 304 filesystem::mojom::FileRequest proxy = GetProxy(&target); |
| 298 bool completed = dir->directory->OpenFile( | 305 bool completed = dir->directory->OpenFile( |
| 299 mojo::String::From(path), std::move(proxy), | 306 mojo::String::From(path), std::move(proxy), |
| 300 filesystem::kFlagOpenAlways | filesystem::kFlagRead | | 307 filesystem::mojom::kFlagOpenAlways | filesystem::mojom::kFlagRead | |
| 301 filesystem::kFlagWrite, | 308 filesystem::mojom::kFlagWrite, |
| 302 out_error); | 309 out_error); |
| 303 DCHECK(completed); | 310 DCHECK(completed); |
| 304 | 311 |
| 305 if (*out_error != filesystem::FileError::OK) | 312 if (*out_error != filesystem::mojom::FileError::OK) |
| 306 return; | 313 return; |
| 307 | 314 |
| 308 completed = target->Lock(out_error); | 315 completed = target->Lock(out_error); |
| 309 DCHECK(completed); | 316 DCHECK(completed); |
| 310 | 317 |
| 311 if (*out_error == filesystem::FileError::OK) { | 318 if (*out_error == filesystem::mojom::FileError::OK) { |
| 312 OpaqueLock* l = new OpaqueLock; | 319 OpaqueLock* l = new OpaqueLock; |
| 313 l->lock_file = std::move(target); | 320 l->lock_file = std::move(target); |
| 314 *out_lock = l; | 321 *out_lock = l; |
| 315 } | 322 } |
| 316 } | 323 } |
| 317 | 324 |
| 318 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock, | 325 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock, |
| 319 filesystem::FileError* out_error) { | 326 filesystem::mojom::FileError* out_error) { |
| 320 lock->lock_file->Unlock(out_error); | 327 lock->lock_file->Unlock(out_error); |
| 321 } | 328 } |
| 322 | 329 |
| 323 } // namespace leveldb | 330 } // namespace leveldb |
| OLD | NEW |