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

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

Issue 2859843002: Add a GUID to base::SharedMemoryHandle. (Closed)
Patch Set: Compile fixes. 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 #include "base/unguessable_token.h"
8 9
9 namespace base { 10 namespace base {
10 11
11 SharedMemoryHandle::SharedMemoryHandle() 12 SharedMemoryHandle::SharedMemoryHandle()
12 : handle_(nullptr), ownership_passes_to_ipc_(false) {} 13 : handle_(nullptr), ownership_passes_to_ipc_(false) {}
13 14
14 SharedMemoryHandle::SharedMemoryHandle(HANDLE h) 15 SharedMemoryHandle(HANDLE h, const base::UnguessableToken& guid)
15 : handle_(h), ownership_passes_to_ipc_(false) {} 16 : handle_(h), ownership_passes_to_ipc_(false), guid_(guid) {}
16
17 SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle)
18 : handle_(handle.handle_),
19 ownership_passes_to_ipc_(handle.ownership_passes_to_ipc_) {}
20
21 SharedMemoryHandle& SharedMemoryHandle::operator=(
22 const SharedMemoryHandle& handle) {
23 if (this == &handle)
24 return *this;
25
26 handle_ = handle.handle_;
27 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_;
28 return *this;
29 }
30 17
31 void SharedMemoryHandle::Close() const { 18 void SharedMemoryHandle::Close() const {
32 DCHECK(handle_ != nullptr); 19 DCHECK(handle_ != nullptr);
33 ::CloseHandle(handle_); 20 ::CloseHandle(handle_);
34 } 21 }
35 22
36 bool SharedMemoryHandle::IsValid() const { 23 bool SharedMemoryHandle::IsValid() const {
37 return handle_ != nullptr; 24 return handle_ != nullptr;
38 } 25 }
39 26
40 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { 27 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
41 HANDLE duped_handle; 28 HANDLE duped_handle;
42 ProcessHandle process = GetCurrentProcess(); 29 ProcessHandle process = GetCurrentProcess();
43 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0, 30 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
44 FALSE, DUPLICATE_SAME_ACCESS); 31 FALSE, DUPLICATE_SAME_ACCESS);
45 if (!success) 32 if (!success)
46 return SharedMemoryHandle(); 33 return SharedMemoryHandle();
47 34
48 base::SharedMemoryHandle handle(duped_handle); 35 base::SharedMemoryHandle handle(duped_handle, GetGUID());
Nico 2017/05/04 17:42:13 So several handles can have the same guid? Documen
erikchen 2017/05/04 19:21:13 Done.
49 handle.SetOwnershipPassesToIPC(true); 36 handle.SetOwnershipPassesToIPC(true);
50 return handle; 37 return handle;
51 } 38 }
52 39
53 HANDLE SharedMemoryHandle::GetHandle() const { 40 HANDLE SharedMemoryHandle::GetHandle() const {
54 return handle_; 41 return handle_;
55 } 42 }
56 43
57 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { 44 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
58 ownership_passes_to_ipc_ = ownership_passes; 45 ownership_passes_to_ipc_ = ownership_passes;
59 } 46 }
60 47
61 bool SharedMemoryHandle::OwnershipPassesToIPC() const { 48 bool SharedMemoryHandle::OwnershipPassesToIPC() const {
62 return ownership_passes_to_ipc_; 49 return ownership_passes_to_ipc_;
63 } 50 }
64 51
65 } // namespace base 52 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698