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 #include "base/memory/shared_memory.h" | 5 #include "base/memory/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> |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 | 230 |
231 // Our current implementation of shmem is with mmap()ing of files. | 231 // Our current implementation of shmem is with mmap()ing of files. |
232 // These files need to be deleted explicitly. | 232 // These files need to be deleted explicitly. |
233 // In practice this call is only needed for unit tests. | 233 // In practice this call is only needed for unit tests. |
234 bool SharedMemory::Delete(const std::string& name) { | 234 bool SharedMemory::Delete(const std::string& name) { |
235 FilePath path; | 235 FilePath path; |
236 if (!FilePathForMemoryName(name, &path)) | 236 if (!FilePathForMemoryName(name, &path)) |
237 return false; | 237 return false; |
238 | 238 |
239 if (file_util::PathExists(path)) { | 239 if (PathExists(path)) |
240 return base::Delete(path, false); | 240 return base::Delete(path, false); |
241 } | |
242 | 241 |
243 // Doesn't exist, so success. | 242 // Doesn't exist, so success. |
244 return true; | 243 return true; |
245 } | 244 } |
246 | 245 |
247 bool SharedMemory::Open(const std::string& name, bool read_only) { | 246 bool SharedMemory::Open(const std::string& name, bool read_only) { |
248 FilePath path; | 247 FilePath path; |
249 if (!FilePathForMemoryName(name, &path)) | 248 if (!FilePathForMemoryName(name, &path)) |
250 return false; | 249 return false; |
251 | 250 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 new_handle->fd = new_fd; | 414 new_handle->fd = new_fd; |
416 new_handle->auto_close = true; | 415 new_handle->auto_close = true; |
417 | 416 |
418 if (close_self) | 417 if (close_self) |
419 Close(); | 418 Close(); |
420 | 419 |
421 return true; | 420 return true; |
422 } | 421 } |
423 | 422 |
424 } // namespace base | 423 } // namespace base |
OLD | NEW |