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

Side by Side Diff: base/shared_memory_posix.cc

Issue 8800025: Adaptively use temp dir instead of /dev/shm for executable shmem file on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean up per review Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « base/file_util_win.cc ('k') | no next file » | 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) 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
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
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
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
OLDNEW
« no previous file with comments | « base/file_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698