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

Unified Diff: base/memory/shared_memory_win.cc

Issue 2102923002: Change MessagePumpForGpu and SharedMemory to ScopedHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed spacing and added Bug ID Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/message_loop/message_pump_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/shared_memory_win.cc
diff --git a/base/memory/shared_memory_win.cc b/base/memory/shared_memory_win.cc
index 7de87a98a9dd91a3647c4c20c47e8c977136e9c9..4e1b63c3cf73b6cfc8b2eaaaa7a63206479acd7c 100644
--- a/base/memory/shared_memory_win.cc
+++ b/base/memory/shared_memory_win.cc
@@ -140,7 +140,6 @@ SharedMemoryCreateOptions::SharedMemoryCreateOptions()
SharedMemory::SharedMemory()
: external_section_(false),
- mapped_file_(NULL),
mapped_size_(0),
memory_(NULL),
read_only_(false),
@@ -149,7 +148,6 @@ SharedMemory::SharedMemory()
SharedMemory::SharedMemory(const std::wstring& name)
: external_section_(false),
name_(name),
- mapped_file_(NULL),
mapped_size_(0),
memory_(NULL),
read_only_(false),
@@ -157,12 +155,12 @@ SharedMemory::SharedMemory(const std::wstring& name)
SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only)
: external_section_(true),
- mapped_file_(handle.GetHandle()),
mapped_size_(0),
memory_(NULL),
read_only_(read_only),
requested_size_(0) {
DCHECK(!handle.IsValid() || handle.BelongsToCurrentProcess());
+ mapped_file_.Set(handle.GetHandle());
}
SharedMemory::~SharedMemory() {
@@ -218,7 +216,7 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
// wasting 32k per mapping on average.
static const size_t kSectionMask = 65536 - 1;
DCHECK(!options.executable);
- DCHECK(!mapped_file_);
+ DCHECK(!mapped_file_.Get());
if (options.size == 0) {
LogError(SIZE_ZERO);
return false;
@@ -262,9 +260,9 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
rand_values[0], rand_values[1],
rand_values[2], rand_values[3]);
}
- mapped_file_ = CreateFileMappingWithReducedPermissions(
- &sa, rounded_size, name_.empty() ? nullptr : name_.c_str());
- if (!mapped_file_) {
+ mapped_file_.Set(CreateFileMappingWithReducedPermissions(
+ &sa, rounded_size, name_.empty() ? nullptr : name_.c_str()));
+ if (!mapped_file_.IsValid()) {
// The error is logged within CreateFileMappingWithReducedPermissions().
return false;
}
@@ -294,15 +292,15 @@ bool SharedMemory::Delete(const std::string& name) {
}
bool SharedMemory::Open(const std::string& name, bool read_only) {
- DCHECK(!mapped_file_);
+ DCHECK(!mapped_file_.Get());
DWORD access = FILE_MAP_READ | SECTION_QUERY;
if (!read_only)
access |= FILE_MAP_WRITE;
name_ = ASCIIToUTF16(name);
read_only_ = read_only;
- mapped_file_ =
- OpenFileMapping(access, false, name_.empty() ? nullptr : name_.c_str());
- if (!mapped_file_)
+ mapped_file_.Set(
+ OpenFileMapping(access, false, name_.empty() ? nullptr : name_.c_str()));
+ if (!mapped_file_.IsValid())
return false;
// If a name specified assume it's an external section.
if (!name_.empty())
@@ -312,7 +310,7 @@ bool SharedMemory::Open(const std::string& name, bool read_only) {
}
bool SharedMemory::MapAt(off_t offset, size_t bytes) {
- if (mapped_file_ == NULL)
+ if (!mapped_file_.Get())
return false;
if (bytes > static_cast<size_t>(std::numeric_limits<int>::max()))
@@ -321,11 +319,12 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) {
if (memory_)
return false;
- if (external_section_ && !IsSectionSafeToMap(mapped_file_))
+ if (external_section_ && !IsSectionSafeToMap(mapped_file_.Get()))
return false;
memory_ = MapViewOfFile(
- mapped_file_, read_only_ ? FILE_MAP_READ : FILE_MAP_READ | FILE_MAP_WRITE,
+ mapped_file_.Get(),
+ read_only_ ? FILE_MAP_READ : FILE_MAP_READ | FILE_MAP_WRITE,
static_cast<uint64_t>(offset) >> 32, static_cast<DWORD>(offset), bytes);
if (memory_ != NULL) {
DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
@@ -352,14 +351,15 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
*new_handle = SharedMemoryHandle();
DWORD access = FILE_MAP_READ | SECTION_QUERY;
DWORD options = 0;
- HANDLE mapped_file = mapped_file_;
+ HANDLE mapped_file = mapped_file_.Get();
HANDLE result;
if (share_mode == SHARE_CURRENT_MODE && !read_only_)
access |= FILE_MAP_WRITE;
if (close_self) {
// DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file.
options = DUPLICATE_CLOSE_SOURCE;
- mapped_file_ = NULL;
+ HANDLE detached_handle = mapped_file_.Take();
+ DCHECK_EQ(detached_handle, mapped_file);
Unmap();
}
@@ -379,14 +379,11 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
void SharedMemory::Close() {
- if (mapped_file_ != NULL) {
- ::CloseHandle(mapped_file_);
- mapped_file_ = NULL;
- }
+ mapped_file_.Close();
}
SharedMemoryHandle SharedMemory::handle() const {
- return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId());
+ return SharedMemoryHandle(mapped_file_.Get(), base::GetCurrentProcId());
}
} // namespace base
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/message_loop/message_pump_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698