summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorgabadie <gabadie@chromium.org>2016-03-23 05:00:29 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-23 12:02:14 +0000
commit6222f26699b65e93e52e69934422be34e2f4ec1e (patch)
tree3f83bc8c47a4467f84d90235b7423b4031cf1ca5 /net
parentbccaa6b939b3daed06d54bd99ffb1c9e24e5a8b4 (diff)
downloadchromium_src-6222f26699b65e93e52e69934422be34e2f4ec1e.zip
chromium_src-6222f26699b65e93e52e69934422be34e2f4ec1e.tar.gz
chromium_src-6222f26699b65e93e52e69934422be34e2f4ec1e.tar.bz2
Reland of "Implements content_decoder_tool.cc to decode offline any resources."
TBR=gavinp@chromium.org BUG=582080 > Revert of Implement content_decoder_tool.cc to decode offline any resources. (patchset #4 id:60001 of https://codereview.chromium.org/1767653002/ ) > > Reason for revert: > Broke iOS build: https://build.chromium.org/p/chromium.mac/builders/iOS_Device/builds/44002 > > Original issue's description: > > Implement content_decoder_tool.cc to decode offline any resources. > > > > Sandwich is going to use the HTMLPreloadScanner to get all the > > resources to prefetch instead of using the Clovis' dependency > > graph. However resources in the chrome HTTP cache or in the WPR > > archive are stored as transport layer content, implying that they > > might be stored using a compression algorithm, according to the > > Content-Encoding response header. > > > > This tools enable us to decode any resources using the same very > > code path used in chrome, implying that we will be able to > > uncompressed absolutely all resources that chrome can and is > > advertising in its Accept-Encoding request header. > > > > BUG=582080 > > > > Committed: https://crrev.com/4dc1dc6668a87620574dd43392046c3691914da2 > > Cr-Commit-Position: refs/heads/master@{#382599} Review URL: https://codereview.chromium.org/1831433002 Cr-Commit-Position: refs/heads/master@{#382831}
Diffstat (limited to 'net')
-rw-r--r--net/net.gyp16
-rw-r--r--net/tools/content_decoder_tool/content_decoder_tool.cc83
2 files changed, 99 insertions, 0 deletions
diff --git a/net/net.gyp b/net/net.gyp
index 661a019..c50c4f6 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1691,6 +1691,22 @@
},
],
}],
+ ['OS == "linux"', {
+ 'targets': [
+ {
+ 'target_name': 'content_decoder_tool',
+ 'type': 'executable',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'net',
+ ],
+ 'sources': [
+ 'tools/content_decoder_tool/content_decoder_tool.cc',
+ 'filter/mock_filter_context.cc',
+ ],
+ }
+ ],
+ }],
['test_isolation_mode != "noop"', {
'targets': [
{
diff --git a/net/tools/content_decoder_tool/content_decoder_tool.cc b/net/tools/content_decoder_tool/content_decoder_tool.cc
new file mode 100644
index 0000000..0eae255
--- /dev/null
+++ b/net/tools/content_decoder_tool/content_decoder_tool.cc
@@ -0,0 +1,83 @@
+// 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.
+
+#include <iostream>
+
+#include "base/command_line.h"
+#include "net/base/io_buffer.h"
+#include "net/filter/filter.h"
+#include "net/filter/mock_filter_context.h"
+
+using net::Filter;
+
+namespace {
+
+// Print the command line help.
+void PrintHelp(const char* command_line_name) {
+ std::cout << command_line_name << " content_encoding [content_encoding]..."
+ << std::endl
+ << std::endl;
+ std::cout << "Decodes the stdin into the stdout using an content_encoding "
+ << "list given in arguments. This list is expected to be the "
+ << "Content-Encoding HTTP response header's value split by ','."
+ << std::endl;
+}
+
+} // namespace
+
+int main(int argc, char* argv[]) {
+ base::CommandLine::Init(argc, argv);
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+
+ std::vector<std::string> content_encodings = command_line.GetArgs();
+ if (content_encodings.size() == 0) {
+ PrintHelp(argv[0]);
+ return 1;
+ }
+
+ std::vector<Filter::FilterType> filter_types;
+ for (const auto& content_encoding : content_encodings) {
+ Filter::FilterType filter_type =
+ Filter::ConvertEncodingToType(content_encoding);
+ if (filter_type == Filter::FILTER_TYPE_UNSUPPORTED) {
+ std::cerr << "Unsupported decoder '" << content_encoding << "'."
+ << std::endl;
+ return 1;
+ }
+ filter_types.push_back(filter_type);
+ }
+
+ net::MockFilterContext filter_context;
+ scoped_ptr<Filter> filter(Filter::Factory(filter_types, filter_context));
+ if (!filter) {
+ std::cerr << "Couldn't create the decoder." << std::endl;
+ return 1;
+ }
+
+ net::IOBuffer* pre_filter_buf = filter->stream_buffer();
+ int pre_filter_buf_len = filter->stream_buffer_size();
+ while (std::cin) {
+ std::cin.read(pre_filter_buf->data(), pre_filter_buf_len);
+ int pre_filter_data_len = std::cin.gcount();
+ filter->FlushStreamBuffer(pre_filter_data_len);
+
+ while (true) {
+ const int kPostFilterBufLen = 4096;
+ char post_filter_buf[kPostFilterBufLen];
+ int post_filter_data_len = kPostFilterBufLen;
+ Filter::FilterStatus filter_status =
+ filter->ReadData(post_filter_buf, &post_filter_data_len);
+ std::cout.write(post_filter_buf, post_filter_data_len);
+ if (filter_status == Filter::FILTER_ERROR) {
+ std::cerr << "Couldn't decode stdin." << std::endl;
+ return 1;
+ } else if (filter_status != Filter::FILTER_OK) {
+ break;
+ }
+ }
+ }
+
+ return 0;
+}