OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_MEMORY_SHARED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_SHARED_MEMORY_H_ |
6 #define BASE_MEMORY_SHARED_MEMORY_H_ | 6 #define BASE_MEMORY_SHARED_MEMORY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 // Returns a read-only handle to this shared memory region. The caller takes | 220 // Returns a read-only handle to this shared memory region. The caller takes |
221 // ownership of the handle. For POSIX handles, CHECK-fails if the region | 221 // ownership of the handle. For POSIX handles, CHECK-fails if the region |
222 // wasn't Created or Opened with share_read_only=true, which is required to | 222 // wasn't Created or Opened with share_read_only=true, which is required to |
223 // make the handle read-only. When the handle is passed to the IPC subsystem, | 223 // make the handle read-only. When the handle is passed to the IPC subsystem, |
224 // that takes ownership of the handle. As such, it's not valid to pass the | 224 // that takes ownership of the handle. As such, it's not valid to pass the |
225 // sample handle to the IPC subsystem twice. Returns an invalid handle on | 225 // sample handle to the IPC subsystem twice. Returns an invalid handle on |
226 // failure. | 226 // failure. |
227 SharedMemoryHandle GetReadOnlyHandle(); | 227 SharedMemoryHandle GetReadOnlyHandle(); |
228 | 228 |
229 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ | |
230 !defined(OS_NACL) | |
231 using UniqueId = std::pair<dev_t, ino_t>; | |
232 | |
233 struct UniqueIdHash { | |
234 size_t operator()(const UniqueId& id) const { | |
235 return HashInts(id.first, id.second); | |
236 } | |
237 }; | |
238 | |
239 // Returns a unique ID for this shared memory's handle. Note this function may | |
240 // access file system and be slow. | |
241 bool GetUniqueId(UniqueId* id) const; | |
242 #endif | |
243 | |
244 // Returns the last error encountered as a result of a call to Create() or | 229 // Returns the last error encountered as a result of a call to Create() or |
245 // Map(). Note: Currently only errors from Mac POSIX shared memory | 230 // Map(). Note: Currently only errors from Mac POSIX shared memory |
246 // implementation are fully instrumented. | 231 // implementation are fully instrumented. |
247 // TODO(asvitkine): Evaluate whether we want to keep this ability after | 232 // TODO(asvitkine): Evaluate whether we want to keep this ability after |
248 // crbug.com/703649 is fixed and expand to all platforms or remove. | 233 // crbug.com/703649 is fixed and expand to all platforms or remove. |
249 SharedMemoryError get_last_error() const { return last_error_; } | 234 SharedMemoryError get_last_error() const { return last_error_; } |
250 | 235 |
251 private: | 236 private: |
252 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 237 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
253 (!defined(OS_MACOSX) || defined(OS_IOS)) | 238 (!defined(OS_MACOSX) || defined(OS_IOS)) |
(...skipping 25 matching lines...) Expand all Loading... |
279 bool read_only_ = false; | 264 bool read_only_ = false; |
280 size_t requested_size_ = 0; | 265 size_t requested_size_ = 0; |
281 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; | 266 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; |
282 | 267 |
283 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 268 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
284 }; | 269 }; |
285 | 270 |
286 } // namespace base | 271 } // namespace base |
287 | 272 |
288 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 273 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |