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

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 2462983003: Move data use measurement to DataUseNetworkDelegate (Closed)
Patch Set: Rebased Created 4 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/net/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 UMA_HISTOGRAM_SPARSE_SLOWLY( 137 UMA_HISTOGRAM_SPARSE_SLOWLY(
138 "Net.HttpRequestCompletionErrorCodes.MainFrame", std::abs(net_error)); 138 "Net.HttpRequestCompletionErrorCodes.MainFrame", std::abs(net_error));
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 } // namespace 143 } // namespace
144 144
145 ChromeNetworkDelegate::ChromeNetworkDelegate( 145 ChromeNetworkDelegate::ChromeNetworkDelegate(
146 extensions::EventRouterForwarder* event_router, 146 extensions::EventRouterForwarder* event_router,
147 BooleanPrefMember* enable_referrers, 147 BooleanPrefMember* enable_referrers)
148 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder)
149 : profile_(nullptr), 148 : profile_(nullptr),
150 enable_referrers_(enable_referrers), 149 enable_referrers_(enable_referrers),
151 enable_do_not_track_(nullptr), 150 enable_do_not_track_(nullptr),
152 force_google_safe_search_(nullptr), 151 force_google_safe_search_(nullptr),
153 force_youtube_restrict_(nullptr), 152 force_youtube_restrict_(nullptr),
154 allowed_domains_for_apps_(nullptr), 153 allowed_domains_for_apps_(nullptr),
155 url_blacklist_manager_(nullptr), 154 url_blacklist_manager_(nullptr),
156 domain_reliability_monitor_(nullptr), 155 domain_reliability_monitor_(nullptr),
157 data_use_measurement_(metrics_data_use_forwarder),
158 experimental_web_platform_features_enabled_( 156 experimental_web_platform_features_enabled_(
159 base::CommandLine::ForCurrentProcess()->HasSwitch( 157 base::CommandLine::ForCurrentProcess()->HasSwitch(
160 switches::kEnableExperimentalWebPlatformFeatures)), 158 switches::kEnableExperimentalWebPlatformFeatures)),
161 data_use_aggregator_(nullptr), 159 data_use_aggregator_(nullptr),
162 is_data_usage_off_the_record_(true) { 160 is_data_usage_off_the_record_(true) {
163 DCHECK(enable_referrers); 161 DCHECK(enable_referrers);
164 extensions_delegate_.reset( 162 extensions_delegate_.reset(
165 ChromeExtensionsNetworkDelegate::Create(event_router)); 163 ChromeExtensionsNetworkDelegate::Create(event_router));
166 } 164 }
167 165
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 228
231 int ChromeNetworkDelegate::OnBeforeURLRequest( 229 int ChromeNetworkDelegate::OnBeforeURLRequest(
232 net::URLRequest* request, 230 net::URLRequest* request,
233 const net::CompletionCallback& callback, 231 const net::CompletionCallback& callback,
234 GURL* new_url) { 232 GURL* new_url) {
235 // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. 233 // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed.
236 tracked_objects::ScopedTracker tracking_profile1( 234 tracked_objects::ScopedTracker tracking_profile1(
237 FROM_HERE_WITH_EXPLICIT_FUNCTION( 235 FROM_HERE_WITH_EXPLICIT_FUNCTION(
238 "456327 URLRequest::ChromeNetworkDelegate::OnBeforeURLRequest")); 236 "456327 URLRequest::ChromeNetworkDelegate::OnBeforeURLRequest"));
239 237
240 data_use_measurement_.OnBeforeURLRequest(request);
241
242 // TODO(joaodasilva): This prevents extensions from seeing URLs that are 238 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
243 // blocked. However, an extension might redirect the request to another URL, 239 // blocked. However, an extension might redirect the request to another URL,
244 // which is not blocked. 240 // which is not blocked.
245 241
246 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 242 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
247 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR; 243 int error = net::ERR_BLOCKED_BY_ADMINISTRATOR;
248 if (info && content::IsResourceTypeFrame(info->GetResourceType()) && 244 if (info && content::IsResourceTypeFrame(info->GetResourceType()) &&
249 url_blacklist_manager_ && 245 url_blacklist_manager_ &&
250 url_blacklist_manager_->ShouldBlockRequestForFrame( 246 url_blacklist_manager_->ShouldBlockRequestForFrame(
251 request->url(), &error)) { 247 request->url(), &error)) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 return extensions_delegate_->OnHeadersReceived( 342 return extensions_delegate_->OnHeadersReceived(
347 request, 343 request,
348 callback, 344 callback,
349 original_response_headers, 345 original_response_headers,
350 override_response_headers, 346 override_response_headers,
351 allowed_unsafe_redirect_url); 347 allowed_unsafe_redirect_url);
352 } 348 }
353 349
354 void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, 350 void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
355 const GURL& new_location) { 351 const GURL& new_location) {
356 data_use_measurement_.OnBeforeRedirect(*request, new_location);
357 if (domain_reliability_monitor_) 352 if (domain_reliability_monitor_)
358 domain_reliability_monitor_->OnBeforeRedirect(request); 353 domain_reliability_monitor_->OnBeforeRedirect(request);
359 extensions_delegate_->OnBeforeRedirect(request, new_location); 354 extensions_delegate_->OnBeforeRedirect(request, new_location);
360 } 355 }
361 356
362 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request, 357 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request,
363 int net_error) { 358 int net_error) {
364 extensions_delegate_->OnResponseStarted(request, net_error); 359 extensions_delegate_->OnResponseStarted(request, net_error);
365 } 360 }
366 361
367 void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, 362 void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
368 int64_t bytes_received) { 363 int64_t bytes_received) {
369 #if defined(ENABLE_TASK_MANAGER) 364 #if defined(ENABLE_TASK_MANAGER)
370 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, 365 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs,
371 // not FTP or other types, so those kinds of bytes will not be reported here. 366 // not FTP or other types, so those kinds of bytes will not be reported here.
372 task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received); 367 task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received);
373 #endif // defined(ENABLE_TASK_MANAGER) 368 #endif // defined(ENABLE_TASK_MANAGER)
374 369
375 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); 370 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received);
376 data_use_measurement_.OnNetworkBytesReceived(*request, bytes_received);
377 } 371 }
378 372
379 void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, 373 void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
380 int64_t bytes_sent) { 374 int64_t bytes_sent) {
381 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); 375 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */);
382 data_use_measurement_.OnNetworkBytesSent(*request, bytes_sent);
383 } 376 }
384 377
385 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, 378 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
386 bool started, 379 bool started,
387 int net_error) { 380 int net_error) {
388 DCHECK_NE(net::ERR_IO_PENDING, net_error); 381 DCHECK_NE(net::ERR_IO_PENDING, net_error);
389 382
390 // TODO(amohammadkhan): Verify that there is no double recording in data use 383 // TODO(amohammadkhan): Verify that there is no double recording in data use
391 // of redirected requests. 384 // of redirected requests.
392 data_use_measurement_.OnCompleted(*request, started);
393 RecordNetworkErrorHistograms(request, net_error); 385 RecordNetworkErrorHistograms(request, net_error);
394 386
395 if (net_error == net::OK) { 387 if (net_error == net::OK) {
396 #if BUILDFLAG(ANDROID_JAVA_UI) 388 #if BUILDFLAG(ANDROID_JAVA_UI)
397 precache::UpdatePrecacheMetricsAndState(request, profile_); 389 precache::UpdatePrecacheMetricsAndState(request, profile_);
398 #endif // BUILDFLAG(ANDROID_JAVA_UI) 390 #endif // BUILDFLAG(ANDROID_JAVA_UI)
399 } 391 }
400 392
401 extensions_delegate_->OnCompleted(request, started, net_error); 393 extensions_delegate_->OnCompleted(request, started, net_error);
402 if (domain_reliability_monitor_) 394 if (domain_reliability_monitor_)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (!data_use_aggregator_) 576 if (!data_use_aggregator_)
585 return; 577 return;
586 578
587 if (is_data_usage_off_the_record_) { 579 if (is_data_usage_off_the_record_) {
588 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); 580 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes);
589 return; 581 return;
590 } 582 }
591 583
592 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); 584 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes);
593 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698