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

Side by Side Diff: base/memory/shared_memory.h

Issue 2876593002: Change SharedMemory to initialize member vars in header. (Closed)
Patch Set: wstring -> string16 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 | « no previous file | 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 (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>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/hash.h" 13 #include "base/hash.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/shared_memory_handle.h" 15 #include "base/memory/shared_memory_handle.h"
16 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
17 #include "base/strings/string16.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 19
19 #if defined(OS_POSIX) 20 #if defined(OS_POSIX)
20 #include <stdio.h> 21 #include <stdio.h>
21 #include <sys/types.h> 22 #include <sys/types.h>
22 #include <semaphore.h> 23 #include <semaphore.h>
23 #include "base/file_descriptor_posix.h" 24 #include "base/file_descriptor_posix.h"
24 #include "base/files/file_util.h" 25 #include "base/files/file_util.h"
25 #include "base/files/scoped_file.h" 26 #include "base/files/scoped_file.h"
26 #endif 27 #endif
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // to map a shared memory OS resource into the virtual address space of the 69 // to map a shared memory OS resource into the virtual address space of the
69 // current process. 70 // current process.
70 class BASE_EXPORT SharedMemory { 71 class BASE_EXPORT SharedMemory {
71 public: 72 public:
72 SharedMemory(); 73 SharedMemory();
73 74
74 #if defined(OS_WIN) 75 #if defined(OS_WIN)
75 // Similar to the default constructor, except that this allows for 76 // Similar to the default constructor, except that this allows for
76 // calling LockDeprecated() to acquire the named mutex before either Create or 77 // calling LockDeprecated() to acquire the named mutex before either Create or
77 // Open are called on Windows. 78 // Open are called on Windows.
78 explicit SharedMemory(const std::wstring& name); 79 explicit SharedMemory(const string16& name);
79 #endif 80 #endif
80 81
81 // Create a new SharedMemory object from an existing, open 82 // Create a new SharedMemory object from an existing, open
82 // shared memory file. 83 // shared memory file.
83 // 84 //
84 // WARNING: This does not reduce the OS-level permissions on the handle; it 85 // WARNING: This does not reduce the OS-level permissions on the handle; it
85 // only affects how the SharedMemory will be mmapped. Use 86 // only affects how the SharedMemory will be mmapped. Use
86 // GetReadOnlyHandle to drop permissions. TODO(jln,jyasskin): DCHECK 87 // GetReadOnlyHandle to drop permissions. TODO(jln,jyasskin): DCHECK
87 // that |read_only| matches the permissions of the handle. 88 // that |read_only| matches the permissions of the handle.
88 SharedMemory(const SharedMemoryHandle& handle, bool read_only); 89 SharedMemory(const SharedMemoryHandle& handle, bool read_only);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 235
235 private: 236 private:
236 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ 237 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \
237 (!defined(OS_MACOSX) || defined(OS_IOS)) 238 (!defined(OS_MACOSX) || defined(OS_IOS))
238 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); 239 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path);
239 #endif 240 #endif
240 241
241 #if defined(OS_WIN) 242 #if defined(OS_WIN)
242 // If true indicates this came from an external source so needs extra checks 243 // If true indicates this came from an external source so needs extra checks
243 // before being mapped. 244 // before being mapped.
244 bool external_section_; 245 bool external_section_ = false;
245 std::wstring name_; 246 string16 name_;
246 #else 247 #else
247
248 // If valid, points to the same memory region as shm_, but with readonly 248 // If valid, points to the same memory region as shm_, but with readonly
249 // permissions. 249 // permissions.
250 SharedMemoryHandle readonly_shm_; 250 SharedMemoryHandle readonly_shm_;
251 #endif 251 #endif
252 252
253 #if defined(OS_MACOSX) && !defined(OS_IOS) 253 #if defined(OS_MACOSX) && !defined(OS_IOS)
254 // The mechanism by which the memory is mapped. Only valid if |memory_| is not 254 // The mechanism by which the memory is mapped. Only valid if |memory_| is not
255 // |nullptr|. 255 // |nullptr|.
256 SharedMemoryHandle::Type mapped_memory_mechanism_; 256 SharedMemoryHandle::Type mapped_memory_mechanism_ = SharedMemoryHandle::MACH;
257 #endif 257 #endif
258 258
259 // The OS primitive that backs the shared memory region. 259 // The OS primitive that backs the shared memory region.
260 SharedMemoryHandle shm_; 260 SharedMemoryHandle shm_;
261 261
262 size_t mapped_size_; 262 size_t mapped_size_ = 0;
263 void* memory_; 263 void* memory_ = nullptr;
264 bool read_only_; 264 bool read_only_ = false;
265 size_t requested_size_; 265 size_t requested_size_ = 0;
266 266
267 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 267 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
268 }; 268 };
269 269
270 } // namespace base 270 } // namespace base
271 271
272 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 272 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698