OLD | NEW |
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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if (memory_ == NULL) | 182 if (memory_ == NULL) |
183 return false; | 183 return false; |
184 | 184 |
185 UnmapViewOfFile(memory_); | 185 UnmapViewOfFile(memory_); |
186 memory_ = NULL; | 186 memory_ = NULL; |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
190 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 190 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
191 SharedMemoryHandle *new_handle, | 191 SharedMemoryHandle *new_handle, |
192 bool close_self) { | 192 bool close_self, |
| 193 ShareMode share_mode) { |
193 *new_handle = 0; | 194 *new_handle = 0; |
194 DWORD access = FILE_MAP_READ; | 195 DWORD access = FILE_MAP_READ; |
195 DWORD options = 0; | 196 DWORD options = 0; |
196 HANDLE mapped_file = mapped_file_; | 197 HANDLE mapped_file = mapped_file_; |
197 HANDLE result; | 198 HANDLE result; |
198 if (!read_only_) | 199 if (share_mode == SHARE_CURRENT_MODE && !read_only_) |
199 access |= FILE_MAP_WRITE; | 200 access |= FILE_MAP_WRITE; |
200 if (close_self) { | 201 if (close_self) { |
201 // DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file. | 202 // DUPLICATE_CLOSE_SOURCE causes DuplicateHandle to close mapped_file. |
202 options = DUPLICATE_CLOSE_SOURCE; | 203 options = DUPLICATE_CLOSE_SOURCE; |
203 mapped_file_ = NULL; | 204 mapped_file_ = NULL; |
204 Unmap(); | 205 Unmap(); |
205 } | 206 } |
206 | 207 |
207 if (process == GetCurrentProcess() && close_self) { | 208 if (process == GetCurrentProcess() && close_self) { |
208 *new_handle = mapped_file; | 209 *new_handle = mapped_file; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void SharedMemory::Unlock() { | 253 void SharedMemory::Unlock() { |
253 DCHECK(lock_ != NULL); | 254 DCHECK(lock_ != NULL); |
254 ReleaseMutex(lock_); | 255 ReleaseMutex(lock_); |
255 } | 256 } |
256 | 257 |
257 SharedMemoryHandle SharedMemory::handle() const { | 258 SharedMemoryHandle SharedMemory::handle() const { |
258 return mapped_file_; | 259 return mapped_file_; |
259 } | 260 } |
260 | 261 |
261 } // namespace base | 262 } // namespace base |
OLD | NEW |