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

Unified Diff: base/memory/shared_memory_handle_win.cc

Issue 2847033003: Get rid of SharedMemory::GiveToProcess. (Closed)
Patch Set: Rebase. 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
Index: base/memory/shared_memory_handle_win.cc
diff --git a/base/memory/shared_memory_handle_win.cc b/base/memory/shared_memory_handle_win.cc
index 277a954daa1cd216c55c3b01333cc0fa4838d58a..f74a4597cbe920638eaec526727403e2ffa0142d 100644
--- a/base/memory/shared_memory_handle_win.cc
+++ b/base/memory/shared_memory_handle_win.cc
@@ -40,6 +40,22 @@ bool SharedMemoryHandle::IsValid() const {
return handle_ != nullptr;
}
+// Duplicates the underlying OS resource.
Nico 2017/05/02 15:58:45 nit: useless comment
erikchen 2017/05/02 18:45:57 Done.
+SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
+ DCHECK(BelongsToCurrentProcess());
+ HANDLE duped_handle;
+ ProcessHandle process = GetCurrentProcess();
+ BOOL success =
+ ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
+ FALSE, DUPLICATE_SAME_ACCESS);
+ if (success) {
Nico 2017/05/02 15:58:45 nit: if (!success) return SharedMemoryHandl
erikchen 2017/05/02 18:45:57 I was wondering if you would nit on this...and bet
+ base::SharedMemoryHandle handle(duped_handle, GetCurrentProcId());
+ handle.SetOwnershipPassesToIPC(true);
+ return handle;
+ }
+ return SharedMemoryHandle();
+}
+
bool SharedMemoryHandle::BelongsToCurrentProcess() const {
return pid_ == base::GetCurrentProcId();
}

Powered by Google App Engine
This is Rietveld 408576698