| 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 17 matching lines...) Expand all Loading... |
| 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/task_management/task_manager_interface.h" | 36 #include "chrome/browser/task_management/task_manager_interface.h" |
| 37 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
| 38 #include "chrome/common/features.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "components/content_settings/core/browser/cookie_settings.h" | 40 #include "components/content_settings/core/browser/cookie_settings.h" |
| 40 #include "components/data_usage/core/data_use_aggregator.h" | 41 #include "components/data_usage/core/data_use_aggregator.h" |
| 41 #include "components/domain_reliability/monitor.h" | 42 #include "components/domain_reliability/monitor.h" |
| 42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/render_frame_host.h" | 44 #include "content/public/browser/render_frame_host.h" |
| 44 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
| 45 #include "content/public/browser/resource_request_info.h" | 46 #include "content/public/browser/resource_request_info.h" |
| 46 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
| 47 #include "content/public/common/process_type.h" | 48 #include "content/public/common/process_type.h" |
| 48 #include "net/base/host_port_pair.h" | 49 #include "net/base/host_port_pair.h" |
| 49 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 50 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 51 #include "net/cookies/canonical_cookie.h" | 52 #include "net/cookies/canonical_cookie.h" |
| 52 #include "net/cookies/cookie_options.h" | 53 #include "net/cookies/cookie_options.h" |
| 53 #include "net/http/http_request_headers.h" | 54 #include "net/http/http_request_headers.h" |
| 54 #include "net/http/http_response_headers.h" | 55 #include "net/http/http_response_headers.h" |
| 55 #include "net/http/http_status_code.h" | 56 #include "net/http/http_status_code.h" |
| 56 #include "net/log/net_log.h" | 57 #include "net/log/net_log.h" |
| 57 #include "net/url_request/url_request.h" | 58 #include "net/url_request/url_request.h" |
| 58 | 59 |
| 59 #if defined(OS_ANDROID) | 60 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 60 #include "chrome/browser/io_thread.h" | 61 #include "chrome/browser/io_thread.h" |
| 61 #include "chrome/browser/precache/precache_manager_factory.h" | 62 #include "chrome/browser/precache/precache_manager_factory.h" |
| 62 #include "components/precache/content/precache_manager.h" | 63 #include "components/precache/content/precache_manager.h" |
| 63 #endif | 64 #endif |
| 64 | 65 |
| 65 #if defined(OS_CHROMEOS) | 66 #if defined(OS_CHROMEOS) |
| 66 #include "base/sys_info.h" | 67 #include "base/sys_info.h" |
| 67 #include "chrome/common/chrome_switches.h" | 68 #include "chrome/common/chrome_switches.h" |
| 68 #endif | 69 #endif |
| 69 | 70 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 99 void ForceGoogleSafeSearchCallbackWrapper( | 100 void ForceGoogleSafeSearchCallbackWrapper( |
| 100 const net::CompletionCallback& callback, | 101 const net::CompletionCallback& callback, |
| 101 net::URLRequest* request, | 102 net::URLRequest* request, |
| 102 GURL* new_url, | 103 GURL* new_url, |
| 103 int rv) { | 104 int rv) { |
| 104 if (rv == net::OK && new_url->is_empty()) | 105 if (rv == net::OK && new_url->is_empty()) |
| 105 safe_search_util::ForceGoogleSafeSearch(request, new_url); | 106 safe_search_util::ForceGoogleSafeSearch(request, new_url); |
| 106 callback.Run(rv); | 107 callback.Run(rv); |
| 107 } | 108 } |
| 108 | 109 |
| 109 #if defined(OS_ANDROID) | 110 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 110 void RecordPrecacheStatsOnUIThread(const GURL& url, | 111 void RecordPrecacheStatsOnUIThread(const GURL& url, |
| 111 const GURL& referrer, | 112 const GURL& referrer, |
| 112 base::TimeDelta latency, | 113 base::TimeDelta latency, |
| 113 const base::Time& fetch_time, | 114 const base::Time& fetch_time, |
| 114 int64 size, | 115 int64 size, |
| 115 bool was_cached, | 116 bool was_cached, |
| 116 void* profile_id) { | 117 void* profile_id) { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 118 | 119 |
| 119 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) | 120 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) |
| 120 return; | 121 return; |
| 121 Profile* profile = reinterpret_cast<Profile*>(profile_id); | 122 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 122 | 123 |
| 123 precache::PrecacheManager* precache_manager = | 124 precache::PrecacheManager* precache_manager = |
| 124 precache::PrecacheManagerFactory::GetForBrowserContext(profile); | 125 precache::PrecacheManagerFactory::GetForBrowserContext(profile); |
| 125 // |precache_manager| could be NULL if the profile is off the record. | 126 // |precache_manager| could be NULL if the profile is off the record. |
| 126 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) | 127 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) |
| 127 return; | 128 return; |
| 128 | 129 |
| 129 precache_manager->RecordStatsForFetch(url, referrer, latency, fetch_time, | 130 precache_manager->RecordStatsForFetch(url, referrer, latency, fetch_time, |
| 130 size, was_cached); | 131 size, was_cached); |
| 131 } | 132 } |
| 132 #endif // defined(OS_ANDROID) | 133 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 133 | 134 |
| 134 void ReportInvalidReferrerSendOnUI() { | 135 void ReportInvalidReferrerSendOnUI() { |
| 135 base::RecordAction( | 136 base::RecordAction( |
| 136 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); | 137 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void ReportInvalidReferrerSend(const GURL& target_url, | 140 void ReportInvalidReferrerSend(const GURL& target_url, |
| 140 const GURL& referrer_url) { | 141 const GURL& referrer_url) { |
| 141 LOG(ERROR) << "Cancelling request to " << target_url | 142 LOG(ERROR) << "Cancelling request to " << target_url |
| 142 << " with invalid referrer " << referrer_url; | 143 << " with invalid referrer " << referrer_url; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 #endif | 520 #endif |
| 520 RecordNetworkErrorHistograms(request); | 521 RecordNetworkErrorHistograms(request); |
| 521 if (started) { | 522 if (started) { |
| 522 // Only call in for requests that were started, to obey the precondition | 523 // Only call in for requests that were started, to obey the precondition |
| 523 // that RecordCacheStateStats can only be called on requests for which | 524 // that RecordCacheStateStats can only be called on requests for which |
| 524 // OnResponseStarted was called. | 525 // OnResponseStarted was called. |
| 525 RecordCacheStateStats(request); | 526 RecordCacheStateStats(request); |
| 526 } | 527 } |
| 527 | 528 |
| 528 if (request->status().status() == net::URLRequestStatus::SUCCESS) { | 529 if (request->status().status() == net::URLRequestStatus::SUCCESS) { |
| 529 #if defined(OS_ANDROID) | 530 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 530 // For better accuracy, we use the actual bytes read instead of the length | 531 // For better accuracy, we use the actual bytes read instead of the length |
| 531 // specified with the Content-Length header, which may be inaccurate, | 532 // specified with the Content-Length header, which may be inaccurate, |
| 532 // or missing, as is the case with chunked encoding. | 533 // or missing, as is the case with chunked encoding. |
| 533 int64 received_content_length = request->received_response_content_length(); | 534 int64 received_content_length = request->received_response_content_length(); |
| 534 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); | 535 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); |
| 535 | 536 |
| 536 // Record precache metrics when a fetch is completed successfully, if | 537 // Record precache metrics when a fetch is completed successfully, if |
| 537 // precaching is allowed. | 538 // precaching is allowed. |
| 538 BrowserThread::PostTask( | 539 BrowserThread::PostTask( |
| 539 BrowserThread::UI, FROM_HERE, | 540 BrowserThread::UI, FROM_HERE, |
| 540 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(), | 541 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(), |
| 541 GURL(request->referrer()), latency, base::Time::Now(), | 542 GURL(request->referrer()), latency, base::Time::Now(), |
| 542 received_content_length, request->was_cached(), profile_)); | 543 received_content_length, request->was_cached(), profile_)); |
| 543 #endif // defined(OS_ANDROID) | 544 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 544 extensions_delegate_->OnCompleted(request, started); | 545 extensions_delegate_->OnCompleted(request, started); |
| 545 } else if (request->status().status() == net::URLRequestStatus::FAILED || | 546 } else if (request->status().status() == net::URLRequestStatus::FAILED || |
| 546 request->status().status() == net::URLRequestStatus::CANCELED) { | 547 request->status().status() == net::URLRequestStatus::CANCELED) { |
| 547 extensions_delegate_->OnCompleted(request, started); | 548 extensions_delegate_->OnCompleted(request, started); |
| 548 } else { | 549 } else { |
| 549 NOTREACHED(); | 550 NOTREACHED(); |
| 550 } | 551 } |
| 551 if (domain_reliability_monitor_) | 552 if (domain_reliability_monitor_) |
| 552 domain_reliability_monitor_->OnCompleted(request, started); | 553 domain_reliability_monitor_->OnCompleted(request, started); |
| 553 RecordRequestSourceBandwidth(request, started); | 554 RecordRequestSourceBandwidth(request, started); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 if (!data_use_aggregator_) | 739 if (!data_use_aggregator_) |
| 739 return; | 740 return; |
| 740 | 741 |
| 741 if (is_data_usage_off_the_record_) { | 742 if (is_data_usage_off_the_record_) { |
| 742 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 743 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 743 return; | 744 return; |
| 744 } | 745 } |
| 745 | 746 |
| 746 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 747 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 747 } | 748 } |
| OLD | NEW |