Commit 277f819d authored by Jacques Chen's avatar Jacques Chen Committed by Commit Bot

Make use of grit's brotli support for brotli-compressed protocol.json

-Change protocol.json to be Brotli compressed by grit
-Have protocol.json be decompressed by GetDataResourceBytes
-Remove brotli.gni that is no longer used

Bug: 826858
Change-Id: I2c49715f85508f494a57d65b09ada446c2efefec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728183
Commit-Queue: Sam Maier <smaier@chromium.org>
Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarJoel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarKunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690865}
parent d51976bb
......@@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/brotli/brotli.gni")
import("//third_party/inspector_protocol/inspector_protocol.gni")
import("//third_party/protobuf/proto_library.gni")
import("//tools/grit/grit_rule.gni")
......@@ -15,21 +14,10 @@ group("resources") {
}
}
compressed_protocol_file =
"$root_gen_dir/third_party/blink/renderer/core/inspector/protocol.json.bro"
compress_file_brotli("compressed_protocol_json") {
input_file =
"$root_gen_dir/third_party/blink/renderer/core/inspector/protocol.json"
output_file = compressed_protocol_file
deps = [
"//third_party/blink/renderer/core/inspector:protocol_version",
]
}
grit("devtools_resources") {
source = "$root_gen_dir/devtools/devtools_resources.grd"
source_is_generated = true
use_brotli = true
outputs = [
"grit/devtools_resources.h",
......@@ -40,15 +28,16 @@ grit("devtools_resources") {
grit_flags = [
"-E",
"compressed_protocol_file=" +
rebase_path(compressed_protocol_file, root_build_dir),
"protocol_file=" + rebase_path(
"$root_gen_dir/third_party/blink/renderer/core/inspector/protocol.json",
root_build_dir),
]
defines =
[ "SHARED_INTERMEDIATE_DIR=" + rebase_path(root_gen_dir, root_build_dir) ]
deps = [
":compressed_protocol_json",
"//third_party/blink/renderer/core/inspector:protocol_version",
# This is the action that generates out .grd input file.
"//third_party/blink/public:blink_generate_devtools_grd",
......
include_rules = [
"+third_party/brotli", # For compressed protocol.json.
"+content/shell/browser/shell.h", # for access to web contents from devtools_protocol_test_support.cc
# V8 version info
"+v8/include/v8-version-string.h",
......
......@@ -48,7 +48,6 @@
#include "net/server/http_server_response_info.h"
#include "net/socket/server_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "third_party/brotli/include/brotli/decode.h"
#include "v8/include/v8-version-string.h"
#if defined(OS_ANDROID)
......@@ -657,36 +656,10 @@ void DevToolsHttpHandler::DecompressAndSendJsonProtocol(int connection_id) {
#if defined(OS_FUCHSIA)
NOTREACHED();
#else
scoped_refptr<base::RefCountedMemory> raw_bytes =
scoped_refptr<base::RefCountedMemory> bytes =
GetContentClient()->GetDataResourceBytes(COMPRESSED_PROTOCOL_JSON);
const uint8_t* next_encoded_byte = raw_bytes->front();
size_t input_size_remaining = raw_bytes->size();
BrotliDecoderState* decoder = BrotliDecoderCreateInstance(
nullptr /* no custom allocator */, nullptr /* no custom deallocator */,
nullptr /* no custom memory handle */);
CHECK(!!decoder);
std::vector<std::string> decoded_parts;
size_t decompressed_size = 0;
while (!BrotliDecoderIsFinished(decoder)) {
size_t output_size_remaining = 0;
CHECK(BrotliDecoderDecompressStream(
decoder, &input_size_remaining, &next_encoded_byte,
&output_size_remaining, nullptr,
nullptr) != BROTLI_DECODER_RESULT_ERROR);
const uint8_t* output_buffer =
BrotliDecoderTakeOutput(decoder, &output_size_remaining);
decoded_parts.emplace_back(reinterpret_cast<const char*>(output_buffer),
output_size_remaining);
decompressed_size += output_size_remaining;
}
BrotliDecoderDestroyInstance(decoder);
// Ideally we'd use a StringBuilder here but there isn't one in base/.
std::string json_protocol;
json_protocol.reserve(decompressed_size);
for (const std::string& part : decoded_parts) {
json_protocol.append(part);
}
std::string json_protocol(reinterpret_cast<const char*>(bytes->front()),
bytes->size());
net::HttpServerResponseInfo response(net::HTTP_OK);
response.SetBody(json_protocol, "application/json; charset=UTF-8");
......
......@@ -54,7 +54,7 @@ kGrdTemplate = '''<?xml version="1.0" encoding="UTF-8"?>
</outputs>
<release seq="1">
<includes>
<include name="COMPRESSED_PROTOCOL_JSON" file="${compressed_protocol_file}" use_base_dir="false" type="BINDATA" skip_in_resource_map = "true"/>
<include name="COMPRESSED_PROTOCOL_JSON" file="${protocol_file}" use_base_dir="false" compress="brotli" type="BINDATA" skip_in_resource_map = "true"/>
</includes>
</release>
</grit>
......
......@@ -16,4 +16,3 @@ Local Modifications:
- Auxiliary fuzzer runners removed from fuzz/
- common/dictionary.bin*: Removed.
- BUILD.gn: Added.
- brotli.gni: Added.
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/compiled_action.gni")
# Compresses a file with brotli.
#
# Variables
# input_file: Path to input file.
# output_file: Path to output file.
#
template("compress_file_brotli") {
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
tool = "//third_party/brotli:brotli"
inputs = [
invoker.input_file,
]
outputs = [
invoker.output_file,
]
args = [
"--force",
"--no-copy-stat",
rebase_path(invoker.input_file, root_build_dir),
"-o",
rebase_path(invoker.output_file, root_build_dir),
]
}
}
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