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 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 28 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 29 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 29 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 30 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 30 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 31 #include "chrome/browser/net/chrome_extensions_network_delegate.h" | 31 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
| 32 #include "chrome/browser/net/connect_interceptor.h" | 32 #include "chrome/browser/net/connect_interceptor.h" |
| 33 #include "chrome/browser/net/request_source_bandwidth_histograms.h" | 33 #include "chrome/browser/net/request_source_bandwidth_histograms.h" |
| 34 #include "chrome/browser/net/safe_search_util.h" | 34 #include "chrome/browser/net/safe_search_util.h" |
| 35 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
| 36 #include "chrome/browser/sessions/session_tab_helper.h" | |
| 36 #include "chrome/browser/task_management/task_manager_interface.h" | 37 #include "chrome/browser/task_management/task_manager_interface.h" |
| 37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 38 #include "components/content_settings/core/browser/cookie_settings.h" | 39 #include "components/content_settings/core/browser/cookie_settings.h" |
| 39 #include "components/data_usage/core/data_use_aggregator.h" | 40 #include "components/data_usage/core/data_use_aggregator.h" |
| 40 #include "components/domain_reliability/monitor.h" | 41 #include "components/domain_reliability/monitor.h" |
| 41 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/render_frame_host.h" | 43 #include "content/public/browser/render_frame_host.h" |
| 43 #include "content/public/browser/render_view_host.h" | 44 #include "content/public/browser/render_view_host.h" |
| 44 #include "content/public/browser/resource_request_info.h" | 45 #include "content/public/browser/resource_request_info.h" |
| 46 #include "content/public/browser/web_contents.h" | |
| 45 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
| 46 #include "content/public/common/process_type.h" | 48 #include "content/public/common/process_type.h" |
| 47 #include "net/base/host_port_pair.h" | 49 #include "net/base/host_port_pair.h" |
| 48 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 49 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 50 #include "net/cookies/canonical_cookie.h" | 52 #include "net/cookies/canonical_cookie.h" |
| 51 #include "net/cookies/cookie_options.h" | 53 #include "net/cookies/cookie_options.h" |
| 52 #include "net/http/http_request_headers.h" | 54 #include "net/http/http_request_headers.h" |
| 53 #include "net/http/http_response_headers.h" | 55 #include "net/http/http_response_headers.h" |
| 54 #include "net/http/http_status_code.h" | 56 #include "net/http/http_status_code.h" |
| 55 #include "net/log/net_log.h" | 57 #include "net/log/net_log.h" |
| 56 #include "net/url_request/url_request.h" | 58 #include "net/url_request/url_request.h" |
| 59 #include "url/gurl.h" | |
| 57 | 60 |
| 58 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
| 59 #include "chrome/browser/io_thread.h" | 62 #include "chrome/browser/io_thread.h" |
| 60 #include "chrome/browser/precache/precache_manager_factory.h" | 63 #include "chrome/browser/precache/precache_manager_factory.h" |
| 61 #include "components/precache/content/precache_manager.h" | 64 #include "components/precache/content/precache_manager.h" |
| 62 #endif | 65 #endif |
| 63 | 66 |
| 64 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
| 65 #include "base/sys_info.h" | 68 #include "base/sys_info.h" |
| 66 #include "chrome/common/chrome_switches.h" | 69 #include "chrome/common/chrome_switches.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 275 |
| 273 int64 size = request->received_response_content_length(); | 276 int64 size = request->received_response_content_length(); |
| 274 if (size >= 0 && state == CACHE_STATE_NO_LONGER_VALID) { | 277 if (size >= 0 && state == CACHE_STATE_NO_LONGER_VALID) { |
| 275 UMA_HISTOGRAM_COUNTS("Net.CacheState.AllBytes", size); | 278 UMA_HISTOGRAM_COUNTS("Net.CacheState.AllBytes", size); |
| 276 if (CanRequestBeDeltaEncoded(request)) { | 279 if (CanRequestBeDeltaEncoded(request)) { |
| 277 UMA_HISTOGRAM_COUNTS("Net.CacheState.EncodeableBytes", size); | 280 UMA_HISTOGRAM_COUNTS("Net.CacheState.EncodeableBytes", size); |
| 278 } | 281 } |
| 279 } | 282 } |
| 280 } | 283 } |
| 281 | 284 |
| 285 void RunTabIdCallback(const base::Callback<void(int32_t)>& tab_id_callback, | |
| 286 int32_t tab_id) { | |
| 287 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 288 tab_id_callback.Run(tab_id); | |
| 289 } | |
| 290 | |
| 291 // Attempt to get the associated tab ID for a given render frame, and pass it to | |
| 292 // |tab_id_callback| on the IO thread. A tab ID of -1 is passed if no associated | |
| 293 // tab was found. | |
| 294 void ProvideTabIdFromUIThread( | |
| 295 int render_process_id, | |
| 296 int render_frame_id, | |
| 297 const base::Callback<void(int32_t)>& tab_id_callback) { | |
| 298 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 299 // TODO(sclittle): For prerendering tabs, investigate if it's possible to find | |
| 300 // the original tab that initiated the prerender. | |
| 301 int32_t tab_id = | |
| 302 SessionTabHelper::IdForTab(content::WebContents::FromRenderFrameHost( | |
| 303 content::RenderFrameHost::FromID(render_process_id, | |
| 304 render_frame_id))); | |
| 305 BrowserThread::PostTask( | |
| 306 BrowserThread::IO, FROM_HERE, | |
| 307 base::Bind(&RunTabIdCallback, tab_id_callback, tab_id)); | |
| 308 } | |
| 309 | |
| 282 } // namespace | 310 } // namespace |
| 283 | 311 |
| 284 ChromeNetworkDelegate::ChromeNetworkDelegate( | 312 ChromeNetworkDelegate::ChromeNetworkDelegate( |
| 285 extensions::EventRouterForwarder* event_router, | 313 extensions::EventRouterForwarder* event_router, |
| 286 BooleanPrefMember* enable_referrers) | 314 BooleanPrefMember* enable_referrers) |
| 287 : profile_(NULL), | 315 : profile_(NULL), |
| 288 enable_referrers_(enable_referrers), | 316 enable_referrers_(enable_referrers), |
| 289 enable_do_not_track_(NULL), | 317 enable_do_not_track_(NULL), |
| 290 force_google_safe_search_(NULL), | 318 force_google_safe_search_(NULL), |
| 291 force_youtube_safety_mode_(NULL), | 319 force_youtube_safety_mode_(NULL), |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 void ChromeNetworkDelegate::OnNetworkBytesReceived( | 523 void ChromeNetworkDelegate::OnNetworkBytesReceived( |
| 496 const net::URLRequest& request, | 524 const net::URLRequest& request, |
| 497 int64_t bytes_received) { | 525 int64_t bytes_received) { |
| 498 #if defined(ENABLE_TASK_MANAGER) | 526 #if defined(ENABLE_TASK_MANAGER) |
| 499 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, | 527 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, |
| 500 // not FTP or other types, so those kinds of bytes will not be reported here. | 528 // not FTP or other types, so those kinds of bytes will not be reported here. |
| 501 task_management::TaskManagerInterface::OnRawBytesRead(request, | 529 task_management::TaskManagerInterface::OnRawBytesRead(request, |
| 502 bytes_received); | 530 bytes_received); |
| 503 #endif // defined(ENABLE_TASK_MANAGER) | 531 #endif // defined(ENABLE_TASK_MANAGER) |
| 504 | 532 |
| 505 if (data_use_aggregator_) { | 533 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); |
| 506 if (is_data_usage_off_the_record_) { | |
| 507 data_use_aggregator_->ReportOffTheRecordDataUse(0 /* tx_bytes */, | |
| 508 bytes_received); | |
| 509 } else { | |
| 510 data_use_aggregator_->ReportDataUse(request, -1 /* tab_id */, | |
| 511 0 /* tx_bytes */, bytes_received); | |
| 512 } | |
| 513 } | |
| 514 } | 534 } |
| 515 | 535 |
| 516 void ChromeNetworkDelegate::OnNetworkBytesSent(const net::URLRequest& request, | 536 void ChromeNetworkDelegate::OnNetworkBytesSent(const net::URLRequest& request, |
| 517 int64_t bytes_sent) { | 537 int64_t bytes_sent) { |
| 518 if (data_use_aggregator_) { | 538 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); |
| 519 if (is_data_usage_off_the_record_) { | |
| 520 data_use_aggregator_->ReportOffTheRecordDataUse(bytes_sent, | |
| 521 0 /* rx_bytes */); | |
| 522 } else { | |
| 523 data_use_aggregator_->ReportDataUse(request, -1 /* tab_id */, bytes_sent, | |
| 524 0 /* rx_bytes */); | |
| 525 } | |
| 526 } | |
| 527 } | 539 } |
| 528 | 540 |
| 529 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, | 541 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
| 530 bool started) { | 542 bool started) { |
| 531 #if !defined(OS_IOS) | 543 #if !defined(OS_IOS) |
| 532 // TODO(amohammadkhan): Verify that there is no double recording in data use | 544 // TODO(amohammadkhan): Verify that there is no double recording in data use |
| 533 // of redirected requests. | 545 // of redirected requests. |
| 534 data_use_measurement_.ReportDataUseUMA(request); | 546 data_use_measurement_.ReportDataUseUMA(request); |
| 535 #endif | 547 #endif |
| 536 RecordNetworkErrorHistograms(request); | 548 RecordNetworkErrorHistograms(request); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 return experimental_web_platform_features_enabled_; | 747 return experimental_web_platform_features_enabled_; |
| 736 } | 748 } |
| 737 | 749 |
| 738 bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 750 bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 739 const net::URLRequest& request, | 751 const net::URLRequest& request, |
| 740 const GURL& target_url, | 752 const GURL& target_url, |
| 741 const GURL& referrer_url) const { | 753 const GURL& referrer_url) const { |
| 742 ReportInvalidReferrerSend(target_url, referrer_url); | 754 ReportInvalidReferrerSend(target_url, referrer_url); |
| 743 return true; | 755 return true; |
| 744 } | 756 } |
| 757 | |
| 758 void ChromeNetworkDelegate::ReportDataUsageStats(const net::URLRequest& request, | |
| 759 int64_t tx_bytes, | |
| 760 int64_t rx_bytes) { | |
| 761 if (!data_use_aggregator_) | |
| 762 return; | |
| 763 | |
| 764 if (is_data_usage_off_the_record_) { | |
| 765 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | |
| 766 return; | |
| 767 } | |
| 768 | |
| 769 net::LoadTimingInfo load_timing_info; | |
| 770 request.GetLoadTimingInfo(&load_timing_info); | |
| 771 | |
| 772 base::Callback<void(int32_t)> report_data_use_with_tab_id_callback = | |
| 773 base::Bind(&data_usage::DataUseAggregator::ReportDataUse, | |
| 774 data_use_aggregator_->GetWeakPtr(), tx_bytes, rx_bytes, | |
| 775 request.url(), load_timing_info.request_start, | |
| 776 request.first_party_for_cookies()); | |
| 777 | |
| 778 int render_process_id = -1, render_frame_id = -1; | |
| 779 if (!content::ResourceRequestInfo::GetRenderFrameForRequest( | |
| 780 &request, &render_process_id, &render_frame_id)) { | |
| 781 // Run the callback immediately if the request has no render frame. | |
| 782 report_data_use_with_tab_id_callback.Run(-1 /* tab_id */); | |
| 783 return; | |
| 784 } | |
| 785 | |
| 786 // Hop to the UI thread and back to get the tab ID for the render frame. | |
| 787 BrowserThread::PostTask( | |
| 788 BrowserThread::UI, FROM_HERE, | |
| 789 base::Bind(&ProvideTabIdFromUIThread, render_process_id, render_frame_id, | |
| 790 report_data_use_with_tab_id_callback)); | |
|
mmenke
2015/10/28 22:43:12
I don't think we want post two tasks every time a
sclittle
2015/10/28 23:04:56
Which IDs are to be avoided, e.g. Tab IDs or rende
mmenke
2015/10/28 23:18:42
Apologies, I meant render process / frame IDs. Th
bengr
2015/10/30 15:56:07
Is your concern that the request might not outlive
| |
| 791 } | |
| OLD | NEW |