OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/predictors/resource_prefetch_predictor_tab_helper.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor_tab_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/predictors/loading_predictor.h" | 9 #include "chrome/browser/predictors/loading_predictor.h" |
10 #include "chrome/browser/predictors/loading_predictor_factory.h" | 10 #include "chrome/browser/predictors/loading_predictor_factory.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 void ResourcePrefetchPredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { | 29 void ResourcePrefetchPredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { |
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
31 | 31 |
32 auto* loading_predictor = LoadingPredictorFactory::GetForProfile( | 32 auto* loading_predictor = LoadingPredictorFactory::GetForProfile( |
33 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 33 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
34 if (!loading_predictor) | 34 if (!loading_predictor) |
35 return; | 35 return; |
36 | 36 |
37 auto* resource_prefetch_predictor = | 37 auto* collector = loading_predictor->loading_data_collector(); |
38 loading_predictor->resource_prefetch_predictor(); | |
39 NavigationID navigation_id(web_contents()); | 38 NavigationID navigation_id(web_contents()); |
40 resource_prefetch_predictor->RecordMainFrameLoadComplete(navigation_id); | 39 collector->RecordMainFrameLoadComplete(navigation_id); |
41 } | 40 } |
42 | 41 |
43 void ResourcePrefetchPredictorTabHelper::DidLoadResourceFromMemoryCache( | 42 void ResourcePrefetchPredictorTabHelper::DidLoadResourceFromMemoryCache( |
44 const GURL& url, | 43 const GURL& url, |
45 const std::string& mime_type, | 44 const std::string& mime_type, |
46 content::ResourceType resource_type) { | 45 content::ResourceType resource_type) { |
47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
48 | 47 |
49 auto* loading_predictor = LoadingPredictorFactory::GetForProfile( | 48 auto* loading_predictor = LoadingPredictorFactory::GetForProfile( |
50 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 49 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
51 if (!loading_predictor) | 50 if (!loading_predictor) |
52 return; | 51 return; |
53 | 52 |
54 ResourcePrefetchPredictor::URLRequestSummary summary; | 53 ResourcePrefetchPredictor::URLRequestSummary summary; |
55 summary.navigation_id = NavigationID(web_contents()); | 54 summary.navigation_id = NavigationID(web_contents()); |
56 summary.resource_url = url; | 55 summary.resource_url = url; |
57 summary.mime_type = mime_type; | 56 summary.mime_type = mime_type; |
58 summary.resource_type = | 57 summary.resource_type = |
59 ResourcePrefetchPredictor::GetResourceTypeFromMimeType( | 58 ResourcePrefetchPredictor::GetResourceTypeFromMimeType( |
60 mime_type, resource_type); | 59 mime_type, resource_type); |
61 summary.was_cached = true; | 60 summary.was_cached = true; |
62 auto* resource_prefetch_predictor = | 61 auto* collector = loading_predictor->loading_data_collector(); |
63 loading_predictor->resource_prefetch_predictor(); | 62 collector->RecordURLResponse(summary); |
64 resource_prefetch_predictor->RecordURLResponse(summary); | |
65 } | 63 } |
66 | 64 |
67 } // namespace predictors | 65 } // namespace predictors |
OLD | NEW |