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

Unified Diff: base/memory/shared_memory_win.cc

Issue 2845113005: Replace base::SharedMemory read-only methods with GetReadOnlyHandle. (Closed)
Patch Set: Comments from thakis. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_win.cc
diff --git a/base/memory/shared_memory_win.cc b/base/memory/shared_memory_win.cc
index ebe1f7bd858062a9ff4e0af0bf57ed49fc2a5cea..881e0609378565e4386234ff2a60347a68296d63 100644
--- a/base/memory/shared_memory_win.cc
+++ b/base/memory/shared_memory_win.cc
@@ -338,16 +338,28 @@ bool SharedMemory::Unmap() {
return true;
}
+SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
+ HANDLE result;
+ ProcessHandle process = GetCurrentProcess();
+ if (!::DuplicateHandle(process, mapped_file_.Get(), process, &result,
+ FILE_MAP_READ | SECTION_QUERY, FALSE, 0)) {
+ return SharedMemoryHandle();
+ }
+ SharedMemoryHandle handle =
+ SharedMemoryHandle(result, base::GetProcId(process));
+ handle.SetOwnershipPassesToIPC(true);
+ return handle;
+}
+
bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
SharedMemoryHandle* new_handle,
- bool close_self,
- ShareMode share_mode) {
+ bool close_self) {
*new_handle = SharedMemoryHandle();
DWORD access = FILE_MAP_READ | SECTION_QUERY;
DWORD options = 0;
HANDLE mapped_file = mapped_file_.Get();
HANDLE result;
- if (share_mode == SHARE_CURRENT_MODE && !read_only_)
+ if (!read_only_)
access |= FILE_MAP_WRITE;
if (close_self) {
// DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file.
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698