summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/cros/burn_library.cc2
-rw-r--r--chrome/browser/component_updater/component_unpacker.cc2
-rw-r--r--chrome/browser/extensions/extension_creator.cc2
-rw-r--r--chrome/common/extensions/extension_unpacker.cc2
-rw-r--r--chrome/common/zip.cc14
-rw-r--r--chrome/common/zip.h9
-rw-r--r--chrome/common/zip_unittest.cc10
-rw-r--r--chrome/test/webdriver/commands/create_session.cc2
8 files changed, 27 insertions, 16 deletions
diff --git a/chrome/browser/chromeos/cros/burn_library.cc b/chrome/browser/chromeos/cros/burn_library.cc
index a59ee28..cd5bf3f 100644
--- a/chrome/browser/chromeos/cros/burn_library.cc
+++ b/chrome/browser/chromeos/cros/burn_library.cc
@@ -153,7 +153,7 @@ void BurnLibraryImpl::DoBurn(const FilePath& source_path,
void BurnLibraryImpl::UnzipImage() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- if (Unzip(source_zip_file_, source_zip_file_.DirName())) {
+ if (zip::Unzip(source_zip_file_, source_zip_file_.DirName())) {
source_image_file_ =
source_zip_file_.DirName().Append(source_image_name_).value();
}
diff --git a/chrome/browser/component_updater/component_unpacker.cc b/chrome/browser/component_updater/component_unpacker.cc
index 0b64eba..0af20cd 100644
--- a/chrome/browser/component_updater/component_unpacker.cc
+++ b/chrome/browser/component_updater/component_unpacker.cc
@@ -186,7 +186,7 @@ ComponentUnpacker::ComponentUnpacker(const std::vector<uint8>& pk_hash,
error_ = kUzipPathError;
return;
}
- if (!Unzip(path, unpack_path_)) {
+ if (!zip::Unzip(path, unpack_path_)) {
error_ = kUnzipFailed;
return;
}
diff --git a/chrome/browser/extensions/extension_creator.cc b/chrome/browser/extensions/extension_creator.cc
index 1b7af2aef..97a5d5f 100644
--- a/chrome/browser/extensions/extension_creator.cc
+++ b/chrome/browser/extensions/extension_creator.cc
@@ -159,7 +159,7 @@ bool ExtensionCreator::CreateZip(const FilePath& extension_dir,
scoped_refptr<ExtensionCreatorFilter> filter = new ExtensionCreatorFilter();
const base::Callback<bool(const FilePath&)>& filter_cb =
base::Bind(&ExtensionCreatorFilter::ShouldPackageFile, filter.get());
- if (!Zip(extension_dir, *zip_path, filter_cb)) {
+ if (!zip::ZipWithFilterCallback(extension_dir, *zip_path, filter_cb)) {
error_message_ =
l10n_util::GetStringUTF8(IDS_EXTENSION_FAILED_DURING_PACKAGING);
return false;
diff --git a/chrome/common/extensions/extension_unpacker.cc b/chrome/common/extensions/extension_unpacker.cc
index 3b706fd..49104d0 100644
--- a/chrome/common/extensions/extension_unpacker.cc
+++ b/chrome/common/extensions/extension_unpacker.cc
@@ -161,7 +161,7 @@ bool ExtensionUnpacker::Run() {
return false;
}
- if (!Unzip(extension_path_, temp_install_dir_)) {
+ if (!zip::Unzip(extension_path_, temp_install_dir_)) {
SetError(kCouldNotUnzipExtension);
return false;
}
diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc
index 426f44f..5d92c11 100644
--- a/chrome/common/zip.cc
+++ b/chrome/common/zip.cc
@@ -17,6 +17,8 @@
#include "third_party/zlib/contrib/minizip/iowin32.h"
#endif
+namespace zip {
+
static const int kZipMaxPath = 256;
static const int kZipBufSize = 8192;
@@ -264,8 +266,8 @@ static bool AddEntryToZip(zipFile zip_file, const FilePath& path,
return success;
}
-bool Zip(const FilePath& src_dir, const FilePath& dest_file,
- const base::Callback<bool(const FilePath&)>& filter_cb) {
+bool ZipWithFilterCallback(const FilePath& src_dir, const FilePath& dest_file,
+ const FilterCallback& filter_cb) {
DCHECK(file_util::DirectoryExists(src_dir));
#if defined(OS_WIN)
@@ -327,8 +329,12 @@ static bool ExcludeHiddenFilesFilter(const FilePath& file_path) {
bool Zip(const FilePath& src_dir, const FilePath& dest_file,
bool include_hidden_files) {
if (include_hidden_files) {
- return Zip(src_dir, dest_file, base::Bind(&ExcludeNoFilesFilter));
+ return ZipWithFilterCallback(
+ src_dir, dest_file, base::Bind(&ExcludeNoFilesFilter));
} else {
- return Zip(src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter));
+ return ZipWithFilterCallback(
+ src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter));
}
}
+
+} // namespace zip
diff --git a/chrome/common/zip.h b/chrome/common/zip.h
index 7056055..a46b649 100644
--- a/chrome/common/zip.h
+++ b/chrome/common/zip.h
@@ -10,13 +10,16 @@
class FilePath;
+namespace zip {
+
// Zip the contents of src_dir into dest_file. src_path must be a directory.
// An entry will *not* be created in the zip for the root folder -- children
// of src_dir will be at the root level of the created zip. For each file in
// src_dir, include it only if the callback |filter_cb| returns true. Otherwise
// omit it.
-bool Zip(const FilePath& src_dir, const FilePath& dest_file,
- const base::Callback<bool(const FilePath&)>& filter_cb);
+typedef base::Callback<bool(const FilePath&)> FilterCallback;
+bool ZipWithFilterCallback(const FilePath& src_dir, const FilePath& dest_file,
+ const FilterCallback& filter_cb);
// Convenience method for callers who don't need to set up the filter callback.
// If |include_hidden_files| is true, files starting with "." are included.
@@ -27,4 +30,6 @@ bool Zip(const FilePath& src_dir, const FilePath& dest_file,
// Unzip the contents of zip_file into dest_dir.
bool Unzip(const FilePath& zip_file, const FilePath& dest_dir);
+} // namespace zip
+
#endif // CHROME_COMMON_ZIP_H_
diff --git a/chrome/common/zip_unittest.cc b/chrome/common/zip_unittest.cc
index 66aec32..dfffd09 100644
--- a/chrome/common/zip_unittest.cc
+++ b/chrome/common/zip_unittest.cc
@@ -50,7 +50,7 @@ class ZipTest : public PlatformTest {
void TestUnzipFile(const FilePath& path, bool expect_hidden_files) {
ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value();
- ASSERT_TRUE(Unzip(path, test_dir_));
+ ASSERT_TRUE(zip::Unzip(path, test_dir_));
file_util::FileEnumerator files(test_dir_, true,
static_cast<file_util::FileEnumerator::FileType>(
@@ -99,7 +99,7 @@ TEST_F(ZipTest, UnzipEvil) {
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("zip").AppendASCII("evil.zip");
- ASSERT_FALSE(Unzip(path, test_dir_));
+ ASSERT_FALSE(zip::Unzip(path, test_dir_));
FilePath evil_file = test_dir_;
evil_file = evil_file.AppendASCII(
"../levilevilevilevilevilevilevilevilevilevilevilevil");
@@ -110,7 +110,7 @@ TEST_F(ZipTest, UnzipEvil2) {
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip");
- ASSERT_TRUE(Unzip(path, test_dir_));
+ ASSERT_TRUE(zip::Unzip(path, test_dir_));
FilePath evil_file = test_dir_;
evil_file = evil_file.AppendASCII("../evil.txt");
ASSERT_FALSE(file_util::PathExists(evil_file));
@@ -125,7 +125,7 @@ TEST_F(ZipTest, Zip) {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
- EXPECT_TRUE(Zip(src_dir, zip_file, true));
+ EXPECT_TRUE(zip::Zip(src_dir, zip_file, true));
TestUnzipFile(zip_file, true);
}
@@ -138,7 +138,7 @@ TEST_F(ZipTest, ZipIgnoreHidden) {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
- EXPECT_TRUE(Zip(src_dir, zip_file, false));
+ EXPECT_TRUE(zip::Zip(src_dir, zip_file, false));
TestUnzipFile(zip_file, false);
}
diff --git a/chrome/test/webdriver/commands/create_session.cc b/chrome/test/webdriver/commands/create_session.cc
index b76760b8..84bdd5d 100644
--- a/chrome/test/webdriver/commands/create_session.cc
+++ b/chrome/test/webdriver/commands/create_session.cc
@@ -148,7 +148,7 @@ void CreateSession::ExecutePost(Response* const response) {
browser_options.user_data_dir =
temp_profile_dir.path().AppendASCII("user_data_dir");
- if (!Unzip(temp_profile_zip, browser_options.user_data_dir)) {
+ if (!zip::Unzip(temp_profile_zip, browser_options.user_data_dir)) {
response->SetError(new Error(
kBadRequest, "Could not unarchive provided user profile"));
return;