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

Side by Side Diff: mojo/edk/embedder/simple_platform_shared_buffer_posix.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
« no previous file with comments | « mojo/edk/embedder/simple_platform_shared_buffer_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdio.h> // For |fileno()|. 8 #include <stdio.h> // For |fileno()|.
9 #include <sys/mman.h> // For |mmap()|/|munmap()|. 9 #include <sys/mman.h> // For |mmap()|/|munmap()|.
10 #include <sys/stat.h> 10 #include <sys/stat.h>
11 #include <sys/types.h> // For |off_t|. 11 #include <sys/types.h> // For |off_t|.
12 #include <unistd.h> 12 #include <unistd.h>
13 13
14 #include <limits> 14 #include <limits>
15 15
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/files/scoped_file.h" 18 #include "base/files/scoped_file.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/posix/eintr_wrapper.h" 20 #include "base/posix/eintr_wrapper.h"
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
23 #include "mojo/edk/embedder/platform_handle.h"
24 23
25 // We assume that |size_t| and |off_t| (type for |ftruncate()|) fits in a 24 // We assume that |size_t| and |off_t| (type for |ftruncate()|) fits in a
26 // |uint64_t|. 25 // |uint64_t|.
27 static_assert(sizeof(size_t) <= sizeof(uint64_t), "size_t too big"); 26 static_assert(sizeof(size_t) <= sizeof(uint64_t), "size_t too big");
28 static_assert(sizeof(off_t) <= sizeof(uint64_t), "off_t too big"); 27 static_assert(sizeof(off_t) <= sizeof(uint64_t), "off_t too big");
29 28
30 namespace mojo { 29 namespace mojo {
31 namespace embedder { 30 namespace embedder {
32 31
33 // SimplePlatformSharedBuffer -------------------------------------------------- 32 // SimplePlatformSharedBuffer --------------------------------------------------
(...skipping 30 matching lines...) Expand all
64 return false; 63 return false;
65 } 64 }
66 // Note: |unlink()| is not interruptible. 65 // Note: |unlink()| is not interruptible.
67 if (unlink(shared_buffer_file.value().c_str()) != 0) { 66 if (unlink(shared_buffer_file.value().c_str()) != 0) {
68 PLOG(WARNING) << "unlink"; 67 PLOG(WARNING) << "unlink";
69 // This isn't "fatal" (e.g., someone else may have unlinked the file first), 68 // This isn't "fatal" (e.g., someone else may have unlinked the file first),
70 // so we may as well continue. 69 // so we may as well continue.
71 } 70 }
72 71
73 // Note: |dup()| is not interruptible (but |dup2()|/|dup3()| are). 72 // Note: |dup()| is not interruptible (but |dup2()|/|dup3()| are).
74 base::ScopedFD fd(dup(fileno(fp.get()))); 73 ScopedPlatformHandle handle(PlatformHandle(dup(fileno(fp.get()))));
75 if (!fd.is_valid()) { 74 if (!handle.is_valid()) {
76 PLOG(ERROR) << "dup"; 75 PLOG(ERROR) << "dup";
77 return false; 76 return false;
78 } 77 }
79 78
80 if (HANDLE_EINTR(ftruncate(fd.get(), static_cast<off_t>(num_bytes_))) != 0) { 79 if (HANDLE_EINTR(
80 ftruncate(handle.get().fd, static_cast<off_t>(num_bytes_))) != 0) {
81 PLOG(ERROR) << "ftruncate"; 81 PLOG(ERROR) << "ftruncate";
82 return false; 82 return false;
83 } 83 }
84 84
85 handle_.reset(PlatformHandle(fd.release())); 85 handle_ = handle.Pass();
86 return true; 86 return true;
87 } 87 }
88 88
89 bool SimplePlatformSharedBuffer::InitFromPlatformHandle( 89 bool SimplePlatformSharedBuffer::InitFromPlatformHandle(
90 ScopedPlatformHandle platform_handle) { 90 ScopedPlatformHandle platform_handle) {
91 DCHECK(!handle_.is_valid()); 91 DCHECK(!handle_.is_valid());
92 92
93 if (static_cast<uint64_t>(num_bytes_) > 93 if (static_cast<uint64_t>(num_bytes_) >
94 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) { 94 static_cast<uint64_t>(std::numeric_limits<off_t>::max())) {
95 return false; 95 return false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 // SimplePlatformSharedBufferMapping ------------------------------------------- 150 // SimplePlatformSharedBufferMapping -------------------------------------------
151 151
152 void SimplePlatformSharedBufferMapping::Unmap() { 152 void SimplePlatformSharedBufferMapping::Unmap() {
153 int result = munmap(real_base_, real_length_); 153 int result = munmap(real_base_, real_length_);
154 PLOG_IF(ERROR, result != 0) << "munmap"; 154 PLOG_IF(ERROR, result != 0) << "munmap";
155 } 155 }
156 156
157 } // namespace embedder 157 } // namespace embedder
158 } // namespace mojo 158 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/simple_platform_shared_buffer_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698