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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_params.cc

Issue 286013002: Added alternative configuration for the data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h "
10
11 using base::FieldTrialList;
12
13 namespace {
14 const char kEnabled[] = "Enabled";
15 }
16
17 namespace data_reduction_proxy {
18
19 // static
20 bool DataReductionProxyParams::IsIncludedInFieldTrial() {
21 return base::FieldTrialList::FindFullName(
22 "DataCompressionProxyRollout") == kEnabled;
23 }
24
25 // static
26 bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() {
27 return base::FieldTrialList::FindFullName(
28 "DataCompressionProxyAlternativeConfiguration") == kEnabled;
29 }
30
31 // static
32 bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() {
33 return FieldTrialList::FindFullName(
34 "DataCompressionProxyPromoVisibility") == kEnabled;
35 }
36
37 // static
38 bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() {
39 return IsIncludedInFieldTrial() &&
40 FieldTrialList::FindFullName(
41 "DataCompressionProxyPreconnectHints") == kEnabled;
42 }
43
44 // static
45 bool DataReductionProxyParams::IsKeySetOnCommandLine() {
46 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
47 return command_line.HasSwitch(
48 data_reduction_proxy::switches::kEnableDataReductionProxy);
49 }
50
51 DataReductionProxyParams::DataReductionProxyParams(bool allowed,
52 bool fallback_allowed,
53 bool alt_allowed,
54 bool promo_allowed)
55 : allowed_(allowed),
56 fallback_allowed_(fallback_allowed),
57 alt_allowed_(alt_allowed),
58 promo_allowed_(promo_allowed) {
59 DCHECK(Init(allowed, fallback_allowed, alt_allowed));
60 }
61
62 DataReductionProxyParams::~DataReductionProxyParams() {
63 }
64
65 DataReductionProxyParams::DataReductionProxyList
66 DataReductionProxyParams::GetAllowedProxies() const {
67 DataReductionProxyList list;
68 if (allowed_)
69 list.push_back(origin_);
70 if (allowed_ && fallback_allowed_)
71 list.push_back(fallback_origin_);
72 if (alt_allowed_) {
73 list.push_back(alt_origin_);
74 list.push_back(ssl_origin_);
75 }
76 if (alt_allowed_ && fallback_allowed_)
77 list.push_back(alt_fallback_origin_);
78 return list;
79 }
80
81 DataReductionProxyParams::DataReductionProxyParams(bool allowed,
82 bool fallback_allowed,
83 bool alt_allowed,
84 bool promo_allowed,
85 bool should_call_init)
86 : allowed_(allowed),
87 fallback_allowed_(fallback_allowed),
88 alt_allowed_(alt_allowed),
89 promo_allowed_(promo_allowed) {
90 if (should_call_init)
91 DCHECK(Init(allowed, fallback_allowed, alt_allowed));
92 }
93
94 bool DataReductionProxyParams::Init(
95 bool allowed, bool fallback_allowed, bool alt_allowed) {
96 InitWithoutChecks();
97 // Verify that all necessary params are set.
98 if (allowed) {
99 if (!origin_.is_valid()) {
100 DVLOG(1) << "Invalid data reduction proxy origin: " << origin_.spec();
101 return false;
102 }
103 }
104
105 if (allowed && fallback_allowed) {
106 if (!fallback_origin_.is_valid()) {
107 DVLOG(1) << "Invalid data reduction proxy fallback origin: "
108 << fallback_origin_.spec();
109 return false;
110 }
111 }
112
113 if (alt_allowed) {
114 if (!allowed) {
115 DVLOG(1) << "Alternative data reduction proxy configuration cannot "
116 << "be allowed if the regular configuration is not allowed";
117 return false;
118 }
119 if (!alt_origin_.is_valid()) {
120 DVLOG(1) << "Invalid alternative origin:" << alt_origin_.spec();
121 return false;
122 }
123 if (!ssl_origin_.is_valid()) {
124 DVLOG(1) << "Invalid ssl origin: " << ssl_origin_.spec();
125 return false;
126 }
127 }
128
129 if (alt_allowed && fallback_allowed) {
130 if (!alt_fallback_origin_.is_valid()) {
131 DVLOG(1) << "Invalid alternative fallback origin:"
132 << alt_fallback_origin_.spec();
133 return false;
134 }
135 }
136
137 if (!probe_url_.is_valid()) {
138 DVLOG(1) << "Invalid probe url: <null>";
139 return false;
140 }
141
142 if (allowed || alt_allowed) {
143 if (key_.empty()) {
144 DVLOG(1) << "Invalid key: <empty>";
145 return false;
146 }
147 }
148
149 if (fallback_allowed_ && !allowed_) {
150 DVLOG(1) << "The data reduction proxy fallback cannot be allowed if "
151 << "the data reduction proxy is not allowed";
152 return false;
153 }
154 if (promo_allowed_ && !allowed_) {
155 DVLOG(1) << "The data reduction proxy promo cannot be allowed if the "
156 << "data reduction proxy is not allowed";
157 return false;
158 }
159 return true;
160
161 }
162
163
164 void DataReductionProxyParams::InitWithoutChecks() {
165 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
166 std::string origin =
167 command_line.GetSwitchValueASCII(switches::kDataReductionProxyDev);
168 if (origin.empty())
169 origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy);
170 std::string fallback_origin =
171 command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback);
172 std::string ssl_origin =
173 command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy);
174 std::string alt_origin =
175 command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt);
176 std::string alt_fallback_origin = command_line.GetSwitchValueASCII(
177 switches::kDataReductionProxyAltFallback);
178 key_ = command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey);
179
180 bool configured_on_command_line =
181 !(origin.empty() && fallback_origin.empty() && ssl_origin.empty() &&
182 alt_origin.empty() && alt_fallback_origin.empty());
183
184
185 // Configuring the proxy on the command line overrides the values of
186 // |allowed_| and |alt_allowed_|.
187 if (configured_on_command_line)
188 allowed_ = true;
189 if (!(ssl_origin.empty() &&
190 alt_origin.empty() &&
191 alt_fallback_origin.empty()))
192 alt_allowed_ = true;
193
194 // Only use default key if non of the proxies are configured on the command
195 // line.
196 if (key_.empty() && !configured_on_command_line)
197 key_ = GetDefaultKey();
198
199 std::string probe_url = command_line.GetSwitchValueASCII(
200 switches::kDataReductionProxyProbeURL);
201
202 // Set from preprocessor constants those params that are not specified on the
203 // command line.
204 if (origin.empty())
205 origin = GetDefaultDevOrigin();
206 if (origin.empty())
207 origin = GetDefaultOrigin();
208 if (fallback_origin.empty())
209 fallback_origin = GetDefaultFallbackOrigin();
210 if (ssl_origin.empty())
211 ssl_origin = GetDefaultSSLOrigin();
212 if (alt_origin.empty())
213 alt_origin = GetDefaultAltOrigin();
214 if (alt_fallback_origin.empty())
215 alt_fallback_origin = GetDefaultAltFallbackOrigin();
216 if (probe_url.empty())
217 probe_url = GetDefaultProbeURL();
218
219 origin_ = GURL(origin);
220 fallback_origin_ = GURL(fallback_origin);
221 ssl_origin_ = GURL(ssl_origin);
222 alt_origin_ = GURL(alt_origin);
223 alt_fallback_origin_ = GURL(alt_fallback_origin);
224 probe_url_ = GURL(probe_url);
225
226 }
227
228 std::string DataReductionProxyParams::GetDefaultKey() const {
229 #if defined(SPDY_PROXY_AUTH_VALUE)
230 return SPDY_PROXY_AUTH_VALUE;
231 #endif
232 return std::string();
233 }
234
235 std::string DataReductionProxyParams::GetDefaultDevOrigin() const {
236 #if defined(DATA_REDUCTION_DEV_HOST)
237 if (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") ==
238 kEnabled) {
239 return DATA_REDUCTION_DEV_HOST;
240 }
241 #endif
242 return std::string();
243 }
244
245 std::string DataReductionProxyParams::GetDefaultOrigin() const {
246 #if defined(SPDY_PROXY_AUTH_ORIGIN)
247 return SPDY_PROXY_AUTH_ORIGIN;
248 #endif
249 return std::string();
250 }
251
252 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const {
253 #if defined(DATA_REDUCTION_FALLBACK_HOST)
254 return DATA_REDUCTION_FALLBACK_HOST;
255 #endif
256 return std::string();
257 }
258
259 std::string DataReductionProxyParams::GetDefaultSSLOrigin() const {
260 #if defined(DATA_REDUCTION_PROXY_SSL_ORIGIN)
261 return DATA_REDUCTION_PROXY_SSL_ORIGIN;
262 #endif
263 return std::string();
264 }
265
266 std::string DataReductionProxyParams::GetDefaultAltOrigin() const {
267 #if defined(DATA_REDUCTION_PROXY_ALT_ORIGIN)
268 return DATA_REDUCTION_PROXY_ALT_ORIGIN;
269 #endif
270 return std::string();
271 }
272
273 std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const {
274 #if defined(DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN)
275 return DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN;
276 #endif
277 return std::string();
278 }
279
280 std::string DataReductionProxyParams::GetDefaultProbeURL() const {
281 #if defined(DATA_REDUCTION_PROXY_PROBE_URL)
282 return DATA_REDUCTION_PROXY_PROBE_URL;
283 #endif
284 return std::string();
285 }
286
287 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698