summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 22:12:43 +0000
committerojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 22:12:43 +0000
commitc1da9339ac3ac493e53a094dffb4d49cc3aa8dfd (patch)
tree0224c0b3d85fe5078e49cc8d9b1c8f54c98fe200
parent6bea3284a8c15fc9a0e793d0da00423c2c2b885c (diff)
downloadchromium_src-c1da9339ac3ac493e53a094dffb4d49cc3aa8dfd.zip
chromium_src-c1da9339ac3ac493e53a094dffb4d49cc3aa8dfd.tar.gz
chromium_src-c1da9339ac3ac493e53a094dffb4d49cc3aa8dfd.tar.bz2
Reverting 6935.
Broke compile Review URL: http://codereview.chromium.org/14083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6938 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_util.cc23
-rw-r--r--base/file_util.h14
-rw-r--r--base/file_util_posix.cc40
-rw-r--r--base/file_util_win.cc22
-rw-r--r--chrome/browser/spellchecker.cc2
5 files changed, 28 insertions, 73 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 1cf22b7..10e08d5 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -275,29 +275,6 @@ bool CloseFile(FILE* file) {
return fclose(file) == 0;
}
-///////////////////////////////////////////////
-// MemoryMappedFile
-
-MemoryMappedFile::~MemoryMappedFile() {
- CloseHandles();
-}
-
-bool MemoryMappedFile::Initialize(const FilePath& file_name) {
- if (IsValid())
- return false;
-
- if (!MapFileToMemory(file_name)) {
- CloseHandles();
- return false;
- }
-
- return true;
-}
-
-bool MemoryMappedFile::IsValid() {
- return data_ != NULL;
-}
-
// Deprecated functions ----------------------------------------------------
bool AbsolutePath(std::wstring* path_str) {
diff --git a/base/file_util.h b/base/file_util.h
index d1cfb05..854703f 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -414,6 +414,8 @@ class FileEnumerator {
DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator);
};
+// TODO(port): port this class to posix.
+#if defined(OS_WIN)
class MemoryMappedFile {
public:
// The default constructor sets all members to invalid/null values.
@@ -427,8 +429,8 @@ class MemoryMappedFile {
// Later we may want to allow the user to specify access.
bool Initialize(const FilePath& file_name);
- const uint8* data() const { return data_; }
- size_t length() const { return length_; }
+ const uint8* Data() const { return data_; }
+ size_t Length() const { return length_; }
// Is file_ a valid file handle that points to an open, memory mapped file?
bool IsValid();
@@ -441,18 +443,14 @@ class MemoryMappedFile {
// Closes all open handles. Later we may want to make this public.
void CloseHandles();
-#if defined(OS_WIN)
HANDLE file_;
HANDLE file_mapping_;
-#elif defined(OS_POSIX)
- // The file descriptor.
- int file_;
-#endif
- uint8* data_;
+ const uint8* data_;
size_t length_;
DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile);
};
+#endif // defined(OS_WIN)
// Renames a file using the SHFileOperation API to ensure that the target file
// gets the correct default security descriptor in the new path.
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 7448ed8..153f70a 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
-#include <sys/mman.h>
#include <sys/stat.h>
#include <time.h>
@@ -379,9 +378,6 @@ bool SetCurrentDirectory(const FilePath& path) {
return !ret;
}
-///////////////////////////////////////////////
-// FileEnumerator
-
FileEnumerator::FileEnumerator(const FilePath& root_path,
bool recursive,
FileEnumerator::FILE_TYPE file_type)
@@ -483,41 +479,5 @@ FilePath FileEnumerator::Next() {
return Next();
}
-///////////////////////////////////////////////
-// MemoryMappedFile
-
-MemoryMappedFile::MemoryMappedFile()
- : file_(-1),
- data_(NULL),
- length_(0) {
-}
-
-bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
- file_ = open(file_name.value().c_str(), O_RDONLY);
- if (file_ == -1)
- return false;
-
- struct stat file_stat;
- if (fstat(file_, &file_stat) == -1)
- return false;
- length_ = file_stat.st_size;
-
- data_ = static_cast<uint8*>(
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
- if (data_ == MAP_FAILED)
- data_ = NULL;
- return data_ != NULL;
-}
-
-void MemoryMappedFile::CloseHandles() {
- if (data_ != NULL)
- munmap(data_, length_);
- if (file_ != -1)
- close(file_);
-
- data_ = NULL;
- length_ = 0;
- file_ = -1;
-}
} // namespace file_util
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index b674910..c287129 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -704,6 +704,22 @@ MemoryMappedFile::MemoryMappedFile()
length_(INVALID_FILE_SIZE) {
}
+MemoryMappedFile::~MemoryMappedFile() {
+ CloseHandles();
+}
+
+bool MemoryMappedFile::Initialize(const FilePath& file_name) {
+ if (IsValid())
+ return false;
+
+ if (!MapFileToMemory(file_name)) {
+ CloseHandles();
+ return false;
+ }
+
+ return true;
+}
+
bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
file_ = ::CreateFile(file_name.value().c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
@@ -720,11 +736,15 @@ bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
if (file_mapping_ == INVALID_HANDLE_VALUE)
return false;
- data_ = static_cast<const uint8*>(
+ data_ = reinterpret_cast<const uint8*>(
::MapViewOfFile(file_mapping_, FILE_MAP_READ, 0, 0, length_));
return data_ != NULL;
}
+bool MemoryMappedFile::IsValid() {
+ return data_ != NULL;
+}
+
void MemoryMappedFile::CloseHandles() {
if (data_)
::UnmapViewOfFile(data_);
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 6fc9d4c..004c39b 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -430,7 +430,7 @@ bool SpellChecker::Initialize() {
TimeTicks begin_time = TimeTicks::Now();
bdict_file_.reset(new file_util::MemoryMappedFile());
if (bdict_file_->Initialize(FilePath::FromWStringHack(bdict_file_name_))) {
- hunspell_.reset(new Hunspell(bdict_file_->data(), bdict_file_->length()));
+ hunspell_.reset(new Hunspell(bdict_file_->Data(), bdict_file_->Length()));
AddCustomWordsToHunspell();
}
DHISTOGRAM_TIMES(L"Spellcheck.InitTime", TimeTicks::Now() - begin_time);