diff options
author | rvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 05:58:13 +0000 |
---|---|---|
committer | rvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 05:58:13 +0000 |
commit | d8d7e6fb15310ab21200a51d70e0d01f05e782be (patch) | |
tree | 6c73fa41ed0799c719aaf9e0bf60da138582f9f9 /third_party | |
parent | 9b8ed73ac2e8beaec7827725ab4de3df338091e7 (diff) | |
download | chromium_src-d8d7e6fb15310ab21200a51d70e0d01f05e782be.zip chromium_src-d8d7e6fb15310ab21200a51d70e0d01f05e782be.tar.gz chromium_src-d8d7e6fb15310ab21200a51d70e0d01f05e782be.tar.bz2 |
Remove some PlatformFile uses from zlib
BUG=322664
R=hshi@chromium.org
Review URL: https://codereview.chromium.org/166573007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253727 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/zlib/google/zip_reader.cc | 28 | ||||
-rw-r--r-- | third_party/zlib/google/zip_reader.h | 4 | ||||
-rw-r--r-- | third_party/zlib/google/zip_reader_unittest.cc | 57 | ||||
-rw-r--r-- | third_party/zlib/google/zip_unittest.cc | 18 |
4 files changed, 38 insertions, 69 deletions
diff --git a/third_party/zlib/google/zip_reader.cc b/third_party/zlib/google/zip_reader.cc index 7b7870e..5bcc264 100644 --- a/third_party/zlib/google/zip_reader.cc +++ b/third_party/zlib/google/zip_reader.cc @@ -275,16 +275,10 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync( return; } - const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS | - base::PLATFORM_FILE_WRITE); - bool created = false; - base::PlatformFileError platform_file_error; - base::PlatformFile output_file = CreatePlatformFile(output_file_path, - flags, - &created, - &platform_file_error); - - if (platform_file_error != base::PLATFORM_FILE_OK) { + const int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; + base::File output_file(output_file_path, flags); + + if (!output_file.IsValid()) { DVLOG(1) << "Unzip failed: unable to create platform file at " << output_file_path.value(); base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); @@ -295,7 +289,7 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync( FROM_HERE, base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), - output_file, + Passed(output_file.Pass()), success_callback, failure_callback, progress_callback, @@ -374,7 +368,7 @@ void ZipReader::Reset() { current_entry_info_.reset(); } -void ZipReader::ExtractChunk(base::PlatformFile output_file, +void ZipReader::ExtractChunk(base::File output_file, const SuccessCallback& success_callback, const FailureCallback& failure_callback, const ProgressCallback& progress_callback, @@ -387,20 +381,14 @@ void ZipReader::ExtractChunk(base::PlatformFile output_file, if (num_bytes_read == 0) { unzCloseCurrentFile(zip_file_); - base::ClosePlatformFile(output_file); success_callback.Run(); } else if (num_bytes_read < 0) { DVLOG(1) << "Unzip failed: error while reading zipfile " << "(" << num_bytes_read << ")"; - base::ClosePlatformFile(output_file); failure_callback.Run(); } else { - if (num_bytes_read != base::WritePlatformFile(output_file, - offset, - buffer, - num_bytes_read)) { + if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) { DVLOG(1) << "Unzip failed: unable to write all bytes to target."; - base::ClosePlatformFile(output_file); failure_callback.Run(); return; } @@ -413,7 +401,7 @@ void ZipReader::ExtractChunk(base::PlatformFile output_file, FROM_HERE, base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), - output_file, + Passed(output_file.Pass()), success_callback, failure_callback, progress_callback, diff --git a/third_party/zlib/google/zip_reader.h b/third_party/zlib/google/zip_reader.h index 5f0a167..e16a2fb 100644 --- a/third_party/zlib/google/zip_reader.h +++ b/third_party/zlib/google/zip_reader.h @@ -9,10 +9,10 @@ #include "base/basictypes.h" #include "base/callback.h" #include "base/file_util.h" +#include "base/files/file.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/platform_file.h" #include "base/time/time.h" #if defined(USE_SYSTEM_MINIZIP) @@ -199,7 +199,7 @@ class ZipReader { // Extracts a chunk of the file to the target. Will post a task for the next // chunk and success/failure/progress callbacks as necessary. - void ExtractChunk(base::PlatformFile target_file, + void ExtractChunk(base::File target_file, const SuccessCallback& success_callback, const FailureCallback& failure_callback, const ProgressCallback& progress_callback, diff --git a/third_party/zlib/google/zip_reader_unittest.cc b/third_party/zlib/google/zip_reader_unittest.cc index 2033f9f..df20e6f 100644 --- a/third_party/zlib/google/zip_reader_unittest.cc +++ b/third_party/zlib/google/zip_reader_unittest.cc @@ -9,11 +9,11 @@ #include "base/bind.h" #include "base/file_util.h" +#include "base/files/file.h" #include "base/files/scoped_temp_dir.h" #include "base/logging.h" #include "base/md5.h" #include "base/path_service.h" -#include "base/platform_file.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" @@ -25,44 +25,29 @@ namespace { const static std::string kQuuxExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; -// Wrap PlatformFiles in a class so that we don't leak them in tests. -class PlatformFileWrapper { +class FileWrapper { public: typedef enum { READ_ONLY, READ_WRITE } AccessMode; - PlatformFileWrapper(const base::FilePath& file, AccessMode mode) - : file_(base::kInvalidPlatformFileValue) { - switch (mode) { - case READ_ONLY: - file_ = base::CreatePlatformFile(file, - base::PLATFORM_FILE_OPEN | - base::PLATFORM_FILE_READ, - NULL, NULL); - break; - case READ_WRITE: - file_ = base::CreatePlatformFile(file, - base::PLATFORM_FILE_CREATE_ALWAYS | - base::PLATFORM_FILE_READ | - base::PLATFORM_FILE_WRITE, - NULL, NULL); - break; - default: - NOTREACHED(); - } - return; - } + FileWrapper(const base::FilePath& path, AccessMode mode) { + int flags = base::File::FLAG_READ; + if (mode == READ_ONLY) + flags |= base::File::FLAG_OPEN; + else + flags |= base::File::FLAG_WRITE | base::File::FLAG_CREATE_ALWAYS; - ~PlatformFileWrapper() { - base::ClosePlatformFile(file_); + file_.Initialize(path, flags); } - base::PlatformFile platform_file() { return file_; } + ~FileWrapper() {} + + base::PlatformFile platform_file() { return file_.GetPlatformFile(); } private: - base::PlatformFile file_; + base::File file_; }; // A mock that provides methods that can be used as callbacks in asynchronous @@ -70,7 +55,7 @@ class PlatformFileWrapper { // Assumes that progress callbacks will be executed in-order. class MockUnzipListener : public base::SupportsWeakPtr<MockUnzipListener> { public: - MockUnzipListener() + MockUnzipListener() : success_calls_(0), failure_calls_(0), progress_calls_(0), @@ -195,8 +180,7 @@ TEST_F(ZipReaderTest, Open_ValidZipFile) { TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) { ZipReader reader; - PlatformFileWrapper zip_fd_wrapper(test_zip_file_, - PlatformFileWrapper::READ_ONLY); + FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); } @@ -233,8 +217,7 @@ TEST_F(ZipReaderTest, Iteration) { TEST_F(ZipReaderTest, PlatformFileIteration) { std::set<base::FilePath> actual_contents; ZipReader reader; - PlatformFileWrapper zip_fd_wrapper(test_zip_file_, - PlatformFileWrapper::READ_ONLY); + FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); while (reader.HasMore()) { ASSERT_TRUE(reader.OpenCurrentEntryInZip()); @@ -286,8 +269,7 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_RegularFile) { TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) { ZipReader reader; - PlatformFileWrapper zip_fd_wrapper(test_zip_file_, - PlatformFileWrapper::READ_ONLY); + FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); @@ -307,12 +289,11 @@ TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) { #if defined(OS_POSIX) TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFd_RegularFile) { ZipReader reader; - PlatformFileWrapper zip_fd_wrapper(test_zip_file_, - PlatformFileWrapper::READ_ONLY); + FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); base::FilePath out_path = test_dir_.AppendASCII("quux.txt"); - PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE); + FileWrapper out_fd_w(out_path, FileWrapper::READ_WRITE); ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); ASSERT_TRUE(reader.ExtractCurrentEntryToFd(out_fd_w.platform_file())); // Read the output file and compute the MD5. diff --git a/third_party/zlib/google/zip_unittest.cc b/third_party/zlib/google/zip_unittest.cc index afa92f1..ea456f1 100644 --- a/third_party/zlib/google/zip_unittest.cc +++ b/third_party/zlib/google/zip_unittest.cc @@ -7,6 +7,7 @@ #include <vector> #include "base/file_util.h" +#include "base/files/file.h" #include "base/files/file_enumerator.h" #include "base/files/file_path.h" #include "base/files/scoped_temp_dir.h" @@ -280,17 +281,17 @@ TEST_F(ZipTest, ZipFiles) { base::ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); - base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); + base::FilePath zip_name = temp_dir.path().AppendASCII("out.zip"); - const int flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; - const base::PlatformFile zip_fd = - base::CreatePlatformFile(zip_file, flags, NULL, NULL); - ASSERT_LE(0, zip_fd); - EXPECT_TRUE(zip::ZipFiles(src_dir, zip_file_list_, zip_fd)); - base::ClosePlatformFile(zip_fd); + base::File zip_file(zip_name, + base::File::FLAG_CREATE | base::File::FLAG_WRITE); + ASSERT_TRUE(zip_file.IsValid()); + EXPECT_TRUE(zip::ZipFiles(src_dir, zip_file_list_, + zip_file.GetPlatformFile())); + zip_file.Close(); zip::ZipReader reader; - EXPECT_TRUE(reader.Open(zip_file)); + EXPECT_TRUE(reader.Open(zip_name)); EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); for (size_t i = 0; i < zip_file_list_.size(); ++i) { EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); @@ -302,4 +303,3 @@ TEST_F(ZipTest, ZipFiles) { #endif // defined(OS_POSIX) } // namespace - |