| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 FILE *fp; | 117 FILE *fp; |
| 118 bool fix_size = true; | 118 bool fix_size = true; |
| 119 | 119 |
| 120 FilePath path; | 120 FilePath path; |
| 121 if (options.name == NULL || options.name->empty()) { | 121 if (options.name == NULL || options.name->empty()) { |
| 122 // It doesn't make sense to have a open-existing private piece of shmem | 122 // It doesn't make sense to have a open-existing private piece of shmem |
| 123 DCHECK(!options.open_existing); | 123 DCHECK(!options.open_existing); |
| 124 // Q: Why not use the shm_open() etc. APIs? | 124 // Q: Why not use the shm_open() etc. APIs? |
| 125 // A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU | 125 // A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU |
| 126 fp = file_util::CreateAndOpenTemporaryShmemFile(&path); | 126 fp = file_util::CreateAndOpenTemporaryShmemFile(&path, options.executable); |
| 127 | 127 |
| 128 // Deleting the file prevents anyone else from mapping it in | 128 // Deleting the file prevents anyone else from mapping it in |
| 129 // (making it private), and prevents the need for cleanup (once | 129 // (making it private), and prevents the need for cleanup (once |
| 130 // the last fd is closed, it is truly freed). | 130 // the last fd is closed, it is truly freed). |
| 131 if (fp) | 131 if (fp) |
| 132 file_util::Delete(path, false); | 132 file_util::Delete(path, false); |
| 133 | 133 |
| 134 } else { | 134 } else { |
| 135 if (!FilePathForMemoryName(*options.name, &path)) | 135 if (!FilePathForMemoryName(*options.name, &path)) |
| 136 return false; | 136 return false; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // (and possibly create). Modifies |filename|. Return false on | 310 // (and possibly create). Modifies |filename|. Return false on |
| 311 // error, or true of we are happy. | 311 // error, or true of we are happy. |
| 312 bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, | 312 bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, |
| 313 FilePath* path) { | 313 FilePath* path) { |
| 314 // mem_name will be used for a filename; make sure it doesn't | 314 // mem_name will be used for a filename; make sure it doesn't |
| 315 // contain anything which will confuse us. | 315 // contain anything which will confuse us. |
| 316 DCHECK_EQ(std::string::npos, mem_name.find('/')); | 316 DCHECK_EQ(std::string::npos, mem_name.find('/')); |
| 317 DCHECK_EQ(std::string::npos, mem_name.find('\0')); | 317 DCHECK_EQ(std::string::npos, mem_name.find('\0')); |
| 318 | 318 |
| 319 FilePath temp_dir; | 319 FilePath temp_dir; |
| 320 if (!file_util::GetShmemTempDir(&temp_dir)) | 320 if (!file_util::GetShmemTempDir(&temp_dir, false)) |
| 321 return false; | 321 return false; |
| 322 | 322 |
| 323 #if !defined(OS_MACOSX) | 323 #if !defined(OS_MACOSX) |
| 324 #if defined(GOOGLE_CHROME_BUILD) | 324 #if defined(GOOGLE_CHROME_BUILD) |
| 325 std::string name_base = std::string("com.google.Chrome"); | 325 std::string name_base = std::string("com.google.Chrome"); |
| 326 #else | 326 #else |
| 327 std::string name_base = std::string("org.chromium.Chromium"); | 327 std::string name_base = std::string("org.chromium.Chromium"); |
| 328 #endif | 328 #endif |
| 329 #else // OS_MACOSX | 329 #else // OS_MACOSX |
| 330 std::string name_base = std::string(base::mac::BaseBundleID()); | 330 std::string name_base = std::string(base::mac::BaseBundleID()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 360 new_handle->fd = new_fd; | 360 new_handle->fd = new_fd; |
| 361 new_handle->auto_close = true; | 361 new_handle->auto_close = true; |
| 362 | 362 |
| 363 if (close_self) | 363 if (close_self) |
| 364 Close(); | 364 Close(); |
| 365 | 365 |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace base | 369 } // namespace base |
| OLD | NEW |