Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: net/filter/stream_source.cc

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/filter/stream_source.h"
6
7 #include "base/strings/string_util.h"
8 #include "net/filter/brotli_stream_source.h"
9 #include "net/filter/gzip_stream_source.h"
10 #include "net/filter/sdch_stream_source.h"
11
12 namespace {
13
14 const char kDeflate[] = "deflate";
15 const char kGZip[] = "gzip";
16 const char kSdch[] = "sdch";
17 const char kXGZip[] = "x-gzip";
18 const char kBrotli[] = "br";
19
20 enum SourceType {
21 SOURCE_BROTLI,
22 SOURCE_DEFLATE,
23 SOURCE_GZIP,
24 SOURCE_SDCH,
25 SOURCE_GZIP_FALLBACK,
26 SOURCE_INVALID,
27 };
28
29 std::vector<SourceType> SourceTypeNamesToTypes(
30 const std::vector<std::string>& types) {
31 std::vector<SourceType> result;
32 for (const auto& type : types) {
33 if (base::LowerCaseEqualsASCII(type, kBrotli)) {
34 result.push_back(SOURCE_BROTLI);
35 } else if (base::LowerCaseEqualsASCII(type, kDeflate)) {
36 result.push_back(SOURCE_DEFLATE);
37 } else if (base::LowerCaseEqualsASCII(type, kGZip) ||
38 base::LowerCaseEqualsASCII(type, kXGZip)) {
39 result.push_back(SOURCE_GZIP);
40 } else if (base::LowerCaseEqualsASCII(type, kSdch)) {
41 result.push_back(SOURCE_SDCH);
42 }
43 }
44 return result;
45 }
46
47 scoped_ptr<net::StreamSource> BuildSource(
48 scoped_ptr<net::StreamSource> current,
49 SourceType type,
50 net::SdchStreamSourceDelegate* delegate) {
51 if (type == SOURCE_BROTLI) {
52 scoped_ptr<net::BrotliStreamSource> next(
53 new net::BrotliStreamSource(std::move(current)));
54 current = std::move(next);
55 } else if (type == SOURCE_SDCH) {
56 scoped_ptr<net::SdchStreamSource> next(
57 new net::SdchStreamSource(std::move(current), delegate));
58 if (next->Init())
59 current = std::move(next);
60 } else if (type == SOURCE_GZIP || type == SOURCE_DEFLATE ||
61 type == SOURCE_GZIP_FALLBACK) {
62 scoped_ptr<net::GzipStreamSource> next(
63 new net::GzipStreamSource(std::move(current)));
64 net::GzipStreamSource::GzipStreamSourceMode mode =
65 type == SOURCE_DEFLATE
66 ? net::GzipStreamSource::GZIP_STREAM_SOURCE_DEFLATE
67 : net::GzipStreamSource::GZIP_STREAM_SOURCE_GZIP;
68 bool fallback = type == SOURCE_GZIP_FALLBACK;
69 if (next->Init(mode, fallback))
70 current = std::move(next);
71 }
72 return current;
73 }
74
75 } // namespace
76
77 namespace net {
78
79 scoped_ptr<StreamSource> StreamSource::BuildSourceChain(
80 scoped_ptr<StreamSource> current,
81 const std::vector<std::string>& type_names,
82 SdchStreamSourceDelegate* sdch_delegate) {
83 std::vector<SourceType> types = SourceTypeNamesToTypes(type_names);
84
85 // SDCH-specific hack: if the first filter is SDCH, add a gzip filter in front
86 // of it in fallback mode.
87 if (!types.empty() && types.at(0) == SOURCE_SDCH)
88 types.insert(types.begin(), SOURCE_GZIP_FALLBACK);
89
90 for (const auto& type : types)
91 current = BuildSource(std::move(current), type, sdch_delegate);
mmenke 2016/02/18 22:58:28 if current ever ends up null after a BuildSource c
xunjieli 2016/03/03 23:00:09 Done.
Randy Smith (Not in Mondays) 2016/03/03 23:05:48 I've managed to lose track of the debate as to wha
92
93 return current;
94 }
95
96 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698