forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make SharedMemoryHandle a class on windows.
This CL is intended to be a refactor and should not introduce any behavior changes. Previously, SharedMemoryhandle was typedefed to HANDLE. Making it a class allows us to add metainformation about the process in which the HANDLE is valid. This will be used in the future by Chrome's IPC system to automatically duplicate HANDLEs into their destination process. BUG=493414, 535028 Review URL: https://codereview.chromium.org/1320783002 Cr-Commit-Position: refs/heads/master@{#350932}
- Loading branch information
Showing
37 changed files
with
300 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/memory/shared_memory_handle.h" | ||
|
||
#include "base/logging.h" | ||
|
||
namespace base { | ||
|
||
SharedMemoryHandle::SharedMemoryHandle() | ||
: handle_(nullptr), pid_(kNullProcessId) {} | ||
|
||
SharedMemoryHandle::SharedMemoryHandle(HANDLE h, base::ProcessId pid) | ||
: handle_(h), pid_(pid) {} | ||
|
||
SharedMemoryHandle::SharedMemoryHandle(const SharedMemoryHandle& handle) | ||
: handle_(handle.handle_), pid_(handle.pid_) {} | ||
|
||
SharedMemoryHandle& SharedMemoryHandle::operator=( | ||
const SharedMemoryHandle& handle) { | ||
if (this == &handle) | ||
return *this; | ||
|
||
handle_ = handle.handle_; | ||
pid_ = handle.pid_; | ||
return *this; | ||
} | ||
|
||
bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { | ||
// Invalid handles are always equal. | ||
if (!IsValid() && !handle.IsValid()) | ||
return true; | ||
|
||
return handle_ == handle.handle_ && pid_ == handle.pid_; | ||
} | ||
|
||
bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const { | ||
return !(*this == handle); | ||
} | ||
|
||
void SharedMemoryHandle::Close() const { | ||
DCHECK(handle_ != nullptr); | ||
DCHECK(BelongsToCurrentProcess()); | ||
::CloseHandle(handle_); | ||
} | ||
|
||
bool SharedMemoryHandle::IsValid() const { | ||
return handle_ != nullptr; | ||
} | ||
|
||
bool SharedMemoryHandle::BelongsToCurrentProcess() const { | ||
return pid_ == base::GetCurrentProcId(); | ||
} | ||
|
||
bool SharedMemoryHandle::NeedsBrokering() const { | ||
return false; | ||
} | ||
|
||
HANDLE SharedMemoryHandle::GetHandle() const { | ||
return handle_; | ||
} | ||
|
||
base::ProcessId SharedMemoryHandle::GetPID() const { | ||
return pid_; | ||
} | ||
|
||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.