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

Side by Side Diff: base/shared_memory_posix.cc

Issue 6469070: More DCHECK() updates. A mixture of _EQ and _GE. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updating pickle.h order Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/platform_file_posix.cc ('k') | base/shared_memory_win.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) 2010 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>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 // Chromium mostly only uses the unique/private shmem as specified by 93 // Chromium mostly only uses the unique/private shmem as specified by
94 // "name == L"". The exception is in the StatsTable. 94 // "name == L"". The exception is in the StatsTable.
95 // TODO(jrg): there is no way to "clean up" all unused named shmem if 95 // TODO(jrg): there is no way to "clean up" all unused named shmem if
96 // we restart from a crash. (That isn't a new problem, but it is a problem.) 96 // we restart from a crash. (That isn't a new problem, but it is a problem.)
97 // In case we want to delete it later, it may be useful to save the value 97 // In case we want to delete it later, it may be useful to save the value
98 // of mem_filename after FilePathForMemoryName(). 98 // of mem_filename after FilePathForMemoryName().
99 bool SharedMemory::CreateNamed(const std::string& name, 99 bool SharedMemory::CreateNamed(const std::string& name,
100 bool open_existing, uint32 size) { 100 bool open_existing, uint32 size) {
101 DCHECK(mapped_file_ == -1); 101 DCHECK_EQ(-1, mapped_file_);
102 if (size == 0) return false; 102 if (size == 0) return false;
103 103
104 // This function theoretically can block on the disk, but realistically 104 // This function theoretically can block on the disk, but realistically
105 // the temporary files we create will just go into the buffer cache 105 // the temporary files we create will just go into the buffer cache
106 // and be deleted before they ever make it out to disk. 106 // and be deleted before they ever make it out to disk.
107 base::ThreadRestrictions::ScopedAllowIO allow_io; 107 base::ThreadRestrictions::ScopedAllowIO allow_io;
108 108
109 FILE *fp; 109 FILE *fp;
110 bool fix_size = true; 110 bool fix_size = true;
111 111
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 void SharedMemory::Lock() { 237 void SharedMemory::Lock() {
238 LockOrUnlockCommon(F_LOCK); 238 LockOrUnlockCommon(F_LOCK);
239 } 239 }
240 240
241 void SharedMemory::Unlock() { 241 void SharedMemory::Unlock() {
242 LockOrUnlockCommon(F_ULOCK); 242 LockOrUnlockCommon(F_ULOCK);
243 } 243 }
244 244
245 bool SharedMemory::PrepareMapFile(FILE *fp) { 245 bool SharedMemory::PrepareMapFile(FILE *fp) {
246 DCHECK(mapped_file_ == -1); 246 DCHECK_EQ(-1, mapped_file_);
247 if (fp == NULL) return false; 247 if (fp == NULL) return false;
248 248
249 // This function theoretically can block on the disk, but realistically 249 // This function theoretically can block on the disk, but realistically
250 // the temporary files we create will just go into the buffer cache 250 // the temporary files we create will just go into the buffer cache
251 // and be deleted before they ever make it out to disk. 251 // and be deleted before they ever make it out to disk.
252 base::ThreadRestrictions::ScopedAllowIO allow_io; 252 base::ThreadRestrictions::ScopedAllowIO allow_io;
253 253
254 file_util::ScopedFILE file_closer(fp); 254 file_util::ScopedFILE file_closer(fp);
255 255
256 mapped_file_ = dup(fileno(fp)); 256 mapped_file_ = dup(fileno(fp));
(...skipping 14 matching lines...) Expand all
271 return true; 271 return true;
272 } 272 }
273 273
274 // For the given shmem named |mem_name|, return a filename to mmap() 274 // For the given shmem named |mem_name|, return a filename to mmap()
275 // (and possibly create). Modifies |filename|. Return false on 275 // (and possibly create). Modifies |filename|. Return false on
276 // error, or true of we are happy. 276 // error, or true of we are happy.
277 bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, 277 bool SharedMemory::FilePathForMemoryName(const std::string& mem_name,
278 FilePath* path) { 278 FilePath* path) {
279 // mem_name will be used for a filename; make sure it doesn't 279 // mem_name will be used for a filename; make sure it doesn't
280 // contain anything which will confuse us. 280 // contain anything which will confuse us.
281 DCHECK(mem_name.find('/') == std::string::npos); 281 DCHECK_EQ(std::string::npos, mem_name.find('/'));
282 DCHECK(mem_name.find('\0') == std::string::npos); 282 DCHECK_EQ(std::string::npos, mem_name.find('\0'));
283 283
284 FilePath temp_dir; 284 FilePath temp_dir;
285 if (!file_util::GetShmemTempDir(&temp_dir)) 285 if (!file_util::GetShmemTempDir(&temp_dir))
286 return false; 286 return false;
287 287
288 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); 288 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name);
289 return true; 289 return true;
290 } 290 }
291 291
292 void SharedMemory::LockOrUnlockCommon(int function) { 292 void SharedMemory::LockOrUnlockCommon(int function) {
(...skipping 23 matching lines...) Expand all
316 new_handle->fd = new_fd; 316 new_handle->fd = new_fd;
317 new_handle->auto_close = true; 317 new_handle->auto_close = true;
318 318
319 if (close_self) 319 if (close_self)
320 Close(); 320 Close();
321 321
322 return true; 322 return true;
323 } 323 }
324 324
325 } // namespace base 325 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file_posix.cc ('k') | base/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698