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

Side by Side Diff: mojo/edk/embedder/simple_platform_shared_buffer_android.cc

Issue 1346643003: Convert base::ScopedFD to (mojo::embedder::)ScopedPlatformHandle. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/embedder/simple_platform_shared_buffer.h" 5 #include "mojo/edk/embedder/simple_platform_shared_buffer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sys/mman.h> // For |PROT_...|. 8 #include <sys/mman.h> // For |PROT_...|.
9 #include <sys/types.h> // For |off_t|. 9 #include <sys/types.h> // For |off_t|.
10 10
11 #include <limits> 11 #include <limits>
12 12
13 #include "base/files/scoped_file.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "mojo/edk/embedder/platform_handle.h"
16 #include "third_party/ashmem/ashmem.h" 14 #include "third_party/ashmem/ashmem.h"
17 15
18 namespace mojo { 16 namespace mojo {
19 namespace embedder { 17 namespace embedder {
20 18
21 // SimplePlatformSharedBuffer -------------------------------------------------- 19 // SimplePlatformSharedBuffer --------------------------------------------------
22 20
23 bool SimplePlatformSharedBuffer::Init() { 21 bool SimplePlatformSharedBuffer::Init() {
24 DCHECK(!handle_.is_valid()); 22 DCHECK(!handle_.is_valid());
25 23
26 if (static_cast<uint64_t>(num_bytes_) > 24 if (static_cast<uint64_t>(num_bytes_) >
27 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) { 25 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) {
28 return false; 26 return false;
29 } 27 }
30 28
31 base::ScopedFD fd(ashmem_create_region(nullptr, num_bytes_)); 29 ScopedPlatformHandle handle(
32 if (!fd.is_valid()) { 30 PlatformHandle(ashmem_create_region(nullptr, num_bytes_)));
31 if (!handle.is_valid()) {
33 DPLOG(ERROR) << "ashmem_create_region()"; 32 DPLOG(ERROR) << "ashmem_create_region()";
34 return false; 33 return false;
35 } 34 }
36 35
37 if (ashmem_set_prot_region(fd.get(), PROT_READ | PROT_WRITE) < 0) { 36 if (ashmem_set_prot_region(handle.get().fd, PROT_READ | PROT_WRITE) < 0) {
38 DPLOG(ERROR) << "ashmem_set_prot_region()"; 37 DPLOG(ERROR) << "ashmem_set_prot_region()";
39 return false; 38 return false;
40 } 39 }
41 40
42 handle_.reset(PlatformHandle(fd.release())); 41 handle_ = handle.Pass();
43 return true; 42 return true;
44 } 43 }
45 44
46 bool SimplePlatformSharedBuffer::InitFromPlatformHandle( 45 bool SimplePlatformSharedBuffer::InitFromPlatformHandle(
47 ScopedPlatformHandle platform_handle) { 46 ScopedPlatformHandle platform_handle) {
48 DCHECK(!handle_.is_valid()); 47 DCHECK(!handle_.is_valid());
49 48
50 if (static_cast<uint64_t>(num_bytes_) > 49 if (static_cast<uint64_t>(num_bytes_) >
51 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) { 50 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) {
52 return false; 51 return false;
(...skipping 10 matching lines...) Expand all
63 LOG(ERROR) << "Shared memory region has the wrong size"; 62 LOG(ERROR) << "Shared memory region has the wrong size";
64 return false; 63 return false;
65 } 64 }
66 65
67 handle_ = platform_handle.Pass(); 66 handle_ = platform_handle.Pass();
68 return true; 67 return true;
69 } 68 }
70 69
71 } // namespace embedder 70 } // namespace embedder
72 } // namespace mojo 71 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/scoped_platform_handle.h ('k') | mojo/edk/embedder/simple_platform_shared_buffer_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698