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

Side by Side Diff: components/leveldb/leveldb_mojo_proxy.cc

Issue 2539383002: Replace base::File wrapping with typemapping. (Closed)
Patch Set: Created 4 years 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
OLDNEW
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 "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "mojo/public/cpp/bindings/interface_request.h" 12 #include "mojo/public/cpp/bindings/interface_request.h"
13 #include "mojo/public/cpp/system/platform_handle.h"
14 13
15 namespace leveldb { 14 namespace leveldb {
16 15
17 struct LevelDBMojoProxy::OpaqueLock { 16 struct LevelDBMojoProxy::OpaqueLock {
18 filesystem::mojom::FilePtr lock_file; 17 filesystem::mojom::FilePtr lock_file;
19 }; 18 };
20 19
21 struct LevelDBMojoProxy::OpaqueDir { 20 struct LevelDBMojoProxy::OpaqueDir {
22 explicit OpaqueDir( 21 explicit OpaqueDir(
23 mojo::InterfacePtrInfo<filesystem::mojom::Directory> directory_info) { 22 mojo::InterfacePtrInfo<filesystem::mojom::Directory> directory_info) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 OpaqueDir* dir) { 175 OpaqueDir* dir) {
177 // Only delete the directories on the thread that owns them. 176 // Only delete the directories on the thread that owns them.
178 delete dir; 177 delete dir;
179 outstanding_opaque_dirs_--; 178 outstanding_opaque_dirs_--;
180 } 179 }
181 180
182 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir, 181 void LevelDBMojoProxy::OpenFileHandleImpl(OpaqueDir* dir,
183 std::string name, 182 std::string name,
184 uint32_t open_flags, 183 uint32_t open_flags,
185 base::File* output_file) { 184 base::File* output_file) {
186 mojo::ScopedHandle handle; 185 base::File file;
187 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED; 186 filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
188 bool completed = 187 bool completed =
189 dir->directory->OpenFileHandle(name, open_flags, &error, &handle); 188 dir->directory->OpenFileHandle(name, open_flags, &error, &file);
190 DCHECK(completed); 189 DCHECK(completed);
191 190
192 if (error != filesystem::mojom::FileError::OK) { 191 if (error != filesystem::mojom::FileError::OK) {
193 *output_file = base::File(static_cast<base::File::Error>(error)); 192 *output_file = base::File(static_cast<base::File::Error>(error));
194 } else { 193 } else {
195 base::PlatformFile platform_file; 194 *output_file = std::move(file);
196 MojoResult unwrap_result = mojo::UnwrapPlatformFile(std::move(handle),
197 &platform_file);
198 if (unwrap_result == MOJO_RESULT_OK) {
199 *output_file = base::File(platform_file);
200 } else {
201 NOTREACHED();
202 *output_file = base::File(base::File::Error::FILE_ERROR_FAILED);
203 }
204 } 195 }
205 } 196 }
206 197
207 void LevelDBMojoProxy::SyncDirectoryImpl( 198 void LevelDBMojoProxy::SyncDirectoryImpl(
208 OpaqueDir* dir, 199 OpaqueDir* dir,
209 std::string name, 200 std::string name,
210 filesystem::mojom::FileError* out_error) { 201 filesystem::mojom::FileError* out_error) {
211 filesystem::mojom::DirectoryPtr target; 202 filesystem::mojom::DirectoryPtr target;
212 bool completed = dir->directory->OpenDirectory( 203 bool completed = dir->directory->OpenDirectory(
213 name, GetProxy(&target), 204 name, GetProxy(&target),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 *out_lock = l; 312 *out_lock = l;
322 } 313 }
323 } 314 }
324 315
325 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock, 316 void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock,
326 filesystem::mojom::FileError* out_error) { 317 filesystem::mojom::FileError* out_error) {
327 lock->lock_file->Unlock(out_error); 318 lock->lock_file->Unlock(out_error);
328 } 319 }
329 320
330 } // namespace leveldb 321 } // namespace leveldb
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698