OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 const SharedMemoryHandle& handle) { | 23 const SharedMemoryHandle& handle) { |
24 if (this == &handle) | 24 if (this == &handle) |
25 return *this; | 25 return *this; |
26 | 26 |
27 handle_ = handle.handle_; | 27 handle_ = handle.handle_; |
28 pid_ = handle.pid_; | 28 pid_ = handle.pid_; |
29 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; | 29 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; |
30 return *this; | 30 return *this; |
31 } | 31 } |
32 | 32 |
33 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { | |
34 // Invalid handles are always equal. | |
35 if (!IsValid() && !handle.IsValid()) | |
36 return true; | |
37 | |
38 return handle_ == handle.handle_ && pid_ == handle.pid_; | |
39 } | |
40 | |
41 bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const { | |
42 return !(*this == handle); | |
43 } | |
44 | |
45 void SharedMemoryHandle::Close() const { | 33 void SharedMemoryHandle::Close() const { |
46 DCHECK(handle_ != nullptr); | 34 DCHECK(handle_ != nullptr); |
47 DCHECK(BelongsToCurrentProcess()); | 35 DCHECK(BelongsToCurrentProcess()); |
48 ::CloseHandle(handle_); | 36 ::CloseHandle(handle_); |
49 } | 37 } |
50 | 38 |
51 bool SharedMemoryHandle::IsValid() const { | 39 bool SharedMemoryHandle::IsValid() const { |
52 return handle_ != nullptr; | 40 return handle_ != nullptr; |
53 } | 41 } |
54 | 42 |
(...skipping 15 matching lines...) Expand all Loading... |
70 | 58 |
71 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { | 59 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { |
72 ownership_passes_to_ipc_ = ownership_passes; | 60 ownership_passes_to_ipc_ = ownership_passes; |
73 } | 61 } |
74 | 62 |
75 bool SharedMemoryHandle::OwnershipPassesToIPC() const { | 63 bool SharedMemoryHandle::OwnershipPassesToIPC() const { |
76 return ownership_passes_to_ipc_; | 64 return ownership_passes_to_ipc_; |
77 } | 65 } |
78 | 66 |
79 } // namespace base | 67 } // namespace base |
OLD | NEW |