Commit cf0da341 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Support compressed .pak files without a .gz extension.

Many tests have 'data' dependencies on locales/en-US.pak (and other
locales). These dependencies are used to create .isolate files used
for deploying tests.

Rather than changing the dozen or so places where these dependencies
are added (which would also be somewhat fragile), this changes allows
.pak files to be compressed without changing the .pak extension.

Bug: 1017864, 1023761
Change-Id: I7eb5f617376922481bb879a097dd0db61aefe9c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912500
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715080}
parent 4042baed
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "net/filter/gzip_header.h"
#include "third_party/zlib/google/compression_utils.h" #include "third_party/zlib/google/compression_utils.h"
// For details of the file layout, see // For details of the file layout, see
...@@ -156,6 +157,14 @@ class ScopedFileWriter { ...@@ -156,6 +157,14 @@ class ScopedFileWriter {
DISALLOW_COPY_AND_ASSIGN(ScopedFileWriter); DISALLOW_COPY_AND_ASSIGN(ScopedFileWriter);
}; };
bool MmapHasGzipHeader(const base::MemoryMappedFile* mmap) {
net::GZipHeader header;
const char* header_end = nullptr;
net::GZipHeader::Status header_status = header.ReadMore(
reinterpret_cast<const char*>(mmap->data()), mmap->length(), &header_end);
return header_status == net::GZipHeader::COMPLETE_HEADER;
}
} // namespace } // namespace
namespace ui { namespace ui {
...@@ -270,7 +279,7 @@ bool DataPack::LoadFromPath(const base::FilePath& path) { ...@@ -270,7 +279,7 @@ bool DataPack::LoadFromPath(const base::FilePath& path) {
LogDataPackError(INIT_FAILED); LogDataPackError(INIT_FAILED);
return false; return false;
} }
if (path.FinalExtension() == FILE_PATH_LITERAL(".gz")) { if (MmapHasGzipHeader(mmap.get())) {
base::StringPiece compressed(reinterpret_cast<char*>(mmap->data()), base::StringPiece compressed(reinterpret_cast<char*>(mmap->data()),
mmap->length()); mmap->length());
std::string data; std::string data;
......
...@@ -409,12 +409,6 @@ base::FilePath ResourceBundle::GetLocaleFilePath( ...@@ -409,12 +409,6 @@ base::FilePath ResourceBundle::GetLocaleFilePath(
if (base::PathExists(locale_file_path)) if (base::PathExists(locale_file_path))
return locale_file_path; return locale_file_path;
// If a compressed version of the file exists, load that.
base::FilePath compressed_locale_file_path =
locale_file_path.AddExtension(FILE_PATH_LITERAL(".gz"));
if (base::PathExists(compressed_locale_file_path))
return compressed_locale_file_path;
return base::FilePath(); return base::FilePath();
} }
#endif #endif
...@@ -436,7 +430,7 @@ std::string ResourceBundle::LoadLocaleResources( ...@@ -436,7 +430,7 @@ std::string ResourceBundle::LoadLocaleResources(
std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); std::unique_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P));
if (!data_pack->LoadFromPath(locale_file_path)) { if (!data_pack->LoadFromPath(locale_file_path)) {
LOG(ERROR) << "failed to load locale.pak"; LOG(ERROR) << "failed to load locale file: " << locale_file_path;
NOTREACHED(); NOTREACHED();
return std::string(); return std::string();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment