OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 DataReductionProxyNetworkDelegate::SessionNetworkStatsInfoToValue() const { | 146 DataReductionProxyNetworkDelegate::SessionNetworkStatsInfoToValue() const { |
147 base::DictionaryValue* dict = new base::DictionaryValue(); | 147 base::DictionaryValue* dict = new base::DictionaryValue(); |
148 // Use strings to avoid overflow. base::Value only supports 32-bit integers. | 148 // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
149 dict->SetString("session_received_content_length", | 149 dict->SetString("session_received_content_length", |
150 base::Int64ToString(total_received_bytes_)); | 150 base::Int64ToString(total_received_bytes_)); |
151 dict->SetString("session_original_content_length", | 151 dict->SetString("session_original_content_length", |
152 base::Int64ToString(total_original_received_bytes_)); | 152 base::Int64ToString(total_original_received_bytes_)); |
153 return dict; | 153 return dict; |
154 } | 154 } |
155 | 155 |
| 156 void DataReductionProxyNetworkDelegate::OnBeforeURLRequestInternal( |
| 157 net::URLRequest* request, |
| 158 const net::CompletionCallback& callback, |
| 159 GURL* new_url) { |
| 160 // |data_reduction_proxy_io_data_| can be NULL for Webview. |
| 161 if (data_reduction_proxy_io_data_ && |
| 162 (request->load_flags() & net::LOAD_MAIN_FRAME)) { |
| 163 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame(false); |
| 164 } |
| 165 } |
| 166 |
156 void DataReductionProxyNetworkDelegate::OnBeforeSendProxyHeadersInternal( | 167 void DataReductionProxyNetworkDelegate::OnBeforeSendProxyHeadersInternal( |
157 net::URLRequest* request, | 168 net::URLRequest* request, |
158 const net::ProxyInfo& proxy_info, | 169 const net::ProxyInfo& proxy_info, |
159 net::HttpRequestHeaders* headers) { | 170 net::HttpRequestHeaders* headers) { |
160 DCHECK(data_reduction_proxy_config_); | 171 DCHECK(data_reduction_proxy_config_); |
161 | 172 |
162 if (proxy_info.is_empty()) | 173 if (proxy_info.is_empty()) |
163 return; | 174 return; |
| 175 if (!proxy_info.proxy_server().is_valid()) |
| 176 return; |
| 177 if (proxy_info.proxy_server().is_direct()) |
| 178 return; |
| 179 if (proxy_info.proxy_server().host_port_pair().IsEmpty()) |
| 180 return; |
| 181 if (!data_reduction_proxy_config_->IsDataReductionProxy( |
| 182 proxy_info.proxy_server().host_port_pair(), nullptr)) { |
| 183 return; |
| 184 } |
164 | 185 |
165 if (data_reduction_proxy_io_data_ && | 186 if (data_reduction_proxy_io_data_ && |
166 data_reduction_proxy_io_data_->lofi_decider() && request) { | 187 data_reduction_proxy_io_data_->lofi_decider() && request) { |
167 LoFiDecider* lofi_decider = data_reduction_proxy_io_data_->lofi_decider(); | 188 LoFiDecider* lofi_decider = data_reduction_proxy_io_data_->lofi_decider(); |
168 bool is_using_lofi_mode = lofi_decider->MaybeAddLoFiDirectiveToHeaders( | 189 bool is_using_lofi_mode = |
169 *request, headers, proxy_info.proxy_server(), | 190 lofi_decider->MaybeAddLoFiDirectiveToHeaders(*request, headers); |
170 data_reduction_proxy_config_); | |
171 | 191 |
172 if ((request->load_flags() & net::LOAD_MAIN_FRAME)) { | 192 if ((request->load_flags() & net::LOAD_MAIN_FRAME)) { |
173 // TODO(megjablon): Need to switch to per page. | |
174 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( | 193 data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame( |
175 is_using_lofi_mode); | 194 is_using_lofi_mode); |
176 } | 195 } |
177 } | 196 } |
178 | 197 |
179 if (data_reduction_proxy_request_options_) { | 198 if (data_reduction_proxy_request_options_) { |
180 data_reduction_proxy_request_options_->MaybeAddRequestHeader( | 199 data_reduction_proxy_request_options_->AddRequestHeader(headers); |
181 proxy_info.proxy_server(), headers); | |
182 } | 200 } |
183 } | 201 } |
184 | 202 |
185 void DataReductionProxyNetworkDelegate::OnCompletedInternal( | 203 void DataReductionProxyNetworkDelegate::OnCompletedInternal( |
186 net::URLRequest* request, | 204 net::URLRequest* request, |
187 bool started) { | 205 bool started) { |
188 DCHECK(request); | 206 DCHECK(request); |
189 if (data_reduction_proxy_bypass_stats_) | 207 if (data_reduction_proxy_bypass_stats_) |
190 data_reduction_proxy_bypass_stats_->OnUrlRequestCompleted(request, started); | 208 data_reduction_proxy_bypass_stats_->OnUrlRequestCompleted(request, started); |
191 | 209 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 332 } |
315 } | 333 } |
316 | 334 |
317 void DataReductionProxyNetworkDelegate::RecordLoFiTransformationType( | 335 void DataReductionProxyNetworkDelegate::RecordLoFiTransformationType( |
318 LoFiTransformationType type) { | 336 LoFiTransformationType type) { |
319 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.LoFi.TransformationType", type, | 337 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.LoFi.TransformationType", type, |
320 LO_FI_TRANSFORMATION_TYPES_INDEX_BOUNDARY); | 338 LO_FI_TRANSFORMATION_TYPES_INDEX_BOUNDARY); |
321 } | 339 } |
322 | 340 |
323 } // namespace data_reduction_proxy | 341 } // namespace data_reduction_proxy |
OLD | NEW |