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

Side by Side Diff: base/test/test_file_util_mac.cc

Issue 12321062: base: Move MemoryMappedFile out of file_util.h and into its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chrome_frame again Created 7 years, 10 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/i18n/icu_util.cc ('k') | chrome/browser/spellchecker/spellcheck_hunspell_dictionary.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) 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/test/test_file_util.h" 5 #include "base/test/test_file_util.h"
6 6
7 #include <sys/mman.h> 7 #include <sys/mman.h>
8 #include <errno.h> 8 #include <errno.h>
9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/memory_mapped_file.h"
11 13
12 namespace file_util { 14 namespace file_util {
13 15
14 bool EvictFileFromSystemCache(const base::FilePath& file) { 16 bool EvictFileFromSystemCache(const base::FilePath& file) {
15 // There aren't any really direct ways to purge a file from the UBC. From 17 // There aren't any really direct ways to purge a file from the UBC. From
16 // talking with Amit Singh, the safest is to mmap the file with MAP_FILE (the 18 // talking with Amit Singh, the safest is to mmap the file with MAP_FILE (the
17 // default) + MAP_SHARED, then do an msync to invalidate the memory. The next 19 // default) + MAP_SHARED, then do an msync to invalidate the memory. The next
18 // open should then have to load the file from disk. 20 // open should then have to load the file from disk.
19 21
20 int64 length; 22 int64 length;
21 if (!file_util::GetFileSize(file, &length)) { 23 if (!file_util::GetFileSize(file, &length)) {
22 DLOG(ERROR) << "failed to get size of " << file.value(); 24 DLOG(ERROR) << "failed to get size of " << file.value();
23 return false; 25 return false;
24 } 26 }
25 27
26 // When a file is empty, we do not need to evict it from cache. 28 // When a file is empty, we do not need to evict it from cache.
27 // In fact, an attempt to map it to memory will result in error. 29 // In fact, an attempt to map it to memory will result in error.
28 if (length == 0) { 30 if (length == 0) {
29 DLOG(WARNING) << "file size is zero, will not attempt to map to memory"; 31 DLOG(WARNING) << "file size is zero, will not attempt to map to memory";
30 return true; 32 return true;
31 } 33 }
32 34
33 file_util::MemoryMappedFile mapped_file; 35 base::MemoryMappedFile mapped_file;
34 if (!mapped_file.Initialize(file)) { 36 if (!mapped_file.Initialize(file)) {
35 DLOG(WARNING) << "failed to memory map " << file.value(); 37 DLOG(WARNING) << "failed to memory map " << file.value();
36 return false; 38 return false;
37 } 39 }
38 40
39 if (msync(const_cast<uint8*>(mapped_file.data()), mapped_file.length(), 41 if (msync(const_cast<uint8*>(mapped_file.data()), mapped_file.length(),
40 MS_INVALIDATE) != 0) { 42 MS_INVALIDATE) != 0) {
41 DLOG(WARNING) << "failed to invalidate memory map of " << file.value() 43 DLOG(WARNING) << "failed to invalidate memory map of " << file.value()
42 << ", errno: " << errno; 44 << ", errno: " << errno;
43 return false; 45 return false;
44 } 46 }
45 47
46 return true; 48 return true;
47 } 49 }
48 50
49 } // namespace file_util 51 } // namespace file_util
OLDNEW
« no previous file with comments | « base/i18n/icu_util.cc ('k') | chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698