Commit 1e462f3f authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Compress IDR_DIR_HEADER_HTML within the .pak file.

Bug: 982762
Change-Id: Ia381787192d654d21e7928afb58d461f94b6539c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851084Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704692}
parent 3ef9b281
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -23,8 +22,6 @@ namespace { ...@@ -23,8 +22,6 @@ namespace {
// The net module doesn't have access to this HTML or the strings that need to // The net module doesn't have access to this HTML or the strings that need to
// be localized. The Chrome locale will never change while we're running, so // be localized. The Chrome locale will never change while we're running, so
// it's safe to have a static string that we always return a pointer into. // it's safe to have a static string that we always return a pointer into.
// This allows us to have the ResourceProvider return a pointer into the actual
// resource (via a StringPiece), instead of always copying resources.
struct LazyDirectoryListerCacher { struct LazyDirectoryListerCacher {
LazyDirectoryListerCacher() { LazyDirectoryListerCacher() {
base::DictionaryValue value; base::DictionaryValue value;
...@@ -44,22 +41,24 @@ struct LazyDirectoryListerCacher { ...@@ -44,22 +41,24 @@ struct LazyDirectoryListerCacher {
l10n_util::GetStringFUTF16(IDS_DIRECTORY_LISTING_PARSING_ERROR_BOX_TEXT, l10n_util::GetStringFUTF16(IDS_DIRECTORY_LISTING_PARSING_ERROR_BOX_TEXT,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
html_data = webui::GetI18nTemplateHtml( std::string str = webui::GetI18nTemplateHtml(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( ui::ResourceBundle::GetSharedInstance().DecompressDataResource(
IDR_DIR_HEADER_HTML), IDR_DIR_HEADER_HTML),
&value); &value);
html_data = base::RefCountedString::TakeString(&str);
} }
std::string html_data; scoped_refptr<base::RefCountedMemory> html_data;
}; };
} // namespace } // namespace
base::StringPiece ChromeNetResourceProvider(int key) { scoped_refptr<base::RefCountedMemory> ChromeNetResourceProvider(int key) {
static base::NoDestructor<LazyDirectoryListerCacher> lazy_dir_lister; static base::NoDestructor<LazyDirectoryListerCacher> lazy_dir_lister;
if (IDR_DIR_HEADER_HTML == key) if (IDR_DIR_HEADER_HTML == key)
return base::StringPiece(lazy_dir_lister->html_data); return lazy_dir_lister->html_data;
return ui::ResourceBundle::GetSharedInstance().GetRawDataResource(key); return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(key);
} }
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#ifndef CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_ #ifndef CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
#define CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_ #define CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
#include "base/strings/string_piece.h" #include "base/memory/ref_counted_memory.h"
// This is called indirectly by the network layer to access resources. // This is called indirectly by the network layer to access resources.
base::StringPiece ChromeNetResourceProvider(int key); scoped_refptr<base::RefCountedMemory> ChromeNetResourceProvider(int key);
#endif // CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_ #endif // CHROME_COMMON_NET_NET_RESOURCE_PROVIDER_H_
...@@ -83,14 +83,12 @@ GURL GetStartupURL() { ...@@ -83,14 +83,12 @@ GURL GetStartupURL() {
base::MakeAbsoluteFilePath(base::FilePath(args[0]))); base::MakeAbsoluteFilePath(base::FilePath(args[0])));
} }
base::StringPiece PlatformResourceProvider(int key) { scoped_refptr<base::RefCountedMemory> PlatformResourceProvider(int key) {
if (key == IDR_DIR_HEADER_HTML) { if (key == IDR_DIR_HEADER_HTML) {
base::StringPiece html_data = return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DIR_HEADER_HTML); IDR_DIR_HEADER_HTML);
return html_data;
} }
return base::StringPiece(); return nullptr;
} }
} // namespace } // namespace
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/json/string_escape.h" #include "base/json/string_escape.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_piece.h" #include "base/memory/ref_counted_memory.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -18,15 +18,14 @@ ...@@ -18,15 +18,14 @@
namespace net { namespace net {
std::string GetDirectoryListingHeader(const base::string16& title) { std::string GetDirectoryListingHeader(const base::string16& title) {
static const base::StringPiece header( scoped_refptr<base::RefCountedMemory> header(
NetModule::GetResource(IDR_DIR_HEADER_HTML)); NetModule::GetResource(IDR_DIR_HEADER_HTML));
// This can be null in unit tests. // This can be null in unit tests.
DLOG_IF(WARNING, header.empty()) DLOG_IF(WARNING, !header) << "Missing resource: directory listing header";
<< "Missing resource: directory listing header";
std::string result; std::string result;
if (!header.empty()) if (header)
result.assign(header.data(), header.size()); result.assign(header->front_as<char>(), header->size());
result.append("<script>start("); result.append("<script>start(");
base::EscapeJSONString(title, true, &result); base::EscapeJSONString(title, true, &result);
......
...@@ -14,8 +14,8 @@ void NetModule::SetResourceProvider(ResourceProvider func) { ...@@ -14,8 +14,8 @@ void NetModule::SetResourceProvider(ResourceProvider func) {
} }
// static // static
base::StringPiece NetModule::GetResource(int key) { scoped_refptr<base::RefCountedMemory> NetModule::GetResource(int key) {
return resource_provider ? resource_provider(key) : base::StringPiece(); return resource_provider ? resource_provider(key) : nullptr;
} }
} // namespace net } // namespace net
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define NET_BASE_NET_MODULE_H__ #define NET_BASE_NET_MODULE_H__
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_piece.h" #include "base/memory/ref_counted_memory.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
namespace net { namespace net {
...@@ -20,15 +20,15 @@ namespace net { ...@@ -20,15 +20,15 @@ namespace net {
// //
class NET_EXPORT NetModule { class NET_EXPORT NetModule {
public: public:
typedef base::StringPiece (*ResourceProvider)(int key); typedef scoped_refptr<base::RefCountedMemory> (*ResourceProvider)(int key);
// Set the function to call when the net module needs resources // Set the function to call when the net module needs resources
static void SetResourceProvider(ResourceProvider func); static void SetResourceProvider(ResourceProvider func);
// Call the resource provider (if one exists) to get the specified resource. // Call the resource provider (if one exists) to get the specified resource.
// Returns an empty string if the resource does not exist or if there is no // Returns nullptr if the resource does not exist or if there is no resource
// resource provider. // provider.
static base::StringPiece GetResource(int key); static scoped_refptr<base::RefCountedMemory> GetResource(int key);
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(NetModule); DISALLOW_IMPLICIT_CONSTRUCTORS(NetModule);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<translations /> <translations />
<release seq="1"> <release seq="1">
<includes> <includes>
<include name="IDR_DIR_HEADER_HTML" file="dir_header.html" type="BINDATA" /> <include name="IDR_DIR_HEADER_HTML" file="dir_header.html" type="BINDATA" compress="gzip" />
</includes> </includes>
</release> </release>
</grit> </grit>
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