summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-13 01:36:50 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-13 01:36:50 +0000
commit4e1c76f34b910c6e9a832cbac2e2bcce8acc9f52 (patch)
treec92007614f63d5eee9d1a7c85a5834f9603000fe /base
parent3c5ed2c5747de75351c18fbf1e969eccc263d1d5 (diff)
downloadchromium_src-4e1c76f34b910c6e9a832cbac2e2bcce8acc9f52.zip
chromium_src-4e1c76f34b910c6e9a832cbac2e2bcce8acc9f52.tar.gz
chromium_src-4e1c76f34b910c6e9a832cbac2e2bcce8acc9f52.tar.bz2
Use renderer spellchecker for windows.
BUG=25677 Review URL: http://codereview.chromium.org/372075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31875 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.cc27
-rw-r--r--base/file_util.h20
-rw-r--r--base/file_util_posix.cc42
-rw-r--r--base/file_util_win.cc5
4 files changed, 45 insertions, 49 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 4cde773..8d1b517 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -267,6 +267,20 @@ MemoryMappedFile::~MemoryMappedFile() {
CloseHandles();
}
+bool MemoryMappedFile::Initialize(base::PlatformFile file) {
+ if (IsValid())
+ return false;
+
+ file_ = file;
+
+ if (!MapFileToMemoryInternal()) {
+ CloseHandles();
+ return false;
+ }
+
+ return true;
+}
+
bool MemoryMappedFile::Initialize(const FilePath& file_name) {
if (IsValid())
return false;
@@ -279,6 +293,19 @@ bool MemoryMappedFile::Initialize(const FilePath& file_name) {
return true;
}
+bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
+ file_ = base::CreatePlatformFile(file_name,
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
+ NULL);
+
+ if (file_ == base::kInvalidPlatformFileValue) {
+ LOG(ERROR) << "Couldn't open " << file_name.value();
+ return false;
+ }
+
+ return MapFileToMemoryInternal();
+}
+
bool MemoryMappedFile::IsValid() {
return data_ != NULL;
}
diff --git a/base/file_util.h b/base/file_util.h
index 8654e62..782a6a2 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -24,6 +24,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/platform_file.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "base/time.h"
@@ -490,10 +491,9 @@ class MemoryMappedFile {
// the file does not exist, or the memory mapping fails, it will return false.
// Later we may want to allow the user to specify access.
bool Initialize(const FilePath& file_name);
-#if defined(OS_POSIX)
- // As above, but works with an alreay-opened file.
- bool Initialize(const base::FileDescriptor& fd);
-#endif
+ // As above, but works with an already-opened file. MemoryMappedFile will take
+ // ownership of |file| and close it when done.
+ bool Initialize(base::PlatformFile file);
const uint8* data() const { return data_; }
size_t length() const { return length_; }
@@ -502,23 +502,19 @@ class MemoryMappedFile {
bool IsValid();
private:
- // Map the file to memory, set data_ to that memory address. Return true on
- // success, false on any kind of failure. This is a helper for Initialize().
+ // Open the given file and pass it to MapFileToMemoryInternal().
bool MapFileToMemory(const FilePath& file_name);
-#if defined(OS_POSIX)
+ // Map the file to memory, set data_ to that memory address. Return true on
+ // success, false on any kind of failure. This is a helper for Initialize().
bool MapFileToMemoryInternal();
-#endif
// Closes all open handles. Later we may want to make this public.
void CloseHandles();
+ base::PlatformFile file_;
#if defined(OS_WIN)
- HANDLE file_;
HANDLE file_mapping_;
-#elif defined(OS_POSIX)
- // The file descriptor.
- base::FileDescriptor file_;
#endif
uint8* data_;
size_t length_;
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 1a05d79..a269d3f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -667,47 +667,23 @@ bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
// MemoryMappedFile
MemoryMappedFile::MemoryMappedFile()
- : data_(NULL),
+ : file_(base::kInvalidPlatformFileValue),
+ data_(NULL),
length_(0) {
}
-bool MemoryMappedFile::Initialize(const base::FileDescriptor& fd) {
- if (IsValid())
- return false;
-
- file_ = fd;
-
- if (!MapFileToMemoryInternal()) {
- CloseHandles();
- return false;
- }
-
- return true;
-}
-
-bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
- file_ = base::FileDescriptor(open(file_name.value().c_str(), O_RDONLY), true);
-
- if (file_.fd == -1) {
- LOG(ERROR) << "Couldn't open " << file_name.value();
- return false;
- }
-
- return MapFileToMemoryInternal();
-}
-
bool MemoryMappedFile::MapFileToMemoryInternal() {
struct stat file_stat;
- if (fstat(file_.fd, &file_stat) == -1) {
- LOG(ERROR) << "Couldn't fstat " << file_.fd << ", errno " << errno;
+ if (fstat(file_, &file_stat) == base::kInvalidPlatformFileValue) {
+ LOG(ERROR) << "Couldn't fstat " << file_ << ", errno " << errno;
return false;
}
length_ = file_stat.st_size;
data_ = static_cast<uint8*>(
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.fd, 0));
+ mmap(NULL, length_, PROT_READ, MAP_SHARED, file_, 0));
if (data_ == MAP_FAILED)
- LOG(ERROR) << "Couldn't mmap " << file_.fd << ", errno " << errno;
+ LOG(ERROR) << "Couldn't mmap " << file_ << ", errno " << errno;
return data_ != MAP_FAILED;
}
@@ -715,12 +691,12 @@ bool MemoryMappedFile::MapFileToMemoryInternal() {
void MemoryMappedFile::CloseHandles() {
if (data_ != NULL)
munmap(data_, length_);
- if (file_.auto_close && file_.fd != -1)
- close(file_.fd);
+ if (file_ != base::kInvalidPlatformFileValue)
+ close(file_);
data_ = NULL;
length_ = 0;
- file_ = base::FileDescriptor();
+ file_ = base::kInvalidPlatformFileValue;
}
} // namespace file_util
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index d6edc6f..3105d37 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -773,10 +773,7 @@ MemoryMappedFile::MemoryMappedFile()
length_(INVALID_FILE_SIZE) {
}
-bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
- file_ = ::CreateFile(file_name.value().c_str(), GENERIC_READ,
- FILE_SHARE_READ, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
+bool MemoryMappedFile::MapFileToMemoryInternal() {
if (file_ == INVALID_HANDLE_VALUE)
return false;