Skip to content

Commit

Permalink
Display final filter list for URLRequests in net-internals output.
Browse files Browse the repository at this point in the history
BUG=None
R=bnc@chromium.org
R=mmenke@chromium.org

Review URL: https://codereview.chromium.org/732253003

Cr-Commit-Position: refs/heads/master@{#304663}
  • Loading branch information
rdsmith authored and Commit bot committed Nov 18, 2014
1 parent cc5d84f commit 10be006
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 12 deletions.
8 changes: 8 additions & 0 deletions net/base/net_log_event_type_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,14 @@ EVENT_TYPE(URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED)
// "headers": <The list of header:value pairs>,
// }

EVENT_TYPE(URL_REQUEST_FILTERS_SET)
// This event is logged when a URLRequestJob sets up the filters, if any
// filters were added to the job. It logs the filters added.
// The following parameters are attached:
// {
// "filters": <The list of filter names>
// }

// ------------------------------------------------------------------------
// HttpCache
// ------------------------------------------------------------------------
Expand Down
36 changes: 32 additions & 4 deletions net/filter/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ void LogSdchProblem(const FilterContext& filter_context,
base::Bind(&NetLogSdchResourceProblemCallback, problem));
}

std::string FilterTypeAsString(Filter::FilterType type_id) {
switch (type_id) {
case Filter::FILTER_TYPE_DEFLATE:
return "FILTER_TYPE_DEFLATE";
case Filter::FILTER_TYPE_GZIP:
return "FILTER_TYPE_GZIP";
case Filter::FILTER_TYPE_GZIP_HELPING_SDCH:
return "FILTER_TYPE_GZIP_HELPING_SDCH";
case Filter::FILTER_TYPE_SDCH:
return "FILTER_TYPE_SDCH";
case Filter::FILTER_TYPE_SDCH_POSSIBLE :
return "FILTER_TYPE_SDCH_POSSIBLE ";
case Filter::FILTER_TYPE_UNSUPPORTED:
return "FILTER_TYPE_UNSUPPORTED";
}
return "";
}

} // namespace

FilterContext::~FilterContext() {
Expand Down Expand Up @@ -340,12 +358,22 @@ void Filter::FixupEncodingTypes(
return;
}

Filter::Filter()
std::string Filter::OrderedFilterList() const {
if (next_filter_) {
return FilterTypeAsString(type_id_) + "," +
next_filter_->OrderedFilterList();
} else {
return FilterTypeAsString(type_id_);
}
}

Filter::Filter(FilterType type_id)
: stream_buffer_(NULL),
stream_buffer_size_(0),
next_stream_data_(NULL),
stream_data_len_(0),
last_status_(FILTER_NEED_MORE_DATA) {}
last_status_(FILTER_NEED_MORE_DATA),
type_id_(type_id) {}

Filter::FilterStatus Filter::CopyOut(char* dest_buffer, int* dest_len) {
int out_len;
Expand All @@ -370,7 +398,7 @@ Filter::FilterStatus Filter::CopyOut(char* dest_buffer, int* dest_len) {

// static
Filter* Filter::InitGZipFilter(FilterType type_id, int buffer_size) {
scoped_ptr<GZipFilter> gz_filter(new GZipFilter());
scoped_ptr<GZipFilter> gz_filter(new GZipFilter(type_id));
gz_filter->InitBuffer(buffer_size);
return gz_filter->InitDecoding(type_id) ? gz_filter.release() : NULL;
}
Expand All @@ -379,7 +407,7 @@ Filter* Filter::InitGZipFilter(FilterType type_id, int buffer_size) {
Filter* Filter::InitSdchFilter(FilterType type_id,
const FilterContext& filter_context,
int buffer_size) {
scoped_ptr<SdchFilter> sdch_filter(new SdchFilter(filter_context));
scoped_ptr<SdchFilter> sdch_filter(new SdchFilter(type_id, filter_context));
sdch_filter->InitBuffer(buffer_size);
return sdch_filter->InitDecoding(type_id) ? sdch_filter.release() : NULL;
}
Expand Down
9 changes: 8 additions & 1 deletion net/filter/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ class NET_EXPORT_PRIVATE Filter {
static void FixupEncodingTypes(const FilterContext& filter_context,
std::vector<FilterType>* encoding_types);

// Returns a string describing the FilterTypes implemented by this filter.
std::string OrderedFilterList() const;

protected:
friend class GZipUnitTest;
friend class SdchFilterChainingTest;
FRIEND_TEST_ALL_PREFIXES(FilterTest, ThreeFilterChain);

Filter();
explicit Filter(FilterType type_id);

// Filters the data stored in stream_buffer_ and writes the output into the
// dest_buffer passed in.
Expand Down Expand Up @@ -294,10 +297,14 @@ class NET_EXPORT_PRIVATE Filter {

// An optional filter to process output from this filter.
scoped_ptr<Filter> next_filter_;

// Remember what status or local filter last returned so we can better handle
// chained filters.
FilterStatus last_status_;

// The filter type this filter was constructed from.
FilterType type_id_;

DISALLOW_COPY_AND_ASSIGN(Filter);
};

Expand Down
2 changes: 1 addition & 1 deletion net/filter/filter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace {

class PassThroughFilter : public Filter {
public:
PassThroughFilter() {}
PassThroughFilter() : Filter(FILTER_TYPE_UNSUPPORTED) {}

FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len) override {
return CopyOut(dest_buffer, dest_len);
Expand Down
5 changes: 3 additions & 2 deletions net/filter/gzip_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace net {

GZipFilter::GZipFilter()
: decoding_status_(DECODING_UNINITIALIZED),
GZipFilter::GZipFilter(FilterType type)
: Filter(type),
decoding_status_(DECODING_UNINITIALIZED),
decoding_mode_(DECODE_MODE_UNKNOWN),
gzip_header_status_(GZIP_CHECK_HEADER_IN_PROGRESS),
zlib_header_added_(false),
Expand Down
2 changes: 1 addition & 1 deletion net/filter/gzip_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GZipFilter : public Filter {
static const int kGZipFooterSize = 8;

// Only to be instantiated by Filter::Factory.
GZipFilter();
GZipFilter(FilterType type);
friend class Filter;

// Parses and verifies the GZip header.
Expand Down
5 changes: 3 additions & 2 deletions net/filter/sdch_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ base::Value* NetLogSdchResponseCorruptionDetectionCallback(

} // namespace

SdchFilter::SdchFilter(const FilterContext& filter_context)
: filter_context_(filter_context),
SdchFilter::SdchFilter(FilterType type, const FilterContext& filter_context)
: Filter(type),
filter_context_(filter_context),
decoding_status_(DECODING_UNINITIALIZED),
dictionary_hash_(),
dictionary_hash_is_plausible_(false),
Expand Down
2 changes: 1 addition & 1 deletion net/filter/sdch_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NET_EXPORT_PRIVATE SdchFilter : public Filter {
};

// Only to be instantiated by Filter::Factory.
explicit SdchFilter(const FilterContext& filter_context);
SdchFilter(FilterType type, const FilterContext& filter_context);
friend class Filter;

// Identify the suggested dictionary, and initialize underlying decompressor.
Expand Down
17 changes: 17 additions & 0 deletions net/url_request/url_request_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/profiler/scoped_tracker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "net/base/auth.h"
#include "net/base/host_port_pair.h"
#include "net/base/io_buffer.h"
Expand All @@ -21,6 +22,18 @@
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"

namespace {

// Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event.
base::Value* FiltersSetCallback(net::Filter* filter,
enum net::NetLog::LogLevel /* log_level */) {
base::DictionaryValue* event_params = new base::DictionaryValue();
event_params->SetString("filters", filter->OrderedFilterList());
return event_params;
}

} // namespace

namespace net {

URLRequestJob::URLRequestJob(URLRequest* request,
Expand Down Expand Up @@ -424,6 +437,10 @@ void URLRequestJob::NotifyHeadersComplete() {
request_->GetResponseHeaderByName("content-length", &content_length);
if (!content_length.empty())
base::StringToInt64(content_length, &expected_content_size_);
} else {
request_->net_log().AddEvent(
NetLog::TYPE_URL_REQUEST_FILTERS_SET,
base::Bind(&FiltersSetCallback, base::Unretained(filter_.get())));
}

// TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
Expand Down

0 comments on commit 10be006

Please sign in to comment.