diff options
author | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:20:56 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:20:56 +0000 |
commit | a1401311d1ab56c4ed0a474bd38c108f75cb0cd9 (patch) | |
tree | 3437151d9ae1ce20a1e53a0d98c19ca01c786394 /courgette | |
parent | af5066f1e36c6579e74752647e6c584438f80f94 (diff) | |
download | chromium_org-a1401311d1ab56c4ed0a474bd38c108f75cb0cd9.tar.gz |
Merge from Chromium at DEPS revision 257591
This commit was generated by merge_to_master.py.
Change-Id: I0010df2ec3fbb5d4947cd026de2feb150ce7a6b5
Diffstat (limited to 'courgette')
-rw-r--r-- | courgette/courgette.gyp | 3 | ||||
-rw-r--r-- | courgette/courgette_tool.cc | 2 | ||||
-rw-r--r-- | courgette/ensemble_apply.cc | 2 | ||||
-rw-r--r-- | courgette/memory_allocator.cc | 62 | ||||
-rw-r--r-- | courgette/memory_allocator.h | 28 | ||||
-rw-r--r-- | courgette/third_party/bsdiff_apply.cc | 2 |
6 files changed, 25 insertions, 74 deletions
diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp index fbd1ced40d..591e4e2aa5 100644 --- a/courgette/courgette.gyp +++ b/courgette/courgette.gyp @@ -121,7 +121,8 @@ 'conditions': [ [ 'os_posix == 1 and OS != "mac" and OS != "android" and OS != "ios"', { 'conditions': [ - ['linux_use_tcmalloc==1', { + # TODO(dmikurube): Kill linux_use_tcmalloc. http://crbug.com/345554 + ['(use_allocator!="none" and use_allocator!="see_use_tcmalloc") or (use_allocator=="see_use_tcmalloc" and linux_use_tcmalloc==1)', { 'dependencies': [ '../base/allocator/allocator.gyp:allocator', ], diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc index 3b5b5e68c3..23322fd856 100644 --- a/courgette/courgette_tool.cc +++ b/courgette/courgette_tool.cc @@ -61,7 +61,7 @@ std::string ReadOrFail(const base::FilePath& file_name, const char* kind) { void WriteSinkToFile(const courgette::SinkStream *sink, const base::FilePath& output_file) { int count = - file_util::WriteFile(output_file, + base::WriteFile(output_file, reinterpret_cast<const char*>(sink->Buffer()), static_cast<int>(sink->Length())); if (count == -1) diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc index be3618bc24..967b4e48f5 100644 --- a/courgette/ensemble_apply.cc +++ b/courgette/ensemble_apply.cc @@ -416,7 +416,7 @@ Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, // Write the patched data to |new_file_name|. base::FilePath new_file_path(new_file_name); int written = - file_util::WriteFile( + base::WriteFile( new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), static_cast<int>(new_sink_stream.Length())); diff --git a/courgette/memory_allocator.cc b/courgette/memory_allocator.cc index f089163453..07daf439bb 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 d848915b5f..5386dad0d7 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_; }; diff --git a/courgette/third_party/bsdiff_apply.cc b/courgette/third_party/bsdiff_apply.cc index 3ed346e79a..435acc0935 100644 --- a/courgette/third_party/bsdiff_apply.cc +++ b/courgette/third_party/bsdiff_apply.cc @@ -200,7 +200,7 @@ BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path, } // Write the stream to disk. - int written = file_util::WriteFile( + int written = base::WriteFile( new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), static_cast<int>(new_sink_stream.Length())); |