blob: 89bb50a277bb2a918abc0b815d27372a65bb312e [file] [log] [blame]
[email protected]9045b8822012-01-13 20:35:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ac039522010-06-15 16:39:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/net/chrome_network_delegate.h"
6
[email protected]eac11e12013-03-19 22:04:327#include <stdlib.h>
8
[email protected]d1208ba32012-11-08 11:10:339#include <vector>
10
[email protected]d8e4f132012-09-06 04:28:0511#include "base/base_paths.h"
[email protected]4aca5db2013-08-17 00:51:5612#include "base/debug/trace_event.h"
[email protected]7a299a92012-10-24 23:54:5013#include "base/logging.h"
14#include "base/metrics/histogram.h"
[email protected]d8e4f132012-09-06 04:28:0515#include "base/path_service.h"
[email protected]1ab137b2013-03-21 03:33:1816#include "base/prefs/pref_member.h"
[email protected]3853a4c2013-02-11 17:15:5717#include "base/prefs/pref_service.h"
[email protected]3ea1b182013-02-08 22:38:4118#include "base/strings/string_number_conversions.h"
[email protected]1988e1c2013-02-28 20:27:4219#include "base/strings/string_split.h"
[email protected]069c49162013-09-11 20:46:3520#include "base/time/time.h"
[email protected]6baff0b52012-03-06 01:30:1821#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3522#include "chrome/browser/content_settings/cookie_settings.h"
23#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5824#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1425#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]3620bbc2013-10-05 05:07:2326#include "chrome/browser/net/client_hints.h"
[email protected]f53b4802012-12-20 17:04:2327#include "chrome/browser/net/connect_interceptor.h"
[email protected]6f4b4b42012-08-27 21:59:0728#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]28c5d0b72014-05-13 08:19:5929#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]6baff0b52012-03-06 01:30:1830#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5831#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4032#include "chrome/common/pref_names.h"
[email protected]a1d4ab072012-06-07 13:21:1533#include "chrome/common/url_constants.h"
[email protected]a0a06932014-04-14 21:23:4234#include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
[email protected]d8fc4722014-06-13 13:17:1535#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
36#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
[email protected]45de676a2014-03-18 23:52:0237#include "components/domain_reliability/monitor.h"
[email protected]8e44a5b02014-06-19 19:03:2438#include "components/google/core/browser/google_util.h"
[email protected]c38831a12011-10-28 12:44:4939#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5640#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3341#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3542#include "content/public/browser/resource_request_info.h"
[email protected]885c0e92012-11-13 20:27:4243#include "extensions/common/constants.h"
[email protected]82b42302011-04-20 16:28:1644#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1445#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5946#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3447#include "net/cookies/canonical_cookie.h"
48#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4449#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1650#include "net/http/http_response_headers.h"
[email protected]aa28181e2012-06-13 00:53:5851#include "net/socket_stream/socket_stream.h"
[email protected]d05ef99c2011-02-01 21:38:1652#include "net/url_request/url_request.h"
[email protected]28c5d0b72014-05-13 08:19:5953#include "net/url_request/url_request_context.h"
[email protected]d05ef99c2011-02-01 21:38:1654
[email protected]4a2b6232014-06-19 08:44:1455#if defined(OS_ANDROID)
56#include "chrome/browser/io_thread.h"
57#include "components/precache/content/precache_manager.h"
58#include "components/precache/content/precache_manager_factory.h"
59#endif
60
[email protected]4c219e22012-05-05 19:41:0461#if defined(OS_CHROMEOS)
[email protected]288538482012-09-06 21:09:3562#include "base/command_line.h"
[email protected]49c4cf852013-09-27 19:28:2463#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3564#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0465#endif
66
[email protected]3e598ff12011-09-06 11:22:3467#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]f522afa2014-01-08 15:36:3668#include "components/policy/core/browser/url_blacklist_manager.h"
[email protected]3e598ff12011-09-06 11:22:3469#endif
70
[email protected]631bb742011-11-02 11:29:3971using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1172using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2573using content::ResourceRequestInfo;
[email protected]631bb742011-11-02 11:29:3974
[email protected]d8e4f132012-09-06 04:28:0575// By default we don't allow access to all file:// urls on ChromeOS and
76// Android.
77#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0478bool ChromeNetworkDelegate::g_allow_file_access_ = false;
79#else
80bool ChromeNetworkDelegate::g_allow_file_access_ = true;
81#endif
82
[email protected]c4a7df82012-08-09 22:48:4683// This remains false unless the --disable-extensions-http-throttling
84// flag is passed to the browser.
85bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
86
[email protected]d05ef99c2011-02-01 21:38:1687namespace {
88
[email protected]9d8cfb682012-09-13 16:48:0489const char kDNTHeader[] = "DNT";
90
[email protected]d1208ba32012-11-08 11:10:3391// Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
92// same key as the the |second_parameter| (e.g. foo=baz). Both parameters
93// must be in key=value form.
94bool HasSameParameterKey(const std::string& first_parameter,
95 const std::string& second_parameter) {
96 DCHECK(second_parameter.find("=") != std::string::npos);
97 // Prefix for "foo=bar" is "foo=".
98 std::string parameter_prefix = second_parameter.substr(
99 0, second_parameter.find("=") + 1);
100 return StartsWithASCII(first_parameter, parameter_prefix, false);
101}
102
103// Examines the query string containing parameters and adds the necessary ones
104// so that SafeSearch is active. |query| is the string to examine and the
105// return value is the |query| string modified such that SafeSearch is active.
106std::string AddSafeSearchParameters(const std::string& query) {
107 std::vector<std::string> new_parameters;
108 std::string safe_parameter = chrome::kSafeSearchSafeParameter;
109 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter;
110
111 std::vector<std::string> parameters;
112 base::SplitString(query, '&', &parameters);
113
114 std::vector<std::string>::iterator it;
115 for (it = parameters.begin(); it < parameters.end(); ++it) {
116 if (!HasSameParameterKey(*it, safe_parameter) &&
117 !HasSameParameterKey(*it, ssui_parameter)) {
118 new_parameters.push_back(*it);
119 }
120 }
121
122 new_parameters.push_back(safe_parameter);
123 new_parameters.push_back(ssui_parameter);
124 return JoinString(new_parameters, '&');
125}
126
127// If |request| is a request to Google Web Search the function
128// enforces that the SafeSearch query parameters are set to active.
129// Sets the query part of |new_url| with the new value of the parameters.
130void ForceGoogleSafeSearch(net::URLRequest* request,
131 GURL* new_url) {
[email protected]c02f79d2013-06-27 21:46:47132 if (!google_util::IsGoogleSearchUrl(request->url()) &&
133 !google_util::IsGoogleHomePageUrl(request->url()))
[email protected]d1208ba32012-11-08 11:10:33134 return;
135
136 std::string query = request->url().query();
137 std::string new_query = AddSafeSearchParameters(query);
138 if (query == new_query)
139 return;
140
141 GURL::Replacements replacements;
142 replacements.SetQueryStr(new_query);
143 *new_url = request->url().ReplaceComponents(replacements);
144}
145
146// Gets called when the extensions finish work on the URL. If the extensions
147// did not do a redirect (so |new_url| is empty) then we enforce the
148// SafeSearch parameters. Otherwise we will get called again after the
149// redirect and we enforce SafeSearch then.
150void ForceGoogleSafeSearchCallbackWrapper(
151 const net::CompletionCallback& callback,
152 net::URLRequest* request,
153 GURL* new_url,
154 int rv) {
155 if (rv == net::OK && new_url->is_empty())
156 ForceGoogleSafeSearch(request, new_url);
157 callback.Run(rv);
158}
159
[email protected]828eab22013-12-10 22:42:38160void UpdateContentLengthPrefs(
161 int received_content_length,
162 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42163 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34164 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
166 DCHECK_GE(received_content_length, 0);
167 DCHECK_GE(original_content_length, 0);
168
[email protected]a09159a2012-11-29 12:51:48169 // Can be NULL in a unit test.
170 if (!g_browser_process)
171 return;
172
[email protected]7a299a92012-10-24 23:54:50173 PrefService* prefs = g_browser_process->local_state();
[email protected]a09159a2012-11-29 12:51:48174 if (!prefs)
175 return;
[email protected]7a299a92012-10-24 23:54:50176
[email protected]b7796462013-12-12 19:42:34177 // Ignore off-the-record data.
178 if (!g_browser_process->profile_manager()->IsValidProfile(profile) ||
179 profile->IsOffTheRecord()) {
180 return;
181 }
[email protected]0d36d1e2013-09-24 04:25:28182#if defined(OS_ANDROID)
[email protected]b1d5ed52013-12-18 02:34:56183 // If Android ever goes multi profile, the profile should be passed so that
184 // the browser preference will be taken.
[email protected]0d36d1e2013-09-24 04:25:28185 bool with_data_reduction_proxy_enabled =
[email protected]b1d5ed52013-12-18 02:34:56186 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean(
[email protected]a0a06932014-04-14 21:23:42187 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
[email protected]0d36d1e2013-09-24 04:25:28188#else
189 bool with_data_reduction_proxy_enabled = false;
[email protected]eac11e12013-03-19 22:04:32190#endif
[email protected]0d36d1e2013-09-24 04:25:28191
[email protected]a0a06932014-04-14 21:23:42192 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length,
193 original_content_length,
194 with_data_reduction_proxy_enabled,
195 request_type, prefs);
[email protected]7a299a92012-10-24 23:54:50196}
197
[email protected]828eab22013-12-10 22:42:38198void StoreAccumulatedContentLength(
199 int received_content_length,
200 int original_content_length,
[email protected]a0a06932014-04-14 21:23:42201 data_reduction_proxy::DataReductionProxyRequestType request_type,
[email protected]b7796462013-12-12 19:42:34202 Profile* profile) {
[email protected]7a299a92012-10-24 23:54:50203 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
204 base::Bind(&UpdateContentLengthPrefs,
[email protected]2db93e42013-08-07 17:40:41205 received_content_length, original_content_length,
[email protected]a0a06932014-04-14 21:23:42206 request_type, profile));
[email protected]7a299a92012-10-24 23:54:50207}
208
209void RecordContentLengthHistograms(
[email protected]f81a5ee2013-06-20 21:08:49210 int64 received_content_length,
211 int64 original_content_length,
212 const base::TimeDelta& freshness_lifetime) {
[email protected]7a299a92012-10-24 23:54:50213 // Add the current resource to these histograms only when a valid
214 // X-Original-Content-Length header is present.
215 if (original_content_length >= 0) {
216 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL",
217 received_content_length);
218 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLengthWithValidOCL",
219 original_content_length);
220 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifferenceWithValidOCL",
221 original_content_length - received_content_length);
222 } else {
223 // Presume the original content length is the same as the received content
224 // length if the X-Original-Content-Header is not present.
225 original_content_length = received_content_length;
226 }
227 UMA_HISTOGRAM_COUNTS("Net.HttpContentLength", received_content_length);
228 UMA_HISTOGRAM_COUNTS("Net.HttpOriginalContentLength",
229 original_content_length);
230 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthDifference",
231 original_content_length - received_content_length);
[email protected]f81a5ee2013-06-20 21:08:49232 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.HttpContentFreshnessLifetime",
233 freshness_lifetime.InSeconds(),
234 base::TimeDelta::FromHours(1).InSeconds(),
235 base::TimeDelta::FromDays(30).InSeconds(),
236 100);
237 if (freshness_lifetime.InSeconds() <= 0)
238 return;
239 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable",
240 received_content_length);
241 if (freshness_lifetime.InHours() < 4)
242 return;
243 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable4Hours",
244 received_content_length);
245
246 if (freshness_lifetime.InHours() < 24)
247 return;
248 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthCacheable24Hours",
249 received_content_length);
[email protected]7a299a92012-10-24 23:54:50250}
251
[email protected]35558812013-12-18 21:58:36252#if defined(OS_ANDROID)
253void RecordPrecacheStatsOnUIThread(const GURL& url,
254 const base::Time& fetch_time, int64 size,
255 bool was_cached, void* profile_id) {
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
257
258 Profile* profile = reinterpret_cast<Profile*>(profile_id);
259 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) {
260 return;
261 }
262
263 precache::PrecacheManager* precache_manager =
264 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
265 if (!precache_manager) {
266 // This could be NULL if the profile is off the record.
267 return;
268 }
269
270 precache_manager->RecordStatsForFetch(url, fetch_time, size, was_cached);
271}
[email protected]d827e112014-03-31 17:45:05272
273void RecordIOThreadToRequestStartOnUIThread(
274 const base::TimeTicks& request_start) {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
276 base::TimeDelta request_lag = request_start -
277 g_browser_process->io_thread()->creation_time();
278 UMA_HISTOGRAM_TIMES("Net.IOThreadCreationToHTTPRequestStart", request_lag);
279}
[email protected]35558812013-12-18 21:58:36280#endif // defined(OS_ANDROID)
281
[email protected]d05ef99c2011-02-01 21:38:16282} // namespace
[email protected]ac039522010-06-15 16:39:44283
[email protected]0651b812011-02-24 00:22:50284ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10285 extensions::EventRouterForwarder* event_router,
[email protected]a09159a2012-11-29 12:51:48286 BooleanPrefMember* enable_referrers)
[email protected]4a2b6232014-06-19 08:44:14287 : profile_(NULL),
[email protected]6a5f77c32011-09-04 19:19:59288 enable_referrers_(enable_referrers),
[email protected]a09159a2012-11-29 12:51:48289 enable_do_not_track_(NULL),
290 force_google_safe_search_(NULL),
[email protected]4a2b6232014-06-19 08:44:14291#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]a09159a2012-11-29 12:51:48292 url_blacklist_manager_(NULL),
[email protected]4a2b6232014-06-19 08:44:14293#endif
[email protected]45de676a2014-03-18 23:52:02294 domain_reliability_monitor_(NULL),
[email protected]7a299a92012-10-24 23:54:50295 received_content_length_(0),
[email protected]d827e112014-03-31 17:45:05296 original_content_length_(0),
[email protected]28c5d0b72014-05-13 08:19:59297 first_request_(true),
[email protected]d8fc4722014-06-13 13:17:15298 prerender_tracker_(NULL),
299 data_reduction_proxy_params_(NULL) {
[email protected]0a8db0d2011-04-13 15:15:40300 DCHECK(enable_referrers);
[email protected]4a2b6232014-06-19 08:44:14301 extensions_delegate_.reset(
302 ChromeExtensionsNetworkDelegate::Create(event_router));
[email protected]0651b812011-02-24 00:22:50303}
304
[email protected]ac039522010-06-15 16:39:44305ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
306
[email protected]a09159a2012-11-29 12:51:48307void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20308 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14309 extensions_delegate_->set_extension_info_map(extension_info_map);
310}
311
312void ChromeNetworkDelegate::set_profile(void* profile) {
313 profile_ = profile;
314 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48315}
316
317void ChromeNetworkDelegate::set_cookie_settings(
318 CookieSettings* cookie_settings) {
319 cookie_settings_ = cookie_settings;
320}
321
[email protected]f53b4802012-12-20 17:04:23322void ChromeNetworkDelegate::set_predictor(
323 chrome_browser_net::Predictor* predictor) {
324 connect_interceptor_.reset(
325 new chrome_browser_net::ConnectInterceptor(predictor));
326}
327
[email protected]3620bbc2013-10-05 05:07:23328void ChromeNetworkDelegate::SetEnableClientHints() {
329 client_hints_.reset(new ClientHints());
330 client_hints_->Init();
331}
332
[email protected]c4a7df82012-08-09 22:48:46333// static
[email protected]a1d4ab072012-06-07 13:21:15334void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46335 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15336}
337
[email protected]0a8db0d2011-04-13 15:15:40338// static
[email protected]9d8cfb682012-09-13 16:48:04339void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]0a8db0d2011-04-13 15:15:40340 BooleanPrefMember* enable_referrers,
[email protected]9d8cfb682012-09-13 16:48:04341 BooleanPrefMember* enable_do_not_track,
[email protected]d1208ba32012-11-08 11:10:33342 BooleanPrefMember* force_google_safe_search,
[email protected]0a8db0d2011-04-13 15:15:40343 PrefService* pref_service) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]96a5c342012-12-04 18:14:02345 enable_referrers->Init(prefs::kEnableReferrers, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43346 enable_referrers->MoveToThread(
347 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04348 if (enable_do_not_track) {
[email protected]96a5c342012-12-04 18:14:02349 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service);
[email protected]6a1c98e02012-10-24 21:49:43350 enable_do_not_track->MoveToThread(
351 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]9d8cfb682012-09-13 16:48:04352 }
[email protected]d1208ba32012-11-08 11:10:33353 if (force_google_safe_search) {
[email protected]96a5c342012-12-04 18:14:02354 force_google_safe_search->Init(prefs::kForceSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33355 force_google_safe_search->MoveToThread(
356 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
357 }
[email protected]0a8db0d2011-04-13 15:15:40358}
359
[email protected]4c219e22012-05-05 19:41:04360// static
361void ChromeNetworkDelegate::AllowAccessToAllFiles() {
362 g_allow_file_access_ = true;
363}
364
[email protected]7a299a92012-10-24 23:54:50365// static
[email protected]cb1078de2013-12-23 20:04:22366base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() {
[email protected]7a299a92012-10-24 23:54:50367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
368 PrefService* prefs = g_browser_process->local_state();
[email protected]a0a06932014-04-14 21:23:42369 int64 total_received = prefs->GetInt64(
370 data_reduction_proxy::prefs::kHttpReceivedContentLength);
371 int64 total_original = prefs->GetInt64(
372 data_reduction_proxy::prefs::kHttpOriginalContentLength);
[email protected]7a299a92012-10-24 23:54:50373
[email protected]cb1078de2013-12-23 20:04:22374 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42375 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
376 dict->SetString("historic_received_content_length",
377 base::Int64ToString(total_received));
378 dict->SetString("historic_original_content_length",
379 base::Int64ToString(total_original));
[email protected]7a299a92012-10-24 23:54:50380 return dict;
381}
382
[email protected]cb1078de2013-12-23 20:04:22383base::Value* ChromeNetworkDelegate::SessionNetworkStatsInfoToValue() const {
384 base::DictionaryValue* dict = new base::DictionaryValue();
[email protected]ae638fbe22012-12-07 02:57:42385 // Use strings to avoid overflow. base::Value only supports 32-bit integers.
386 dict->SetString("session_received_content_length",
387 base::Int64ToString(received_content_length_));
388 dict->SetString("session_original_content_length",
389 base::Int64ToString(original_content_length_));
[email protected]7a299a92012-10-24 23:54:50390 return dict;
391}
392
[email protected]4875ba12011-03-30 22:31:51393int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12394 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47395 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12396 GURL* new_url) {
[email protected]d827e112014-03-31 17:45:05397#if defined(OS_ANDROID)
398 // This UMA tracks the time to the first user-initiated request start, so
399 // only non-null profiles are considered.
400 if (first_request_ && profile_) {
401 bool record_timing = true;
[email protected]bec6a992014-06-19 01:03:21402 if (data_reduction_proxy_params_) {
403 record_timing =
404 (request->url() != data_reduction_proxy_params_->probe_url()) &&
405 (request->url() != data_reduction_proxy_params_->warmup_url());
406 }
[email protected]d827e112014-03-31 17:45:05407 if (record_timing) {
408 first_request_ = false;
409 net::LoadTimingInfo timing_info;
410 request->GetLoadTimingInfo(&timing_info);
411 BrowserThread::PostTask(
412 BrowserThread::UI, FROM_HERE,
413 base::Bind(&RecordIOThreadToRequestStartOnUIThread,
414 timing_info.request_start));
415 }
416 }
417#endif // defined(OS_ANDROID)
418
[email protected]3e598ff12011-09-06 11:22:34419#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59420 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
421 // blocked. However, an extension might redirect the request to another URL,
422 // which is not blocked.
[email protected]cb85f8e52014-04-08 11:44:40423 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]6a5f77c32011-09-04 19:19:59424 if (url_blacklist_manager_ &&
[email protected]cb85f8e52014-04-08 11:44:40425 url_blacklist_manager_->IsRequestBlocked(*request, &error)) {
[email protected]6a5f77c32011-09-04 19:19:59426 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59427 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26428 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
429 net::NetLog::StringCallback("url",
430 &request->url().possibly_invalid_spec()));
[email protected]cb85f8e52014-04-08 11:44:40431 return error;
[email protected]6a5f77c32011-09-04 19:19:59432 }
[email protected]3e598ff12011-09-06 11:22:34433#endif
[email protected]6a5f77c32011-09-04 19:19:59434
[email protected]4a2b6232014-06-19 08:44:14435 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18436
[email protected]0a8db0d2011-04-13 15:15:40437 if (!enable_referrers_->GetValue())
[email protected]99ecf6e2013-04-10 22:46:13438 request->SetReferrer(std::string());
[email protected]9d8cfb682012-09-13 16:48:04439 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
440 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
[email protected]d1208ba32012-11-08 11:10:33441
[email protected]3620bbc2013-10-05 05:07:23442 if (client_hints_) {
443 request->SetExtraRequestHeaderByName(
444 ClientHints::kDevicePixelRatioHeader,
445 client_hints_->GetDevicePixelRatioHeader(), true);
446 }
447
[email protected]d1208ba32012-11-08 11:10:33448 bool force_safe_search = force_google_safe_search_ &&
449 force_google_safe_search_->GetValue();
450
451 net::CompletionCallback wrapped_callback = callback;
452 if (force_safe_search) {
453 wrapped_callback = base::Bind(&ForceGoogleSafeSearchCallbackWrapper,
454 callback,
455 base::Unretained(request),
456 base::Unretained(new_url));
457 }
458
[email protected]4a2b6232014-06-19 08:44:14459 int rv = extensions_delegate_->OnBeforeURLRequest(
460 request, wrapped_callback, new_url);
[email protected]d1208ba32012-11-08 11:10:33461
462 if (force_safe_search && rv == net::OK && new_url->is_empty())
463 ForceGoogleSafeSearch(request, new_url);
464
[email protected]f53b4802012-12-20 17:04:23465 if (connect_interceptor_)
466 connect_interceptor_->WitnessURLRequest(request);
467
[email protected]d1208ba32012-11-08 11:10:33468 return rv;
[email protected]d05ef99c2011-02-01 21:38:16469}
470
[email protected]4875ba12011-03-30 22:31:51471int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01472 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47473 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12474 net::HttpRequestHeaders* headers) {
[email protected]186468f2013-10-24 02:44:11475 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
[email protected]4a2b6232014-06-19 08:44:14476 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
[email protected]ac039522010-06-15 16:39:44477}
[email protected]8202d0c2011-02-23 08:31:14478
[email protected]5796dc942011-07-14 19:26:10479void ChromeNetworkDelegate::OnSendHeaders(
480 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15481 const net::HttpRequestHeaders& headers) {
[email protected]4a2b6232014-06-19 08:44:14482 extensions_delegate_->OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:16483}
484
[email protected]ea8141e2011-10-05 13:12:51485int ChromeNetworkDelegate::OnHeadersReceived(
486 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47487 const net::CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:32488 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16489 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
490 GURL* allowed_unsafe_redirect_url) {
[email protected]d8fc4722014-06-13 13:17:15491 if (data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
492 data_reduction_proxy_params_,
493 request,
494 original_response_headers,
495 override_response_headers)) {
496 return net::OK;
497 }
498
[email protected]4a2b6232014-06-19 08:44:14499 return extensions_delegate_->OnHeadersReceived(
[email protected]5f714132014-03-26 10:41:16500 request,
501 callback,
502 original_response_headers,
503 override_response_headers,
504 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51505}
506
[email protected]31b2e5f2011-04-20 16:58:32507void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
508 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02509 if (domain_reliability_monitor_)
510 domain_reliability_monitor_->OnBeforeRedirect(request);
[email protected]4a2b6232014-06-19 08:44:14511 extensions_delegate_->OnBeforeRedirect(request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32512}
513
514
[email protected]8202d0c2011-02-23 08:31:14515void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]186468f2013-10-24 02:44:11516 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "ResponseStarted");
[email protected]4a2b6232014-06-19 08:44:14517 extensions_delegate_->OnResponseStarted(request);
[email protected]8202d0c2011-02-23 08:31:14518}
519
[email protected]8523ba52011-05-22 19:00:58520void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
521 int bytes_read) {
[email protected]186468f2013-10-24 02:44:11522 TRACE_EVENT_ASYNC_STEP_PAST1("net", "URLRequest", &request, "DidRead",
523 "bytes_read", bytes_read);
[email protected]6f4b4b42012-08-27 21:59:07524 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread(
525 request, bytes_read);
526
[email protected]44879ed2012-04-06 01:11:02527#if defined(ENABLE_TASK_MANAGER)
[email protected]17df9e7c2014-02-13 03:49:29528 // This is not completely accurate, but as a first approximation ignore
529 // requests that are served from the cache. See bug 330931 for more info.
530 if (!request.was_cached())
531 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02532#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58533}
534
[email protected]9045b8822012-01-13 20:35:35535void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
536 bool started) {
[email protected]4aca5db2013-08-17 00:51:56537 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request);
[email protected]2756a8e2012-09-07 18:24:29538 if (request->status().status() == net::URLRequestStatus::SUCCESS) {
[email protected]7a299a92012-10-24 23:54:50539 // For better accuracy, we use the actual bytes read instead of the length
540 // specified with the Content-Length header, which may be inaccurate,
541 // or missing, as is the case with chunked encoding.
542 int64 received_content_length = request->received_response_content_length();
543
[email protected]35558812013-12-18 21:58:36544#if defined(OS_ANDROID)
545 if (precache::PrecacheManager::IsPrecachingEnabled()) {
546 // Record precache metrics when a fetch is completed successfully, if
547 // precaching is enabled.
548 BrowserThread::PostTask(
549 BrowserThread::UI, FROM_HERE,
550 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(),
551 base::Time::Now(), received_content_length,
552 request->was_cached(), profile_));
553 }
554#endif // defined(OS_ANDROID)
555
[email protected]7a299a92012-10-24 23:54:50556 // Only record for http or https urls.
557 bool is_http = request->url().SchemeIs("http");
558 bool is_https = request->url().SchemeIs("https");
559
560 if (!request->was_cached() && // Don't record cached content
561 received_content_length && // Zero-byte responses aren't useful.
562 (is_http || is_https)) { // Only record for HTTP or HTTPS urls.
563 int64 original_content_length =
564 request->response_info().headers->GetInt64HeaderValue(
565 "x-original-content-length");
[email protected]a0a06932014-04-14 21:23:42566 data_reduction_proxy::DataReductionProxyRequestType request_type =
567 data_reduction_proxy::GetDataReductionProxyRequestType(request);
[email protected]2db93e42013-08-07 17:40:41568
[email protected]f81a5ee2013-06-20 21:08:49569 base::TimeDelta freshness_lifetime =
570 request->response_info().headers->GetFreshnessLifetime(
571 request->response_info().response_time);
[email protected]828eab22013-12-10 22:42:38572 int64 adjusted_original_content_length =
[email protected]a0a06932014-04-14 21:23:42573 data_reduction_proxy::GetAdjustedOriginalContentLength(
574 request_type, original_content_length,
[email protected]828eab22013-12-10 22:42:38575 received_content_length);
[email protected]7a299a92012-10-24 23:54:50576 AccumulateContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41577 adjusted_original_content_length,
[email protected]a0a06932014-04-14 21:23:42578 request_type);
[email protected]7a299a92012-10-24 23:54:50579 RecordContentLengthHistograms(received_content_length,
[email protected]f81a5ee2013-06-20 21:08:49580 original_content_length,
581 freshness_lifetime);
[email protected]7a299a92012-10-24 23:54:50582 DVLOG(2) << __FUNCTION__
583 << " received content length: " << received_content_length
584 << " original content length: " << original_content_length
585 << " url: " << request->url();
586 }
587
[email protected]4a2b6232014-06-19 08:44:14588 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01589 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
590 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]4a2b6232014-06-19 08:44:14591 extensions_delegate_->OnCompleted(request, started);
[email protected]a83dd332011-07-13 10:41:01592 } else {
593 NOTREACHED();
[email protected]48944382011-04-23 13:28:16594 }
[email protected]45de676a2014-03-18 23:52:02595 if (domain_reliability_monitor_)
596 domain_reliability_monitor_->OnCompleted(request, started);
[email protected]4a2b6232014-06-19 08:44:14597 extensions_delegate_->ForwardProxyErrors(request);
598 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14599}
[email protected]4b50cb52011-03-10 00:29:37600
[email protected]4875ba12011-03-30 22:31:51601void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
[email protected]4a2b6232014-06-19 08:44:14602 extensions_delegate_->OnURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51603}
604
[email protected]82a37672011-05-03 12:02:41605void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09606 const base::string16& error) {
[email protected]4a2b6232014-06-19 08:44:14607 extensions_delegate_->OnPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41608}
[email protected]7efc582d2011-08-03 20:46:35609
[email protected]c2911d72011-10-03 22:16:36610net::NetworkDelegate::AuthRequiredResponse
611ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35612 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36613 const net::AuthChallengeInfo& auth_info,
614 const AuthCallback& callback,
615 net::AuthCredentials* credentials) {
[email protected]4a2b6232014-06-19 08:44:14616 return extensions_delegate_->OnAuthRequired(
617 request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35618}
[email protected]9c8ae8c2012-03-09 13:13:35619
[email protected]4c219e22012-05-05 19:41:04620bool ChromeNetworkDelegate::OnCanGetCookies(
621 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35622 const net::CookieList& cookie_list) {
623 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02624 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35625 return true;
626
627 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04628 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35629
630 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16631 int render_frame_id = -1;
[email protected]f7fa5b62014-03-19 15:20:06632
633 // |is_for_blocking_resource| indicates whether the cookies read were for a
634 // blocking resource (eg script, css). It is only temporarily added for
635 // diagnostic purposes, per bug 353678. Will be removed again once data
636 // collection is finished.
637 bool is_for_blocking_resource = false;
638 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
639 if (info && ((!info->IsAsync()) ||
640 info->GetResourceType() == ResourceType::STYLESHEET ||
641 info->GetResourceType() == ResourceType::SCRIPT)) {
642 is_for_blocking_resource = true;
643 }
644
[email protected]f3add922013-12-20 23:17:16645 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
646 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35647 BrowserThread::PostTask(
648 BrowserThread::UI, FROM_HERE,
649 base::Bind(&TabSpecificContentSettings::CookiesRead,
[email protected]f3add922013-12-20 23:17:16650 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04651 request.url(), request.first_party_for_cookies(),
[email protected]f7fa5b62014-03-19 15:20:06652 cookie_list, !allow, is_for_blocking_resource));
[email protected]9c8ae8c2012-03-09 13:13:35653 }
654
655 return allow;
656}
657
[email protected]4c219e22012-05-05 19:41:04658bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
659 const std::string& cookie_line,
660 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35661 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02662 if (!cookie_settings_.get())
[email protected]9c8ae8c2012-03-09 13:13:35663 return true;
664
665 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04666 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35667
[email protected]9c8ae8c2012-03-09 13:13:35668 int render_process_id = -1;
[email protected]f3add922013-12-20 23:17:16669 int render_frame_id = -1;
670 if (content::ResourceRequestInfo::GetRenderFrameForRequest(
671 &request, &render_process_id, &render_frame_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35672 BrowserThread::PostTask(
673 BrowserThread::UI, FROM_HERE,
674 base::Bind(&TabSpecificContentSettings::CookieChanged,
[email protected]f3add922013-12-20 23:17:16675 render_process_id, render_frame_id,
[email protected]4c219e22012-05-05 19:41:04676 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43677 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35678 }
679
[email protected]28c5d0b72014-05-13 08:19:59680 if (prerender_tracker_) {
681 prerender_tracker_->OnCookieChangedForURL(
682 render_process_id,
683 request.context()->cookie_store()->GetCookieMonster(),
684 request.url());
685 }
686
[email protected]9c8ae8c2012-03-09 13:13:35687 return allow;
688}
[email protected]4c219e22012-05-05 19:41:04689
690bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
[email protected]650b2d52013-02-10 03:41:45691 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04692 if (g_allow_file_access_)
693 return true;
694
[email protected]d8e4f132012-09-06 04:28:05695#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
696 return true;
697#else
[email protected]4c219e22012-05-05 19:41:04698#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05699 // If we're running Chrome for ChromeOS on Linux, we want to allow file
700 // access.
[email protected]49c4cf852013-09-27 19:28:24701 if (!base::SysInfo::IsRunningOnChromeOS() ||
[email protected]288538482012-09-06 21:09:35702 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
[email protected]d8e4f132012-09-06 04:28:05703 return true;
[email protected]288538482012-09-06 21:09:35704 }
[email protected]d8e4f132012-09-06 04:28:05705
706 // Use a whitelist to only allow access to files residing in the list of
707 // directories below.
[email protected]4c219e22012-05-05 19:41:04708 static const char* const kLocalAccessWhiteList[] = {
709 "/home/chronos/user/Downloads",
710 "/home/chronos/user/log",
[email protected]4791af43d2014-05-05 13:19:42711 "/home/chronos/user/WebRTC Logs",
[email protected]4c219e22012-05-05 19:41:04712 "/media",
713 "/opt/oem",
714 "/usr/share/chromeos-assets",
715 "/tmp",
716 "/var/log",
717 };
[email protected]ae015e12013-11-04 19:11:33718
[email protected]9e733282014-06-18 16:56:55719 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
720 // the profile path ("/home/chronos/user' is a hard link to current primary
721 // logged in profile.) For the support of multi-profile sessions, we are
722 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
723 // access.
[email protected]ae015e12013-11-04 19:11:33724 if (!profile_path_.empty()) {
725 const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
726 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
727 return true;
[email protected]9e733282014-06-18 16:56:55728 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
729 if (webrtc_logs == path.StripTrailingSeparators() ||
730 webrtc_logs.IsParent(path)) {
731 return true;
732 }
[email protected]ae015e12013-11-04 19:11:33733 }
[email protected]d8e4f132012-09-06 04:28:05734#elif defined(OS_ANDROID)
735 // Access to files in external storage is allowed.
[email protected]650b2d52013-02-10 03:41:45736 base::FilePath external_storage_path;
[email protected]d8e4f132012-09-06 04:28:05737 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
738 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04739 return true;
740
[email protected]d8e4f132012-09-06 04:28:05741 // Whitelist of other allowed directories.
742 static const char* const kLocalAccessWhiteList[] = {
743 "/sdcard",
744 "/mnt/sdcard",
745 };
746#endif
747
[email protected]4c219e22012-05-05 19:41:04748 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
[email protected]650b2d52013-02-10 03:41:45749 const base::FilePath white_listed_path(kLocalAccessWhiteList[i]);
750 // base::FilePath::operator== should probably handle trailing separators.
[email protected]4c219e22012-05-05 19:41:04751 if (white_listed_path == path.StripTrailingSeparators() ||
752 white_listed_path.IsParent(path)) {
753 return true;
754 }
755 }
[email protected]d8e4f132012-09-06 04:28:05756
[email protected]288538482012-09-06 21:09:35757 DVLOG(1) << "File access denied - " << path.value().c_str();
[email protected]4c219e22012-05-05 19:41:04758 return false;
[email protected]d8e4f132012-09-06 04:28:05759#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04760}
[email protected]a1d4ab072012-06-07 13:21:15761
762bool ChromeNetworkDelegate::OnCanThrottleRequest(
763 const net::URLRequest& request) const {
[email protected]4a2b6232014-06-19 08:44:14764 if (g_never_throttle_requests_)
[email protected]a1d4ab072012-06-07 13:21:15765 return false;
[email protected]c4a7df82012-08-09 22:48:46766 return request.first_party_for_cookies().scheme() ==
[email protected]885c0e92012-11-13 20:27:42767 extensions::kExtensionScheme;
[email protected]a1d4ab072012-06-07 13:21:15768}
[email protected]aa28181e2012-06-13 00:53:58769
[email protected]e6d017652013-05-17 18:01:40770bool ChromeNetworkDelegate::OnCanEnablePrivacyMode(
771 const GURL& url,
772 const GURL& first_party_for_cookies) const {
773 // NULL during tests, or when we're running in the system context.
[email protected]5173de8b2013-06-02 21:16:02774 if (!cookie_settings_.get())
[email protected]e6d017652013-05-17 18:01:40775 return false;
776
777 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed(
778 url, first_party_for_cookies);
779 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed(
780 url, first_party_for_cookies);
781 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed);
782 return privacy_mode;
783}
784
[email protected]aa28181e2012-06-13 00:53:58785int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
786 net::SocketStream* socket,
787 const net::CompletionCallback& callback) {
788#if defined(ENABLE_CONFIGURATION_POLICY)
789 if (url_blacklist_manager_ &&
790 url_blacklist_manager_->IsURLBlocked(socket->url())) {
791 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58792 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26793 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
794 net::NetLog::StringCallback("url",
795 &socket->url().possibly_invalid_spec()));
[email protected]91468a92013-03-06 17:21:55796 return net::ERR_BLOCKED_BY_ADMINISTRATOR;
[email protected]aa28181e2012-06-13 00:53:58797 }
798#endif
799 return net::OK;
800}
[email protected]5a07c192012-07-30 20:18:22801
[email protected]7a299a92012-10-24 23:54:50802void ChromeNetworkDelegate::AccumulateContentLength(
[email protected]b7796462013-12-12 19:42:34803 int64 received_content_length,
804 int64 original_content_length,
[email protected]a0a06932014-04-14 21:23:42805 data_reduction_proxy::DataReductionProxyRequestType request_type) {
[email protected]7a299a92012-10-24 23:54:50806 DCHECK_GE(received_content_length, 0);
807 DCHECK_GE(original_content_length, 0);
808 StoreAccumulatedContentLength(received_content_length,
[email protected]2db93e42013-08-07 17:40:41809 original_content_length,
[email protected]a0a06932014-04-14 21:23:42810 request_type,
[email protected]b7796462013-12-12 19:42:34811 reinterpret_cast<Profile*>(profile_));
[email protected]7a299a92012-10-24 23:54:50812 received_content_length_ += received_content_length;
813 original_content_length_ += original_content_length;
814}