OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/shared_memory.h" | 5 #include "base/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/platform_thread.h" | 15 #include "base/platform_thread.h" |
16 #include "base/safe_strerror_posix.h" | 16 #include "base/safe_strerror_posix.h" |
17 #include "base/string_util.h" | 17 #include "base/utf_string_conversions.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 | 20 |
21 namespace { | 21 namespace { |
22 // Paranoia. Semaphores and shared memory segments should live in different | 22 // Paranoia. Semaphores and shared memory segments should live in different |
23 // namespaces, but who knows what's out there. | 23 // namespaces, but who knows what's out there. |
24 const char kSemaphoreSuffix[] = "-sem"; | 24 const char kSemaphoreSuffix[] = "-sem"; |
25 } | 25 } |
26 | 26 |
27 SharedMemory::SharedMemory() | 27 SharedMemory::SharedMemory() |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // mem_name will be used for a filename; make sure it doesn't | 126 // mem_name will be used for a filename; make sure it doesn't |
127 // contain anything which will confuse us. | 127 // contain anything which will confuse us. |
128 DCHECK(memname.find_first_of(L"/") == std::string::npos); | 128 DCHECK(memname.find_first_of(L"/") == std::string::npos); |
129 DCHECK(memname.find_first_of(L"\0") == std::string::npos); | 129 DCHECK(memname.find_first_of(L"\0") == std::string::npos); |
130 | 130 |
131 FilePath temp_dir; | 131 FilePath temp_dir; |
132 if (file_util::GetShmemTempDir(&temp_dir) == false) | 132 if (file_util::GetShmemTempDir(&temp_dir) == false) |
133 return false; | 133 return false; |
134 | 134 |
135 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + | 135 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + |
136 WideToASCII(memname)); | 136 WideToUTF8(memname)); |
137 return true; | 137 return true; |
138 } | 138 } |
139 | 139 |
140 // Chromium mostly only use the unique/private shmem as specified by | 140 // Chromium mostly only use the unique/private shmem as specified by |
141 // "name == L"". The exception is in the StatsTable. | 141 // "name == L"". The exception is in the StatsTable. |
142 // TODO(jrg): there is no way to "clean up" all unused named shmem if | 142 // TODO(jrg): there is no way to "clean up" all unused named shmem if |
143 // we restart from a crash. (That isn't a new problem, but it is a problem.) | 143 // we restart from a crash. (That isn't a new problem, but it is a problem.) |
144 // In case we want to delete it later, it may be useful to save the value | 144 // In case we want to delete it later, it may be useful to save the value |
145 // of mem_filename after FilePathForMemoryName(). | 145 // of mem_filename after FilePathForMemoryName(). |
146 bool SharedMemory::CreateOrOpen(const std::wstring &name, | 146 bool SharedMemory::CreateOrOpen(const std::wstring &name, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 void SharedMemory::Unlock() { | 310 void SharedMemory::Unlock() { |
311 LockOrUnlockCommon(F_ULOCK); | 311 LockOrUnlockCommon(F_ULOCK); |
312 } | 312 } |
313 | 313 |
314 SharedMemoryHandle SharedMemory::handle() const { | 314 SharedMemoryHandle SharedMemory::handle() const { |
315 return FileDescriptor(mapped_file_, false); | 315 return FileDescriptor(mapped_file_, false); |
316 } | 316 } |
317 | 317 |
318 } // namespace base | 318 } // namespace base |
OLD | NEW |