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() : handle_(nullptr), pid_(0) {} | |
Nico
2015/09/24 15:48:54
(i'm assuming you're aware of http://blogs.msdn.co
erikchen
2015/09/24 16:32:42
Windows is inconsistent about the value it uses to
Nico
2015/09/24 16:47:43
The point of the article is that INVALID_HANDLE_VA
| |
12 | |
13 SharedMemoryHandle::SharedMemoryHandle(HANDLE h, base::ProcessId pid) | |
14 : handle_(h), pid_(pid) {} | |
15 | |
16 SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle) | |
17 : handle_(handle.handle_), pid_(handle.pid_) {} | |
18 | |
19 SharedMemoryHandle& SharedMemoryHandle::operator=( | |
20 const SharedMemoryHandle& handle) { | |
21 if (this == &handle) | |
22 return *this; | |
23 | |
24 handle_ = handle.handle_; | |
25 pid_ = handle.pid_; | |
26 return *this; | |
27 } | |
28 | |
29 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { | |
30 // Invalid handles are always equal. | |
31 if (!IsValid() && !handle.IsValid()) | |
32 return true; | |
33 | |
34 return handle_ == handle.handle_ && pid_ == handle.pid_; | |
35 } | |
36 | |
37 bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const { | |
38 return !(*this == handle); | |
39 } | |
40 | |
41 void SharedMemoryHandle::Close() const { | |
42 DCHECK(handle_ != nullptr); | |
43 DCHECK(BelongsToCurrentProcess()); | |
44 ::CloseHandle(handle_); | |
45 } | |
46 | |
47 bool SharedMemoryHandle::IsValid() const { | |
48 return handle_ != nullptr; | |
49 } | |
50 | |
51 bool SharedMemoryHandle::BelongsToCurrentProcess() const { | |
52 return pid_ == base::GetCurrentProcId(); | |
53 } | |
54 | |
55 bool SharedMemoryHandle::NeedsBrokering() const { | |
56 return false; | |
57 } | |
58 | |
59 HANDLE SharedMemoryHandle::GetHandle() const { | |
60 return handle_; | |
61 } | |
62 | |
63 base::ProcessId SharedMemoryHandle::GetPID() const { | |
64 return pid_; | |
65 } | |
66 | |
67 } // namespace base | |
OLD | NEW |