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

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

Issue 2875453002: Add a size parameter to SharedMemoryHandle. (Closed)
Patch Set: Remove extraneous period. 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_handle_posix.cc ('k') | base/memory/shared_memory_mac.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 2015 The Chromium Authors. All rights reserved. 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 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_handle.h" 5 #include "base/memory/shared_memory_handle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/unguessable_token.h" 8 #include "base/unguessable_token.h"
9 9
10 namespace base { 10 namespace base {
11 11
12 SharedMemoryHandle::SharedMemoryHandle() 12 SharedMemoryHandle::SharedMemoryHandle() {}
13 : handle_(nullptr), ownership_passes_to_ipc_(false) {}
14 13
15 SharedMemoryHandle::SharedMemoryHandle(HANDLE h, 14 SharedMemoryHandle::SharedMemoryHandle(HANDLE h,
15 size_t size,
16 const base::UnguessableToken& guid) 16 const base::UnguessableToken& guid)
17 : handle_(h), ownership_passes_to_ipc_(false), guid_(guid) {} 17 : handle_(h), guid_(guid), size_(size) {}
18 18
19 void SharedMemoryHandle::Close() const { 19 void SharedMemoryHandle::Close() const {
20 DCHECK(handle_ != nullptr); 20 DCHECK(handle_ != nullptr);
21 ::CloseHandle(handle_); 21 ::CloseHandle(handle_);
22 } 22 }
23 23
24 bool SharedMemoryHandle::IsValid() const { 24 bool SharedMemoryHandle::IsValid() const {
25 return handle_ != nullptr; 25 return handle_ != nullptr;
26 } 26 }
27 27
28 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { 28 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
29 HANDLE duped_handle; 29 HANDLE duped_handle;
30 ProcessHandle process = GetCurrentProcess(); 30 ProcessHandle process = GetCurrentProcess();
31 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0, 31 BOOL success = ::DuplicateHandle(process, handle_, process, &duped_handle, 0,
32 FALSE, DUPLICATE_SAME_ACCESS); 32 FALSE, DUPLICATE_SAME_ACCESS);
33 if (!success) 33 if (!success)
34 return SharedMemoryHandle(); 34 return SharedMemoryHandle();
35 35
36 base::SharedMemoryHandle handle(duped_handle, GetGUID()); 36 base::SharedMemoryHandle handle(duped_handle, GetSize(), GetGUID());
37 handle.SetOwnershipPassesToIPC(true); 37 handle.SetOwnershipPassesToIPC(true);
38 return handle; 38 return handle;
39 } 39 }
40 40
41 HANDLE SharedMemoryHandle::GetHandle() const { 41 HANDLE SharedMemoryHandle::GetHandle() const {
42 return handle_; 42 return handle_;
43 } 43 }
44 44
45 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) { 45 void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
46 ownership_passes_to_ipc_ = ownership_passes; 46 ownership_passes_to_ipc_ = ownership_passes;
47 } 47 }
48 48
49 bool SharedMemoryHandle::OwnershipPassesToIPC() const { 49 bool SharedMemoryHandle::OwnershipPassesToIPC() const {
50 return ownership_passes_to_ipc_; 50 return ownership_passes_to_ipc_;
51 } 51 }
52 52
53 } // namespace base 53 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle_posix.cc ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698