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

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

Issue 2845113005: Replace base::SharedMemory read-only methods with GetReadOnlyHandle. (Closed)
Patch Set: Comments from thakis. Created 3 years, 7 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_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 331
332 bool SharedMemory::Unmap() { 332 bool SharedMemory::Unmap() {
333 if (memory_ == NULL) 333 if (memory_ == NULL)
334 return false; 334 return false;
335 335
336 UnmapViewOfFile(memory_); 336 UnmapViewOfFile(memory_);
337 memory_ = NULL; 337 memory_ = NULL;
338 return true; 338 return true;
339 } 339 }
340 340
341 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
342 HANDLE result;
343 ProcessHandle process = GetCurrentProcess();
344 if (!::DuplicateHandle(process, mapped_file_.Get(), process, &result,
345 FILE_MAP_READ | SECTION_QUERY, FALSE, 0)) {
346 return SharedMemoryHandle();
347 }
348 SharedMemoryHandle handle =
349 SharedMemoryHandle(result, base::GetProcId(process));
350 handle.SetOwnershipPassesToIPC(true);
351 return handle;
352 }
353
341 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, 354 bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
342 SharedMemoryHandle* new_handle, 355 SharedMemoryHandle* new_handle,
343 bool close_self, 356 bool close_self) {
344 ShareMode share_mode) {
345 *new_handle = SharedMemoryHandle(); 357 *new_handle = SharedMemoryHandle();
346 DWORD access = FILE_MAP_READ | SECTION_QUERY; 358 DWORD access = FILE_MAP_READ | SECTION_QUERY;
347 DWORD options = 0; 359 DWORD options = 0;
348 HANDLE mapped_file = mapped_file_.Get(); 360 HANDLE mapped_file = mapped_file_.Get();
349 HANDLE result; 361 HANDLE result;
350 if (share_mode == SHARE_CURRENT_MODE && !read_only_) 362 if (!read_only_)
351 access |= FILE_MAP_WRITE; 363 access |= FILE_MAP_WRITE;
352 if (close_self) { 364 if (close_self) {
353 // DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file. 365 // DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file.
354 options = DUPLICATE_CLOSE_SOURCE; 366 options = DUPLICATE_CLOSE_SOURCE;
355 HANDLE detached_handle = mapped_file_.Take(); 367 HANDLE detached_handle = mapped_file_.Take();
356 DCHECK_EQ(detached_handle, mapped_file); 368 DCHECK_EQ(detached_handle, mapped_file);
357 Unmap(); 369 Unmap();
358 } 370 }
359 371
360 if (process == GetCurrentProcess() && close_self) { 372 if (process == GetCurrentProcess() && close_self) {
(...skipping 21 matching lines...) Expand all
382 394
383 SharedMemoryHandle SharedMemory::TakeHandle() { 395 SharedMemoryHandle SharedMemory::TakeHandle() {
384 SharedMemoryHandle handle(mapped_file_.Take(), base::GetCurrentProcId()); 396 SharedMemoryHandle handle(mapped_file_.Take(), base::GetCurrentProcId());
385 handle.SetOwnershipPassesToIPC(true); 397 handle.SetOwnershipPassesToIPC(true);
386 memory_ = nullptr; 398 memory_ = nullptr;
387 mapped_size_ = 0; 399 mapped_size_ = 0;
388 return handle; 400 return handle;
389 } 401 }
390 402
391 } // namespace base 403 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_unittest.cc ('k') | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698