Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
| 13 #include "base/debug/dump_without_crashing.h" | 13 #include "base/debug/dump_without_crashing.h" |
| 14 #include "base/debug/stack_trace.h" | 14 #include "base/debug/stack_trace.h" |
| 15 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/sparse_histogram.h" | |
| 18 #include "base/metrics/user_metrics.h" | 19 #include "base/metrics/user_metrics.h" |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 20 #include "base/prefs/pref_member.h" | 21 #include "base/prefs/pref_member.h" |
| 21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
| 22 #include "base/profiler/scoped_tracker.h" | 23 #include "base/profiler/scoped_tracker.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/content_settings/cookie_settings.h" | 27 #include "chrome/browser/content_settings/cookie_settings.h" |
| 27 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 28 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 reason = DATA_URL; | 237 reason = DATA_URL; |
| 237 else if (target_url.SchemeIs(url::kHttpScheme)) | 238 else if (target_url.SchemeIs(url::kHttpScheme)) |
| 238 reason = HTTP_URL; | 239 reason = HTTP_URL; |
| 239 base::debug::Alias(&reason); | 240 base::debug::Alias(&reason); |
| 240 base::RecordAction( | 241 base::RecordAction( |
| 241 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); | 242 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); |
| 242 base::debug::DumpWithoutCrashing(); | 243 base::debug::DumpWithoutCrashing(); |
| 243 NOTREACHED(); | 244 NOTREACHED(); |
| 244 } | 245 } |
| 245 | 246 |
| 247 // Determine whether the specified |request| is for a main frame resource. Used | |
| 248 // for histograms. | |
| 249 bool IsMainFrameResourceRequest(const net::URLRequest* request) { | |
| 250 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | |
| 251 return info && info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME; | |
| 252 } | |
| 253 | |
| 254 // Record network errors that requests complete with, including OK and ABORTED. | |
| 255 void RecordNetworkErrorHistograms(const net::URLRequest* request) { | |
| 256 if (request->url().SchemeIs("http")) { | |
| 257 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.HttpRequestCompletionErrorCodes", | |
| 258 std::abs(request->status().error())); | |
| 259 | |
| 260 if (IsMainFrameResourceRequest(request)) { | |
| 261 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
| 262 "Net.HttpRequestCompletionErrorCodes.MainFrame", | |
| 263 std::abs(request->status().error())); | |
| 264 } | |
| 265 } | |
| 266 } | |
| 267 | |
| 246 } // namespace | 268 } // namespace |
| 247 | 269 |
| 248 ChromeNetworkDelegate::ChromeNetworkDelegate( | 270 ChromeNetworkDelegate::ChromeNetworkDelegate( |
| 249 extensions::EventRouterForwarder* event_router, | 271 extensions::EventRouterForwarder* event_router, |
| 250 BooleanPrefMember* enable_referrers) | 272 BooleanPrefMember* enable_referrers) |
| 251 : profile_(NULL), | 273 : profile_(NULL), |
| 252 enable_referrers_(enable_referrers), | 274 enable_referrers_(enable_referrers), |
| 253 enable_do_not_track_(NULL), | 275 enable_do_not_track_(NULL), |
| 254 force_safe_search_(NULL), | 276 force_safe_search_(NULL), |
| 255 force_google_safe_search_(NULL), | 277 force_google_safe_search_(NULL), |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 "423948 ChromeNetworkDelegate::OnRawBytesRead2")); | 564 "423948 ChromeNetworkDelegate::OnRawBytesRead2")); |
| 543 | 565 |
| 544 task_manager->model()->NotifyBytesRead(request, bytes_read); | 566 task_manager->model()->NotifyBytesRead(request, bytes_read); |
| 545 } | 567 } |
| 546 #endif // defined(ENABLE_TASK_MANAGER) | 568 #endif // defined(ENABLE_TASK_MANAGER) |
| 547 } | 569 } |
| 548 | 570 |
| 549 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, | 571 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
| 550 bool started) { | 572 bool started) { |
| 551 if (data_reduction_proxy_usage_stats_) | 573 if (data_reduction_proxy_usage_stats_) |
| 552 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted(request, started); | 574 data_reduction_proxy_usage_stats_->OnUrlRequestCompleted( |
|
bengr
2014/12/09 23:44:13
After megjablon@'s CL lands, this will be in DataR
sclittle
2014/12/10 00:05:03
Darn. Being able to single out main frame resource
| |
| 575 request, started, IsMainFrameResourceRequest(request)); | |
| 576 | |
| 577 RecordNetworkErrorHistograms(request); | |
| 553 | 578 |
| 554 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); | 579 TRACE_EVENT_ASYNC_END0("net", "URLRequest", request); |
| 555 if (request->status().status() == net::URLRequestStatus::SUCCESS) { | 580 if (request->status().status() == net::URLRequestStatus::SUCCESS) { |
| 556 // For better accuracy, we use the actual bytes read instead of the length | 581 // For better accuracy, we use the actual bytes read instead of the length |
| 557 // specified with the Content-Length header, which may be inaccurate, | 582 // specified with the Content-Length header, which may be inaccurate, |
| 558 // or missing, as is the case with chunked encoding. | 583 // or missing, as is the case with chunked encoding. |
| 559 int64 received_content_length = request->received_response_content_length(); | 584 int64 received_content_length = request->received_response_content_length(); |
| 560 | 585 |
| 561 #if defined(OS_ANDROID) | 586 #if defined(OS_ANDROID) |
| 562 if (precache::PrecacheManager::IsPrecachingEnabled()) { | 587 if (precache::PrecacheManager::IsPrecachingEnabled()) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 if (data_reduction_proxy_statistics_prefs_) { | 857 if (data_reduction_proxy_statistics_prefs_) { |
| 833 StoreAccumulatedContentLength(received_content_length, | 858 StoreAccumulatedContentLength(received_content_length, |
| 834 original_content_length, | 859 original_content_length, |
| 835 request_type, | 860 request_type, |
| 836 reinterpret_cast<Profile*>(profile_), | 861 reinterpret_cast<Profile*>(profile_), |
| 837 data_reduction_proxy_statistics_prefs_); | 862 data_reduction_proxy_statistics_prefs_); |
| 838 } | 863 } |
| 839 received_content_length_ += received_content_length; | 864 received_content_length_ += received_content_length; |
| 840 original_content_length_ += original_content_length; | 865 original_content_length_ += original_content_length; |
| 841 } | 866 } |
| OLD | NEW |