OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/shared_memory_handle.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace base { |
| 10 |
| 11 SharedMemoryHandle::SharedMemoryHandle() |
| 12 : handle_(nullptr), pid_(kNullProcessId) {} |
| 13 |
| 14 SharedMemoryHandle::SharedMemoryHandle(HANDLE h, base::ProcessId pid) |
| 15 : handle_(h), pid_(pid) {} |
| 16 |
| 17 SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle) |
| 18 : handle_(handle.handle_), pid_(handle.pid_) {} |
| 19 |
| 20 SharedMemoryHandle& SharedMemoryHandle::operator=( |
| 21 const SharedMemoryHandle& handle) { |
| 22 if (this == &handle) |
| 23 return *this; |
| 24 |
| 25 handle_ = handle.handle_; |
| 26 pid_ = handle.pid_; |
| 27 return *this; |
| 28 } |
| 29 |
| 30 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { |
| 31 // Invalid handles are always equal. |
| 32 if (!IsValid() && !handle.IsValid()) |
| 33 return true; |
| 34 |
| 35 return handle_ == handle.handle_ && pid_ == handle.pid_; |
| 36 } |
| 37 |
| 38 bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const { |
| 39 return !(*this == handle); |
| 40 } |
| 41 |
| 42 void SharedMemoryHandle::Close() const { |
| 43 DCHECK(handle_ != nullptr); |
| 44 DCHECK(BelongsToCurrentProcess()); |
| 45 ::CloseHandle(handle_); |
| 46 } |
| 47 |
| 48 bool SharedMemoryHandle::IsValid() const { |
| 49 return handle_ != nullptr; |
| 50 } |
| 51 |
| 52 bool SharedMemoryHandle::BelongsToCurrentProcess() const { |
| 53 return pid_ == base::GetCurrentProcId(); |
| 54 } |
| 55 |
| 56 bool SharedMemoryHandle::NeedsBrokering() const { |
| 57 return false; |
| 58 } |
| 59 |
| 60 HANDLE SharedMemoryHandle::GetHandle() const { |
| 61 return handle_; |
| 62 } |
| 63 |
| 64 base::ProcessId SharedMemoryHandle::GetPID() const { |
| 65 return pid_; |
| 66 } |
| 67 |
| 68 } // namespace base |
OLD | NEW |