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

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

Issue 2847033003: Get rid of SharedMemory::GiveToProcess. (Closed)
Patch Set: Comments from avi. 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_handle.h ('k') | base/memory/shared_memory_mac.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_handle.h" 5 #include "base/memory/shared_memory_handle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 10
(...skipping 22 matching lines...) Expand all
33 void SharedMemoryHandle::Close() const { 33 void SharedMemoryHandle::Close() const {
34 DCHECK(handle_ != nullptr); 34 DCHECK(handle_ != nullptr);
35 DCHECK(BelongsToCurrentProcess()); 35 DCHECK(BelongsToCurrentProcess());
36 ::CloseHandle(handle_); 36 ::CloseHandle(handle_);
37 } 37 }
38 38
39 bool SharedMemoryHandle::IsValid() const { 39 bool SharedMemoryHandle::IsValid() const {
40 return handle_ != nullptr; 40 return handle_ != nullptr;
41 } 41 }
42 42
43 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
44 DCHECK(BelongsToCurrentProcess());
45 HANDLE duped_handle;
46 ProcessHandle process = GetCurrentProcess();
47 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
48 FALSE, DUPLICATE_SAME_ACCESS);
49 if (!success)
50 return SharedMemoryHandle();
51
52 base::SharedMemoryHandle handle(duped_handle, GetCurrentProcId());
53 handle.SetOwnershipPassesToIPC(true);
54 return handle;
55 }
56
43 bool SharedMemoryHandle::BelongsToCurrentProcess() const { 57 bool SharedMemoryHandle::BelongsToCurrentProcess() const {
44 return pid_ == base::GetCurrentProcId(); 58 return pid_ == base::GetCurrentProcId();
45 } 59 }
46 60
47 bool SharedMemoryHandle::NeedsBrokering() const { 61 bool SharedMemoryHandle::NeedsBrokering() const {
48 return BelongsToCurrentProcess(); 62 return BelongsToCurrentProcess();
49 } 63 }
50 64
51 HANDLE SharedMemoryHandle::GetHandle() const { 65 HANDLE SharedMemoryHandle::GetHandle() const {
52 return handle_; 66 return handle_;
53 } 67 }
54 68
55 base::ProcessId SharedMemoryHandle::GetPID() const { 69 base::ProcessId SharedMemoryHandle::GetPID() const {
56 return pid_; 70 return pid_;
57 } 71 }
58 72
59 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { 73 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
60 ownership_passes_to_ipc_ = ownership_passes; 74 ownership_passes_to_ipc_ = ownership_passes;
61 } 75 }
62 76
63 bool SharedMemoryHandle::OwnershipPassesToIPC() const { 77 bool SharedMemoryHandle::OwnershipPassesToIPC() const {
64 return ownership_passes_to_ipc_; 78 return ownership_passes_to_ipc_;
65 } 79 }
66 80
67 } // namespace base 81 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698