| 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" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 delete dir; | 178 delete dir; |
| 179 outstanding_opaque_dirs_--; | 179 outstanding_opaque_dirs_--; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir, | 182 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir, |
| 183 std::string name, | 183 std::string name, |
| 184 uint32_t open_flags, | 184 uint32_t open_flags, |
| 185 base::File* output_file) { | 185 base::File* output_file) { |
| 186 mojo::ScopedHandle handle; | 186 mojo::ScopedHandle handle; |
| 187 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; | 187 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 188 bool completed = dir->directory->OpenFileHandle(mojo::String::From(name), | 188 bool completed = |
| 189 open_flags, &error, &handle); | 189 dir->directory->OpenFileHandle(name, open_flags, &error, &handle); |
| 190 DCHECK(completed); | 190 DCHECK(completed); |
| 191 | 191 |
| 192 if (error != filesystem::mojom::FileError::OK) { | 192 if (error != filesystem::mojom::FileError::OK) { |
| 193 *output_file = base::File(static_cast<base::File::Error>(error)); | 193 *output_file = base::File(static_cast<base::File::Error>(error)); |
| 194 } else { | 194 } else { |
| 195 base::PlatformFile platform_file; | 195 base::PlatformFile platform_file; |
| 196 MojoResult unwrap_result = mojo::UnwrapPlatformFile(std::move(handle), | 196 MojoResult unwrap_result = mojo::UnwrapPlatformFile(std::move(handle), |
| 197 &platform_file); | 197 &platform_file); |
| 198 if (unwrap_result == MOJO_RESULT_OK) { | 198 if (unwrap_result == MOJO_RESULT_OK) { |
| 199 *output_file = base::File(platform_file); | 199 *output_file = base::File(platform_file); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 completed = target->Flush(out_error); | 220 completed = target->Flush(out_error); |
| 221 DCHECK(completed); | 221 DCHECK(completed); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void LevelDBMojoProxy::FileExistsImpl(OpaqueDir* dir, | 224 void LevelDBMojoProxy::FileExistsImpl(OpaqueDir* dir, |
| 225 std::string name, | 225 std::string name, |
| 226 bool* exists) { | 226 bool* exists) { |
| 227 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; | 227 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; |
| 228 bool completed = | 228 bool completed = dir->directory->Exists(name, &error, exists); |
| 229 dir->directory->Exists(mojo::String::From(name), &error, exists); | |
| 230 DCHECK(completed); | 229 DCHECK(completed); |
| 231 } | 230 } |
| 232 | 231 |
| 233 void LevelDBMojoProxy::GetChildrenImpl( | 232 void LevelDBMojoProxy::GetChildrenImpl( |
| 234 OpaqueDir* dir, | 233 OpaqueDir* dir, |
| 235 std::string name, | 234 std::string name, |
| 236 std::vector<std::string>* out_contents, | 235 std::vector<std::string>* out_contents, |
| 237 filesystem::mojom::FileError* out_error) { | 236 filesystem::mojom::FileError* out_error) { |
| 238 filesystem::mojom::DirectoryPtr target; | 237 filesystem::mojom::DirectoryPtr target; |
| 239 filesystem::mojom::DirectoryRequest proxy = GetProxy(&target); | 238 filesystem::mojom::DirectoryRequest proxy = GetProxy(&target); |
| 240 bool completed = dir->directory->OpenDirectory( | 239 bool completed = dir->directory->OpenDirectory( |
| 241 name, std::move(proxy), | 240 name, std::move(proxy), |
| 242 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error); | 241 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error); |
| 243 DCHECK(completed); | 242 DCHECK(completed); |
| 244 | 243 |
| 245 if (*out_error != filesystem::mojom::FileError::OK) | 244 if (*out_error != filesystem::mojom::FileError::OK) |
| 246 return; | 245 return; |
| 247 | 246 |
| 248 mojo::Array<filesystem::mojom::DirectoryEntryPtr> directory_contents; | 247 base::Optional<std::vector<filesystem::mojom::DirectoryEntryPtr>> |
| 248 directory_contents; |
| 249 completed = target->Read(out_error, &directory_contents); | 249 completed = target->Read(out_error, &directory_contents); |
| 250 DCHECK(completed); | 250 DCHECK(completed); |
| 251 | 251 |
| 252 if (!directory_contents.is_null()) { | 252 if (directory_contents.has_value()) { |
| 253 for (size_t i = 0; i < directory_contents.size(); ++i) | 253 for (size_t i = 0; i < directory_contents->size(); ++i) |
| 254 out_contents->push_back(directory_contents[i]->name.To<std::string>()); | 254 out_contents->push_back(directory_contents.value()[i]->name); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 void LevelDBMojoProxy::DeleteImpl(OpaqueDir* dir, | 258 void LevelDBMojoProxy::DeleteImpl(OpaqueDir* dir, |
| 259 std::string name, | 259 std::string name, |
| 260 uint32_t delete_flags, | 260 uint32_t delete_flags, |
| 261 filesystem::mojom::FileError* out_error) { | 261 filesystem::mojom::FileError* out_error) { |
| 262 bool completed = | 262 bool completed = dir->directory->Delete(name, delete_flags, out_error); |
| 263 dir->directory->Delete(mojo::String::From(name), delete_flags, out_error); | |
| 264 DCHECK(completed); | 263 DCHECK(completed); |
| 265 } | 264 } |
| 266 | 265 |
| 267 void LevelDBMojoProxy::CreateDirImpl(OpaqueDir* dir, | 266 void LevelDBMojoProxy::CreateDirImpl(OpaqueDir* dir, |
| 268 std::string name, | 267 std::string name, |
| 269 filesystem::mojom::FileError* out_error) { | 268 filesystem::mojom::FileError* out_error) { |
| 270 bool completed = dir->directory->OpenDirectory( | 269 bool completed = dir->directory->OpenDirectory( |
| 271 name, nullptr, | 270 name, nullptr, |
| 272 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite | | 271 filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite | |
| 273 filesystem::mojom::kFlagCreate, | 272 filesystem::mojom::kFlagCreate, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 284 bool completed = dir->directory->StatFile(path, out_error, &info); | 283 bool completed = dir->directory->StatFile(path, out_error, &info); |
| 285 DCHECK(completed); | 284 DCHECK(completed); |
| 286 if (info) | 285 if (info) |
| 287 *file_size = info->size; | 286 *file_size = info->size; |
| 288 } | 287 } |
| 289 | 288 |
| 290 void LevelDBMojoProxy::RenameFileImpl(OpaqueDir* dir, | 289 void LevelDBMojoProxy::RenameFileImpl(OpaqueDir* dir, |
| 291 const std::string& old_path, | 290 const std::string& old_path, |
| 292 const std::string& new_path, | 291 const std::string& new_path, |
| 293 filesystem::mojom::FileError* out_error) { | 292 filesystem::mojom::FileError* out_error) { |
| 294 bool completed = dir->directory->Rename( | 293 bool completed = dir->directory->Rename(old_path, new_path, out_error); |
| 295 mojo::String::From(old_path), mojo::String::From(new_path), out_error); | |
| 296 DCHECK(completed); | 294 DCHECK(completed); |
| 297 } | 295 } |
| 298 | 296 |
| 299 void LevelDBMojoProxy::LockFileImpl(OpaqueDir* dir, | 297 void LevelDBMojoProxy::LockFileImpl(OpaqueDir* dir, |
| 300 const std::string& path, | 298 const std::string& path, |
| 301 filesystem::mojom::FileError* out_error, | 299 filesystem::mojom::FileError* out_error, |
| 302 OpaqueLock** out_lock) { | 300 OpaqueLock** out_lock) { |
| 303 // 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 |
| 304 // have a persistent file on the other side of the connection. | 302 // have a persistent file on the other side of the connection. |
| 305 filesystem::mojom::FilePtr target; | 303 filesystem::mojom::FilePtr target; |
| 306 filesystem::mojom::FileRequest proxy = GetProxy(&target); | 304 filesystem::mojom::FileRequest proxy = GetProxy(&target); |
| 307 bool completed = dir->directory->OpenFile( | 305 bool completed = dir->directory->OpenFile(path, std::move(proxy), |
| 308 mojo::String::From(path), std::move(proxy), | 306 filesystem::mojom::kFlagOpenAlways | |
| 309 filesystem::mojom::kFlagOpenAlways | filesystem::mojom::kFlagRead | | 307 filesystem::mojom::kFlagRead | |
| 310 filesystem::mojom::kFlagWrite, | 308 filesystem::mojom::kFlagWrite, |
| 311 out_error); | 309 out_error); |
| 312 DCHECK(completed); | 310 DCHECK(completed); |
| 313 | 311 |
| 314 if (*out_error != filesystem::mojom::FileError::OK) | 312 if (*out_error != filesystem::mojom::FileError::OK) |
| 315 return; | 313 return; |
| 316 | 314 |
| 317 completed = target->Lock(out_error); | 315 completed = target->Lock(out_error); |
| 318 DCHECK(completed); | 316 DCHECK(completed); |
| 319 | 317 |
| 320 if (*out_error == filesystem::mojom::FileError::OK) { | 318 if (*out_error == filesystem::mojom::FileError::OK) { |
| 321 OpaqueLock* l = new OpaqueLock; | 319 OpaqueLock* l = new OpaqueLock; |
| 322 l->lock_file = std::move(target); | 320 l->lock_file = std::move(target); |
| 323 *out_lock = l; | 321 *out_lock = l; |
| 324 } | 322 } |
| 325 } | 323 } |
| 326 | 324 |
| 327 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock, | 325 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock, |
| 328 filesystem::mojom::FileError* out_error) { | 326 filesystem::mojom::FileError* out_error) { |
| 329 lock->lock_file->Unlock(out_error); | 327 lock->lock_file->Unlock(out_error); |
| 330 } | 328 } |
| 331 | 329 |
| 332 } // namespace leveldb | 330 } // namespace leveldb |
| OLD | NEW |