| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/net/chrome_extensions_network_delegate.h" | 33 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
| 34 #include "chrome/browser/net/request_source_bandwidth_histograms.h" | 34 #include "chrome/browser/net/request_source_bandwidth_histograms.h" |
| 35 #include "chrome/browser/net/safe_search_util.h" | 35 #include "chrome/browser/net/safe_search_util.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 37 #include "chrome/browser/task_management/task_manager_interface.h" | 37 #include "chrome/browser/task_management/task_manager_interface.h" |
| 38 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
| 39 #include "chrome/common/features.h" | 39 #include "chrome/common/features.h" |
| 40 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 41 #include "components/content_settings/core/browser/cookie_settings.h" | 41 #include "components/content_settings/core/browser/cookie_settings.h" |
| 42 #include "components/data_usage/core/data_use_aggregator.h" | 42 #include "components/data_usage/core/data_use_aggregator.h" |
| 43 #include "components/data_use_measurement/content/data_use_measurement.h" |
| 43 #include "components/domain_reliability/monitor.h" | 44 #include "components/domain_reliability/monitor.h" |
| 44 #include "components/policy/core/browser/url_blacklist_manager.h" | 45 #include "components/policy/core/browser/url_blacklist_manager.h" |
| 45 #include "components/prefs/pref_member.h" | 46 #include "components/prefs/pref_member.h" |
| 46 #include "components/prefs/pref_service.h" | 47 #include "components/prefs/pref_service.h" |
| 47 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
| 49 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
| 50 #include "content/public/browser/resource_request_info.h" | 51 #include "content/public/browser/resource_request_info.h" |
| 51 #include "content/public/common/content_switches.h" | 52 #include "content/public/common/content_switches.h" |
| 52 #include "content/public/common/process_type.h" | 53 #include "content/public/common/process_type.h" |
| 53 #include "net/base/host_port_pair.h" | 54 #include "net/base/host_port_pair.h" |
| 54 #include "net/base/load_flags.h" | 55 #include "net/base/load_flags.h" |
| 55 #include "net/base/net_errors.h" | 56 #include "net/base/net_errors.h" |
| 56 #include "net/cookies/canonical_cookie.h" | 57 #include "net/cookies/canonical_cookie.h" |
| 57 #include "net/cookies/cookie_options.h" | 58 #include "net/cookies/cookie_options.h" |
| 58 #include "net/http/http_request_headers.h" | 59 #include "net/http/http_request_headers.h" |
| 59 #include "net/http/http_response_headers.h" | 60 #include "net/http/http_response_headers.h" |
| 60 #include "net/http/http_status_code.h" | 61 #include "net/http/http_status_code.h" |
| 61 #include "net/log/net_log.h" | 62 #include "net/log/net_log.h" |
| 62 #include "net/url_request/url_request.h" | 63 #include "net/url_request/url_request.h" |
| 63 | 64 |
| 64 #if BUILDFLAG(ANDROID_JAVA_UI) | 65 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 65 #include "chrome/browser/io_thread.h" | 66 #include "chrome/browser/io_thread.h" |
| 66 #include "chrome/browser/precache/precache_manager_factory.h" | 67 #include "chrome/browser/precache/precache_util.h" |
| 67 #include "components/precache/content/precache_manager.h" | |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
| 71 #include "base/sys_info.h" | 71 #include "base/sys_info.h" |
| 72 #include "chrome/common/chrome_switches.h" | 72 #include "chrome/common/chrome_switches.h" |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 #if defined(ENABLE_EXTENSIONS) | 75 #if defined(ENABLE_EXTENSIONS) |
| 76 #include "extensions/common/constants.h" | 76 #include "extensions/common/constants.h" |
| 77 #endif | 77 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 100 void ForceGoogleSafeSearchCallbackWrapper( | 100 void ForceGoogleSafeSearchCallbackWrapper( |
| 101 const net::CompletionCallback& callback, | 101 const net::CompletionCallback& callback, |
| 102 net::URLRequest* request, | 102 net::URLRequest* request, |
| 103 GURL* new_url, | 103 GURL* new_url, |
| 104 int rv) { | 104 int rv) { |
| 105 if (rv == net::OK && new_url->is_empty()) | 105 if (rv == net::OK && new_url->is_empty()) |
| 106 safe_search_util::ForceGoogleSafeSearch(request, new_url); | 106 safe_search_util::ForceGoogleSafeSearch(request, new_url); |
| 107 callback.Run(rv); | 107 callback.Run(rv); |
| 108 } | 108 } |
| 109 | 109 |
| 110 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 111 void RecordPrecacheStatsOnUIThread(const GURL& url, | |
| 112 const GURL& referrer, | |
| 113 base::TimeDelta latency, | |
| 114 const base::Time& fetch_time, | |
| 115 int64_t size, | |
| 116 bool was_cached, | |
| 117 void* profile_id) { | |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 119 | |
| 120 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) | |
| 121 return; | |
| 122 Profile* profile = reinterpret_cast<Profile*>(profile_id); | |
| 123 | |
| 124 precache::PrecacheManager* precache_manager = | |
| 125 precache::PrecacheManagerFactory::GetForBrowserContext(profile); | |
| 126 // |precache_manager| could be NULL if the profile is off the record. | |
| 127 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) | |
| 128 return; | |
| 129 | |
| 130 precache_manager->RecordStatsForFetch(url, referrer, latency, fetch_time, | |
| 131 size, was_cached); | |
| 132 } | |
| 133 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 134 | |
| 135 void ReportInvalidReferrerSendOnUI() { | 110 void ReportInvalidReferrerSendOnUI() { |
| 136 base::RecordAction( | 111 base::RecordAction( |
| 137 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); | 112 base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); |
| 138 } | 113 } |
| 139 | 114 |
| 140 void ReportInvalidReferrerSend(const GURL& target_url, | 115 void ReportInvalidReferrerSend(const GURL& target_url, |
| 141 const GURL& referrer_url) { | 116 const GURL& referrer_url) { |
| 142 LOG(ERROR) << "Cancelling request to " << target_url | 117 LOG(ERROR) << "Cancelling request to " << target_url |
| 143 << " with invalid referrer " << referrer_url; | 118 << " with invalid referrer " << referrer_url; |
| 144 // Record information to help debug http://crbug.com/422871 | 119 // Record information to help debug http://crbug.com/422871 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 RecordNetworkErrorHistograms(request); | 496 RecordNetworkErrorHistograms(request); |
| 522 if (started) { | 497 if (started) { |
| 523 // Only call in for requests that were started, to obey the precondition | 498 // Only call in for requests that were started, to obey the precondition |
| 524 // that RecordCacheStateStats can only be called on requests for which | 499 // that RecordCacheStateStats can only be called on requests for which |
| 525 // OnResponseStarted was called. | 500 // OnResponseStarted was called. |
| 526 RecordCacheStateStats(request); | 501 RecordCacheStateStats(request); |
| 527 } | 502 } |
| 528 | 503 |
| 529 if (request->status().status() == net::URLRequestStatus::SUCCESS) { | 504 if (request->status().status() == net::URLRequestStatus::SUCCESS) { |
| 530 #if BUILDFLAG(ANDROID_JAVA_UI) | 505 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 531 // For better accuracy, we use the actual bytes read instead of the length | 506 precache::PrecacheUtil::UpdatePrecacheMetricsAndState(request, profile_); |
| 532 // specified with the Content-Length header, which may be inaccurate, | |
| 533 // or missing, as is the case with chunked encoding. | |
| 534 int64_t received_content_length = | |
| 535 request->received_response_content_length(); | |
| 536 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); | |
| 537 | |
| 538 // Record precache metrics when a fetch is completed successfully, if | |
| 539 // precaching is allowed. | |
| 540 BrowserThread::PostTask( | |
| 541 BrowserThread::UI, FROM_HERE, | |
| 542 base::Bind(&RecordPrecacheStatsOnUIThread, request->url(), | |
| 543 GURL(request->referrer()), latency, base::Time::Now(), | |
| 544 received_content_length, request->was_cached(), profile_)); | |
| 545 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 507 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 546 extensions_delegate_->OnCompleted(request, started); | 508 extensions_delegate_->OnCompleted(request, started); |
| 547 } else if (request->status().status() == net::URLRequestStatus::FAILED || | 509 } else if (request->status().status() == net::URLRequestStatus::FAILED || |
| 548 request->status().status() == net::URLRequestStatus::CANCELED) { | 510 request->status().status() == net::URLRequestStatus::CANCELED) { |
| 549 extensions_delegate_->OnCompleted(request, started); | 511 extensions_delegate_->OnCompleted(request, started); |
| 550 } else { | 512 } else { |
| 551 NOTREACHED(); | 513 NOTREACHED(); |
| 552 } | 514 } |
| 553 if (domain_reliability_monitor_) | 515 if (domain_reliability_monitor_) |
| 554 domain_reliability_monitor_->OnCompleted(request, started); | 516 domain_reliability_monitor_->OnCompleted(request, started); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 if (!data_use_aggregator_) | 710 if (!data_use_aggregator_) |
| 749 return; | 711 return; |
| 750 | 712 |
| 751 if (is_data_usage_off_the_record_) { | 713 if (is_data_usage_off_the_record_) { |
| 752 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 714 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 753 return; | 715 return; |
| 754 } | 716 } |
| 755 | 717 |
| 756 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 718 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 757 } | 719 } |
| OLD | NEW |