| 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 "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 typedef HANDLE SharedMemoryHandle; | 34 typedef HANDLE SharedMemoryHandle; |
| 35 #elif defined(OS_POSIX) | 35 #elif defined(OS_POSIX) |
| 36 // A SharedMemoryId is sufficient to identify a given shared memory segment on a | 36 // A SharedMemoryId is sufficient to identify a given shared memory segment on a |
| 37 // system, but insufficient to map it. | 37 // system, but insufficient to map it. |
| 38 typedef FileDescriptor SharedMemoryHandle; | 38 typedef FileDescriptor SharedMemoryHandle; |
| 39 typedef ino_t SharedMemoryId; | 39 typedef ino_t SharedMemoryId; |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 // Options for creating a shared memory object. | 42 // Options for creating a shared memory object. |
| 43 struct SharedMemoryCreateOptions { | 43 struct SharedMemoryCreateOptions { |
| 44 SharedMemoryCreateOptions() : name(NULL), size(0), open_existing(false), | 44 SharedMemoryCreateOptions() : name_deprecated(NULL), size(0), |
| 45 open_existing_deprecated(false), |
| 45 executable(false) {} | 46 executable(false) {} |
| 46 | 47 |
| 48 // DEPRECATED (crbug.com/345734): |
| 47 // If NULL, the object is anonymous. This pointer is owned by the caller | 49 // If NULL, the object is anonymous. This pointer is owned by the caller |
| 48 // and must live through the call to Create(). | 50 // and must live through the call to Create(). |
| 49 const std::string* name; | 51 const std::string* name_deprecated; |
| 50 | 52 |
| 51 // Size of the shared memory object to be created. | 53 // Size of the shared memory object to be created. |
| 52 // When opening an existing object, this has no effect. | 54 // When opening an existing object, this has no effect. |
| 53 size_t size; | 55 size_t size; |
| 54 | 56 |
| 57 // DEPRECATED (crbug.com/345734): |
| 55 // If true, and the shared memory already exists, Create() will open the | 58 // If true, and the shared memory already exists, Create() will open the |
| 56 // existing shared memory and ignore the size parameter. If false, | 59 // existing shared memory and ignore the size parameter. If false, |
| 57 // shared memory must not exist. This flag is meaningless unless name is | 60 // shared memory must not exist. This flag is meaningless unless |
| 58 // non-NULL. | 61 // name_deprecated is non-NULL. |
| 59 bool open_existing; | 62 bool open_existing_deprecated; |
| 60 | 63 |
| 61 // If true, mappings might need to be made executable later. | 64 // If true, mappings might need to be made executable later. |
| 62 bool executable; | 65 bool executable; |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 // Platform abstraction for shared memory. Provides a C++ wrapper | 68 // Platform abstraction for shared memory. Provides a C++ wrapper |
| 66 // around the OS primitive for a memory mapped file. | 69 // around the OS primitive for a memory mapped file. |
| 67 class BASE_EXPORT SharedMemory { | 70 class BASE_EXPORT SharedMemory { |
| 68 public: | 71 public: |
| 69 SharedMemory(); | 72 SharedMemory(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 bool CreateAndMapAnonymous(size_t size); | 118 bool CreateAndMapAnonymous(size_t size); |
| 116 | 119 |
| 117 // Creates an anonymous shared memory segment of size size. | 120 // Creates an anonymous shared memory segment of size size. |
| 118 // Returns true on success and false on failure. | 121 // Returns true on success and false on failure. |
| 119 bool CreateAnonymous(size_t size) { | 122 bool CreateAnonymous(size_t size) { |
| 120 SharedMemoryCreateOptions options; | 123 SharedMemoryCreateOptions options; |
| 121 options.size = size; | 124 options.size = size; |
| 122 return Create(options); | 125 return Create(options); |
| 123 } | 126 } |
| 124 | 127 |
| 128 // DEPRECATED (crbug.com/345734): |
| 125 // Creates or opens a shared memory segment based on a name. | 129 // Creates or opens a shared memory segment based on a name. |
| 126 // If open_existing is true, and the shared memory already exists, | 130 // If open_existing is true, and the shared memory already exists, |
| 127 // opens the existing shared memory and ignores the size parameter. | 131 // opens the existing shared memory and ignores the size parameter. |
| 128 // If open_existing is false, shared memory must not exist. | 132 // If open_existing is false, shared memory must not exist. |
| 129 // size is the size of the block to be created. | 133 // size is the size of the block to be created. |
| 130 // Returns true on success, false on failure. | 134 // Returns true on success, false on failure. |
| 131 bool CreateNamed(const std::string& name, bool open_existing, size_t size) { | 135 bool CreateNamedDeprecated( |
| 136 const std::string& name, bool open_existing, size_t size) { |
| 132 SharedMemoryCreateOptions options; | 137 SharedMemoryCreateOptions options; |
| 133 options.name = &name; | 138 options.name_deprecated = &name; |
| 134 options.open_existing = open_existing; | 139 options.open_existing_deprecated = open_existing; |
| 135 options.size = size; | 140 options.size = size; |
| 136 return Create(options); | 141 return Create(options); |
| 137 } | 142 } |
| 138 | 143 |
| 139 // Deletes resources associated with a shared memory segment based on name. | 144 // Deletes resources associated with a shared memory segment based on name. |
| 140 // Not all platforms require this call. | 145 // Not all platforms require this call. |
| 141 bool Delete(const std::string& name); | 146 bool Delete(const std::string& name); |
| 142 | 147 |
| 143 // Opens a shared memory segment based on a name. | 148 // Opens a shared memory segment based on a name. |
| 144 // If read_only is true, opens for read-only access. | 149 // If read_only is true, opens for read-only access. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 306 } |
| 302 | 307 |
| 303 private: | 308 private: |
| 304 SharedMemory* shared_memory_; | 309 SharedMemory* shared_memory_; |
| 305 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); | 310 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); |
| 306 }; | 311 }; |
| 307 | 312 |
| 308 } // namespace base | 313 } // namespace base |
| 309 | 314 |
| 310 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 315 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
| OLD | NEW |