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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // Returns a read-only handle to this shared memory region. The caller takes | 228 // Returns a read-only handle to this shared memory region. The caller takes |
229 // ownership of the handle. For POSIX handles, CHECK-fails if the region | 229 // ownership of the handle. For POSIX handles, CHECK-fails if the region |
230 // wasn't Created or Opened with share_read_only=true, which is required to | 230 // wasn't Created or Opened with share_read_only=true, which is required to |
231 // make the handle read-only. When the handle is passed to the IPC subsystem, | 231 // make the handle read-only. When the handle is passed to the IPC subsystem, |
232 // that takes ownership of the handle. As such, it's not valid to pass the | 232 // that takes ownership of the handle. As such, it's not valid to pass the |
233 // sample handle to the IPC subsystem twice. Returns an invalid handle on | 233 // sample handle to the IPC subsystem twice. Returns an invalid handle on |
234 // failure. | 234 // failure. |
235 SharedMemoryHandle GetReadOnlyHandle(); | 235 SharedMemoryHandle GetReadOnlyHandle(); |
236 | 236 |
237 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ | |
238 !defined(OS_NACL) | |
239 using UniqueId = std::pair<dev_t, ino_t>; | |
240 | |
241 struct UniqueIdHash { | |
242 size_t operator()(const UniqueId& id) const { | |
243 return HashInts(id.first, id.second); | |
244 } | |
245 }; | |
246 | |
247 // Returns a unique ID for this shared memory's handle. Note this function may | |
248 // access file system and be slow. | |
249 bool GetUniqueId(UniqueId* id) const; | |
250 #endif | |
251 | |
252 // Returns the last error encountered as a result of a call to Create() or | 237 // Returns the last error encountered as a result of a call to Create() or |
253 // Map(). Note: Currently only errors from Mac POSIX shared memory | 238 // Map(). Note: Currently only errors from Mac POSIX shared memory |
254 // implementation are fully instrumented. | 239 // implementation are fully instrumented. |
255 // TODO(asvitkine): Evaluate whether we want to keep this ability after | 240 // TODO(asvitkine): Evaluate whether we want to keep this ability after |
256 // crbug.com/703649 is fixed and expand to all platforms or remove. | 241 // crbug.com/703649 is fixed and expand to all platforms or remove. |
257 SharedMemoryError get_last_error() const { return last_error_; } | 242 SharedMemoryError get_last_error() const { return last_error_; } |
258 | 243 |
259 private: | 244 private: |
260 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 245 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
261 (!defined(OS_MACOSX) || defined(OS_IOS)) | 246 (!defined(OS_MACOSX) || defined(OS_IOS)) |
(...skipping 25 matching lines...) Expand all Loading... |
287 bool read_only_ = false; | 272 bool read_only_ = false; |
288 size_t requested_size_ = 0; | 273 size_t requested_size_ = 0; |
289 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; | 274 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; |
290 | 275 |
291 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 276 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
292 }; | 277 }; |
293 | 278 |
294 } // namespace base | 279 } // namespace base |
295 | 280 |
296 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 281 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |