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

Side by Side Diff: base/memory/shared_memory_android.cc

Issue 2845113005: Replace base::SharedMemory read-only methods with GetReadOnlyHandle. (Closed)
Patch Set: Comments from thakis. Created 3 years, 7 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 | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <sys/mman.h> 8 #include <sys/mman.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 24 matching lines...) Expand all
35 35
36 int err = ashmem_set_prot_region(shm_.GetHandle(), 36 int err = ashmem_set_prot_region(shm_.GetHandle(),
37 PROT_READ | PROT_WRITE | PROT_EXEC); 37 PROT_READ | PROT_WRITE | PROT_EXEC);
38 if (err < 0) { 38 if (err < 0) {
39 DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; 39 DLOG(ERROR) << "Error " << err << " when setting protection of ashmem";
40 return false; 40 return false;
41 } 41 }
42 42
43 // Android doesn't appear to have a way to drop write access on an ashmem 43 // Android doesn't appear to have a way to drop write access on an ashmem
44 // segment for a single descriptor. http://crbug.com/320865 44 // segment for a single descriptor. http://crbug.com/320865
45 readonly_mapped_file_ = dup(shm_.GetHandle()); 45 readonly_shm_ = SharedMemoryHandle::ImportHandle(dup(shm_.GetHandle()));
46 if (-1 == readonly_mapped_file_) { 46 if (!readonly_shm_.IsValid()) {
47 DPLOG(ERROR) << "dup() failed"; 47 DPLOG(ERROR) << "dup() failed";
48 return false; 48 return false;
49 } 49 }
50 50
51 requested_size_ = options.size; 51 requested_size_ = options.size;
52 52
53 return true; 53 return true;
54 } 54 }
55 55
56 bool SharedMemory::Delete(const std::string& name) { 56 bool SharedMemory::Delete(const std::string& name) {
57 // Like on Windows, this is intentionally returning true as ashmem will 57 // Like on Windows, this is intentionally returning true as ashmem will
58 // automatically releases the resource when all FDs on it are closed. 58 // automatically releases the resource when all FDs on it are closed.
59 return true; 59 return true;
60 } 60 }
61 61
62 bool SharedMemory::Open(const std::string& name, bool read_only) { 62 bool SharedMemory::Open(const std::string& name, bool read_only) {
63 // ashmem doesn't support name mapping 63 // ashmem doesn't support name mapping
64 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
65 return false; 65 return false;
66 } 66 }
67 67
68 } // namespace base 68 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory.h ('k') | base/memory/shared_memory_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698