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

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

Issue 2859843002: Add a GUID to base::SharedMemoryHandle. (Closed)
Patch Set: fix guid on android. 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_posix.cc ('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 #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::SharedMemoryHandle(HANDLE h,
15 : handle_(h), ownership_passes_to_ipc_(false) {} 16 const base::UnguessableToken& guid)
16 17 : handle_(h), ownership_passes_to_ipc_(false), guid_(guid) {}
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 18
31 void SharedMemoryHandle::Close() const { 19 void SharedMemoryHandle::Close() const {
32 DCHECK(handle_ != nullptr); 20 DCHECK(handle_ != nullptr);
33 ::CloseHandle(handle_); 21 ::CloseHandle(handle_);
34 } 22 }
35 23
36 bool SharedMemoryHandle::IsValid() const { 24 bool SharedMemoryHandle::IsValid() const {
37 return handle_ != nullptr; 25 return handle_ != nullptr;
38 } 26 }
39 27
40 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { 28 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
41 HANDLE duped_handle; 29 HANDLE duped_handle;
42 ProcessHandle process = GetCurrentProcess(); 30 ProcessHandle process = GetCurrentProcess();
43 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0, 31 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
44 FALSE, DUPLICATE_SAME_ACCESS); 32 FALSE, DUPLICATE_SAME_ACCESS);
45 if (!success) 33 if (!success)
46 return SharedMemoryHandle(); 34 return SharedMemoryHandle();
47 35
48 base::SharedMemoryHandle handle(duped_handle); 36 base::SharedMemoryHandle handle(duped_handle, GetGUID());
49 handle.SetOwnershipPassesToIPC(true); 37 handle.SetOwnershipPassesToIPC(true);
50 return handle; 38 return handle;
51 } 39 }
52 40
53 HANDLE SharedMemoryHandle::GetHandle() const { 41 HANDLE SharedMemoryHandle::GetHandle() const {
54 return handle_; 42 return handle_;
55 } 43 }
56 44
57 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { 45 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
58 ownership_passes_to_ipc_ = ownership_passes; 46 ownership_passes_to_ipc_ = ownership_passes;
59 } 47 }
60 48
61 bool SharedMemoryHandle::OwnershipPassesToIPC() const { 49 bool SharedMemoryHandle::OwnershipPassesToIPC() const {
62 return ownership_passes_to_ipc_; 50 return ownership_passes_to_ipc_;
63 } 51 }
64 52
65 } // namespace base 53 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle_posix.cc ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698