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

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

Issue 1320783002: Make SharedMemoryHandle a class on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_global
Patch Set: Rebase. Created 5 years, 2 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.h ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle.h ('k') | base/memory/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698