summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-21 16:07:52 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-21 16:07:52 +0000
commit578d5dae5655184ce0abed013a103e6d9e9875d2 (patch)
treebc690b2540544b54a53625f8fd1b7a42bc5a64cd /courgette
parent88fff08b067589d6a7f5e8a69c05a67f86e39e73 (diff)
downloadchromium_src-578d5dae5655184ce0abed013a103e6d9e9875d2.zip
chromium_src-578d5dae5655184ce0abed013a103e6d9e9875d2.tar.gz
chromium_src-578d5dae5655184ce0abed013a103e6d9e9875d2.tar.bz2
Remove PlatformFile from courgette
BUG=322664 R=tommi@chromium.org Review URL: https://codereview.chromium.org/166273021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette')
-rw-r--r--courgette/memory_allocator.cc62
-rw-r--r--courgette/memory_allocator.h28
2 files changed, 20 insertions, 70 deletions
diff --git a/courgette/memory_allocator.cc b/courgette/memory_allocator.cc
index f089163..07daf43 100644
--- a/courgette/memory_allocator.cc
+++ b/courgette/memory_allocator.cc
@@ -11,54 +11,25 @@
#if defined(OS_WIN)
-namespace courgette {
-
-// TempFile
-
-TempFile::TempFile() : file_(base::kInvalidPlatformFileValue) {
-}
+namespace {
-TempFile::~TempFile() {
- Close();
-}
-
-void TempFile::Close() {
- if (valid()) {
- base::ClosePlatformFile(file_);
- file_ = base::kInvalidPlatformFileValue;
- }
-}
-
-bool TempFile::Create() {
- DCHECK(file_ == base::kInvalidPlatformFileValue);
+// The file is created in the %TEMP% folder.
+// NOTE: Since the file will be used as backing for a memory allocation,
+// it will never be so big that size_t cannot represent its size.
+base::File CreateTempFile() {
base::FilePath path;
if (!base::CreateTemporaryFile(&path))
- return false;
+ return base::File();
- bool created = false;
- base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
- int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE |
- base::PLATFORM_FILE_DELETE_ON_CLOSE |
- base::PLATFORM_FILE_TEMPORARY;
- file_ = base::CreatePlatformFile(path, flags, &created, &error_code);
- if (file_ == base::kInvalidPlatformFileValue)
- return false;
-
- return true;
-}
-
-bool TempFile::valid() const {
- return file_ != base::kInvalidPlatformFileValue;
+ int flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
+ base::File::FLAG_WRITE | base::File::FLAG_DELETE_ON_CLOSE |
+ base::File::FLAG_TEMPORARY;
+ return base::File(path, flags);
}
-base::PlatformFile TempFile::handle() const {
- return file_;
-}
+} // namespace
-bool TempFile::SetSize(size_t size) {
- return base::TruncatePlatformFile(file_, size);
-}
+namespace courgette {
// FileMapping
@@ -116,13 +87,16 @@ TempMapping::~TempMapping() {
}
bool TempMapping::Initialize(size_t size) {
+ file_ = CreateTempFile();
+ if (!file_.IsValid())
+ return false;
+
// TODO(tommi): The assumption here is that the alignment of pointers (this)
// is as strict or stricter than the alignment of the element type. This is
// not always true, e.g. __m128 has 16-byte alignment.
size += sizeof(this);
- if (!file_.Create() ||
- !file_.SetSize(size) ||
- !mapping_.Create(file_.handle(), size)) {
+ if (!file_.SetLength(size) ||
+ !mapping_.Create(file_.GetPlatformFile(), size)) {
file_.Close();
return false;
}
diff --git a/courgette/memory_allocator.h b/courgette/memory_allocator.h
index d848915..5386dad 100644
--- a/courgette/memory_allocator.h
+++ b/courgette/memory_allocator.h
@@ -8,9 +8,9 @@
#include <memory>
#include "base/basictypes.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "base/platform_file.h"
#ifndef NDEBUG
@@ -57,30 +57,6 @@ namespace courgette {
#if defined(OS_WIN)
-// Manages a temporary file. The file is created in the %TEMP% folder and
-// is deleted when the file handle is closed.
-// NOTE: Since the file will be used as backing for a memory allocation,
-// it will never be so big that size_t cannot represent its size.
-class TempFile {
- public:
- TempFile();
- ~TempFile();
-
- bool Create();
- void Close();
- bool SetSize(size_t size);
-
- // Returns true iff the temp file is currently open.
- bool valid() const;
-
- // Returns the handle of the temporary file or INVALID_HANDLE_VALUE if
- // a temp file has not been created.
- base::PlatformFile handle() const;
-
- protected:
- base::PlatformFile file_;
-};
-
// Manages a read/write virtual mapping of a physical file.
class FileMapping {
public:
@@ -130,7 +106,7 @@ class TempMapping {
static TempMapping* GetMappingFromPtr(void* mem);
protected:
- TempFile file_;
+ base::File file_;
FileMapping mapping_;
};