| 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/loader/chrome_resource_dispatcher_host_delegate.h" | 5 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <utility> | 9 #include <utility> | 
| 10 #include <vector> | 10 #include <vector> | 
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 344     } | 344     } | 
| 345   } | 345   } | 
| 346 } | 346 } | 
| 347 | 347 | 
| 348 void NotifyUIThreadOfRequestComplete( | 348 void NotifyUIThreadOfRequestComplete( | 
| 349     const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 349     const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | 
| 350     const GURL& url, | 350     const GURL& url, | 
| 351     const content::GlobalRequestID& request_id, | 351     const content::GlobalRequestID& request_id, | 
| 352     ResourceType resource_type, | 352     ResourceType resource_type, | 
| 353     bool was_cached, | 353     bool was_cached, | 
| 354     bool used_data_reduction_proxy, | 354     std::unique_ptr<data_reduction_proxy::DataReductionProxyData> | 
|  | 355         data_reduction_proxy_data, | 
| 355     int net_error, | 356     int net_error, | 
| 356     int64_t total_received_bytes, | 357     int64_t total_received_bytes, | 
| 357     int64_t raw_body_bytes, | 358     int64_t raw_body_bytes, | 
| 358     int64_t original_content_length, | 359     int64_t original_content_length, | 
| 359     base::TimeTicks request_creation_time, | 360     base::TimeTicks request_creation_time, | 
| 360     base::TimeDelta request_loading_time) { | 361     base::TimeDelta request_loading_time) { | 
| 361   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 362   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 
| 362   content::WebContents* web_contents = web_contents_getter.Run(); | 363   content::WebContents* web_contents = web_contents_getter.Run(); | 
| 363   if (!web_contents) | 364   if (!web_contents) | 
| 364     return; | 365     return; | 
| 365   if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | 366   if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | 
| 366     LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time, | 367     LogMainFrameMetricsOnUIThread(url, net_error, request_loading_time, | 
| 367                                   web_contents); | 368                                   web_contents); | 
| 368   } | 369   } | 
| 369   if (!was_cached) { | 370   if (!was_cached) { | 
| 370     UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes); | 371     UpdatePrerenderNetworkBytesCallback(web_contents, total_received_bytes); | 
| 371 #if defined(OS_ANDROID) | 372 #if defined(OS_ANDROID) | 
| 372     offline_pages::BackgroundLoaderOffliner* background_loader = | 373     offline_pages::BackgroundLoaderOffliner* background_loader = | 
| 373         offline_pages::BackgroundLoaderOffliner::FromWebContents(web_contents); | 374         offline_pages::BackgroundLoaderOffliner::FromWebContents(web_contents); | 
| 374 | 375 | 
| 375     if (background_loader) | 376     if (background_loader) | 
| 376       background_loader->OnNetworkBytesChanged(total_received_bytes); | 377       background_loader->OnNetworkBytesChanged(total_received_bytes); | 
| 377 #endif  // OS_ANDROID | 378 #endif  // OS_ANDROID | 
| 378   } | 379   } | 
| 379   page_load_metrics::MetricsWebContentsObserver* metrics_observer = | 380   page_load_metrics::MetricsWebContentsObserver* metrics_observer = | 
| 380       page_load_metrics::MetricsWebContentsObserver::FromWebContents( | 381       page_load_metrics::MetricsWebContentsObserver::FromWebContents( | 
| 381           web_contents); | 382           web_contents); | 
| 382   if (metrics_observer) { | 383   if (metrics_observer) { | 
| 383     metrics_observer->OnRequestComplete( | 384     metrics_observer->OnRequestComplete(request_id, resource_type, was_cached, | 
| 384         request_id, resource_type, was_cached, used_data_reduction_proxy, | 385                                         std::move(data_reduction_proxy_data), | 
| 385         raw_body_bytes, original_content_length, request_creation_time); | 386                                         raw_body_bytes, original_content_length, | 
|  | 387                                         request_creation_time); | 
| 386   } | 388   } | 
| 387 } | 389 } | 
| 388 | 390 | 
| 389 }  // namespace | 391 }  // namespace | 
| 390 | 392 | 
| 391 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() | 393 ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate() | 
| 392     : download_request_limiter_(g_browser_process->download_request_limiter()), | 394     : download_request_limiter_(g_browser_process->download_request_limiter()), | 
| 393       safe_browsing_(g_browser_process->safe_browsing_service()) | 395       safe_browsing_(g_browser_process->safe_browsing_service()) | 
| 394 #if BUILDFLAG(ENABLE_EXTENSIONS) | 396 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
| 395       , user_script_listener_(new extensions::UserScriptListener()) | 397       , user_script_listener_(new extensions::UserScriptListener()) | 
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 815   if (!url_request) | 817   if (!url_request) | 
| 816     return; | 818     return; | 
| 817   // TODO(maksims): remove this and use net_error argument in RequestComplete | 819   // TODO(maksims): remove this and use net_error argument in RequestComplete | 
| 818   // once ResourceDispatcherHostDelegate is modified. | 820   // once ResourceDispatcherHostDelegate is modified. | 
| 819   int net_error = url_request->status().error(); | 821   int net_error = url_request->status().error(); | 
| 820   const ResourceRequestInfo* info = | 822   const ResourceRequestInfo* info = | 
| 821       ResourceRequestInfo::ForRequest(url_request); | 823       ResourceRequestInfo::ForRequest(url_request); | 
| 822 | 824 | 
| 823   data_reduction_proxy::DataReductionProxyData* data = | 825   data_reduction_proxy::DataReductionProxyData* data = | 
| 824       data_reduction_proxy::DataReductionProxyData::GetData(*url_request); | 826       data_reduction_proxy::DataReductionProxyData::GetData(*url_request); | 
| 825   bool used_data_reduction_proxy = data && data->used_data_reduction_proxy(); | 827   std::unique_ptr<data_reduction_proxy::DataReductionProxyData> | 
|  | 828       data_reduction_proxy_data; | 
|  | 829   if (data) | 
|  | 830     data_reduction_proxy_data = data->DeepCopy(); | 
| 826   int64_t original_content_length = | 831   int64_t original_content_length = | 
| 827       used_data_reduction_proxy | 832       data && data->used_data_reduction_proxy() | 
| 828           ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request) | 833           ? data_reduction_proxy::util::CalculateEffectiveOCL(*url_request) | 
| 829           : url_request->GetRawBodyBytes(); | 834           : url_request->GetRawBodyBytes(); | 
| 830 | 835 | 
| 831   BrowserThread::PostTask( | 836   BrowserThread::PostTask( | 
| 832       BrowserThread::UI, FROM_HERE, | 837       BrowserThread::UI, FROM_HERE, | 
| 833       base::Bind(&NotifyUIThreadOfRequestComplete, | 838       base::Bind(&NotifyUIThreadOfRequestComplete, | 
| 834                  info->GetWebContentsGetterForRequest(), url_request->url(), | 839                  info->GetWebContentsGetterForRequest(), url_request->url(), | 
| 835                  info->GetGlobalRequestID(), info->GetResourceType(), | 840                  info->GetGlobalRequestID(), info->GetResourceType(), | 
| 836                  url_request->was_cached(), used_data_reduction_proxy, | 841                  url_request->was_cached(), | 
| 837                  net_error, url_request->GetTotalReceivedBytes(), | 842                  base::Passed(&data_reduction_proxy_data), net_error, | 
|  | 843                  url_request->GetTotalReceivedBytes(), | 
| 838                  url_request->GetRawBodyBytes(), original_content_length, | 844                  url_request->GetRawBodyBytes(), original_content_length, | 
| 839                  url_request->creation_time(), | 845                  url_request->creation_time(), | 
| 840                  base::TimeTicks::Now() - url_request->creation_time())); | 846                  base::TimeTicks::Now() - url_request->creation_time())); | 
| 841 } | 847 } | 
| 842 | 848 | 
| 843 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState( | 849 content::PreviewsState ChromeResourceDispatcherHostDelegate::GetPreviewsState( | 
| 844     const net::URLRequest& url_request, | 850     const net::URLRequest& url_request, | 
| 845     content::ResourceContext* resource_context) { | 851     content::ResourceContext* resource_context) { | 
| 846   ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 852   ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 
| 847   data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = | 853   data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data = | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 912           base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, | 918           base::Bind(&ChromeResourceDispatcherHostDelegate::OnAbortedFrameLoad, | 
| 913                     base::Unretained(this), url, request_loading_time)); | 919                     base::Unretained(this), url, request_loading_time)); | 
| 914       return; | 920       return; | 
| 915   } | 921   } | 
| 916 | 922 | 
| 917   std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? | 923   std::string metric_name = (request_loading_time.InMilliseconds() < 100 ? | 
| 918       "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); | 924       "Net.ErrAborted.Fast" : "Net.ErrAborted.Slow"); | 
| 919   rappor::SampleDomainAndRegistryFromGURL( | 925   rappor::SampleDomainAndRegistryFromGURL( | 
| 920       g_browser_process->rappor_service(), metric_name, url); | 926       g_browser_process->rappor_service(), metric_name, url); | 
| 921 } | 927 } | 
| OLD | NEW | 
|---|