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

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

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

Powered by Google App Engine
This is Rietveld 408576698