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

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

Issue 2847033003: Get rid of SharedMemory::GiveToProcess. (Closed)
Patch Set: Rebase. 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
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 // Duplicates the underlying OS resource.
Nico 2017/05/02 15:58:45 nit: useless comment
erikchen 2017/05/02 18:45:57 Done.
44 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
45 DCHECK(BelongsToCurrentProcess());
46 HANDLE duped_handle;
47 ProcessHandle process = GetCurrentProcess();
48 BOOL success =
49 ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
50 FALSE, DUPLICATE_SAME_ACCESS);
51 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
52 base::SharedMemoryHandle handle(duped_handle, GetCurrentProcId());
53 handle.SetOwnershipPassesToIPC(true);
54 return handle;
55 }
56 return SharedMemoryHandle();
57 }
58
43 bool SharedMemoryHandle::BelongsToCurrentProcess() const { 59 bool SharedMemoryHandle::BelongsToCurrentProcess() const {
44 return pid_ == base::GetCurrentProcId(); 60 return pid_ == base::GetCurrentProcId();
45 } 61 }
46 62
47 bool SharedMemoryHandle::NeedsBrokering() const { 63 bool SharedMemoryHandle::NeedsBrokering() const {
48 return BelongsToCurrentProcess(); 64 return BelongsToCurrentProcess();
49 } 65 }
50 66
51 HANDLE SharedMemoryHandle::GetHandle() const { 67 HANDLE SharedMemoryHandle::GetHandle() const {
52 return handle_; 68 return handle_;
53 } 69 }
54 70
55 base::ProcessId SharedMemoryHandle::GetPID() const { 71 base::ProcessId SharedMemoryHandle::GetPID() const {
56 return pid_; 72 return pid_;
57 } 73 }
58 74
59 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { 75 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
60 ownership_passes_to_ipc_ = ownership_passes; 76 ownership_passes_to_ipc_ = ownership_passes;
61 } 77 }
62 78
63 bool SharedMemoryHandle::OwnershipPassesToIPC() const { 79 bool SharedMemoryHandle::OwnershipPassesToIPC() const {
64 return ownership_passes_to_ipc_; 80 return ownership_passes_to_ipc_;
65 } 81 }
66 82
67 } // namespace base 83 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698