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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 7 #include <string> |
8 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 8 |
| 9 #include "chrome/browser/predictors/glowplug_predictor.h" |
| 10 #include "chrome/browser/predictors/glowplug_predictor_factory.h" |
9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
11 | 13 |
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
13 predictors::ResourcePrefetchPredictorTabHelper); | 15 predictors::ResourcePrefetchPredictorTabHelper); |
14 | 16 |
15 using content::BrowserThread; | 17 using content::BrowserThread; |
16 | 18 |
17 namespace predictors { | 19 namespace predictors { |
18 | 20 |
19 ResourcePrefetchPredictorTabHelper::ResourcePrefetchPredictorTabHelper( | 21 ResourcePrefetchPredictorTabHelper::ResourcePrefetchPredictorTabHelper( |
20 content::WebContents* web_contents) | 22 content::WebContents* web_contents) |
21 : content::WebContentsObserver(web_contents) { | 23 : content::WebContentsObserver(web_contents) { |
22 } | 24 } |
23 | 25 |
24 ResourcePrefetchPredictorTabHelper::~ResourcePrefetchPredictorTabHelper() { | 26 ResourcePrefetchPredictorTabHelper::~ResourcePrefetchPredictorTabHelper() { |
25 } | 27 } |
26 | 28 |
27 void ResourcePrefetchPredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { | 29 void ResourcePrefetchPredictorTabHelper::DocumentOnLoadCompletedInMainFrame() { |
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
29 | 31 |
30 ResourcePrefetchPredictor* predictor = | 32 auto* predictor = GlowplugPredictorFactory::GetForProfile( |
31 ResourcePrefetchPredictorFactory::GetForProfile( | 33 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
32 web_contents()->GetBrowserContext()); | |
33 if (!predictor) | 34 if (!predictor) |
34 return; | 35 return; |
35 | 36 |
| 37 auto* resource_prefetch_predictor = predictor->resource_prefetch_predictor(); |
36 NavigationID navigation_id(web_contents()); | 38 NavigationID navigation_id(web_contents()); |
37 predictor->RecordMainFrameLoadComplete(navigation_id); | 39 resource_prefetch_predictor->RecordMainFrameLoadComplete(navigation_id); |
38 } | 40 } |
39 | 41 |
40 void ResourcePrefetchPredictorTabHelper::DidLoadResourceFromMemoryCache( | 42 void ResourcePrefetchPredictorTabHelper::DidLoadResourceFromMemoryCache( |
41 const GURL& url, | 43 const GURL& url, |
42 const std::string& mime_type, | 44 const std::string& mime_type, |
43 content::ResourceType resource_type) { | 45 content::ResourceType resource_type) { |
44 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
45 | 47 |
46 ResourcePrefetchPredictor* predictor = | 48 auto* predictor = GlowplugPredictorFactory::GetForProfile( |
47 ResourcePrefetchPredictorFactory::GetForProfile( | 49 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
48 web_contents()->GetBrowserContext()); | |
49 if (!predictor) | 50 if (!predictor) |
50 return; | 51 return; |
51 | 52 |
52 ResourcePrefetchPredictor::URLRequestSummary summary; | 53 ResourcePrefetchPredictor::URLRequestSummary summary; |
53 summary.navigation_id = NavigationID(web_contents()); | 54 summary.navigation_id = NavigationID(web_contents()); |
54 summary.resource_url = url; | 55 summary.resource_url = url; |
55 summary.mime_type = mime_type; | 56 summary.mime_type = mime_type; |
56 summary.resource_type = | 57 summary.resource_type = |
57 ResourcePrefetchPredictor::GetResourceTypeFromMimeType( | 58 ResourcePrefetchPredictor::GetResourceTypeFromMimeType( |
58 mime_type, resource_type); | 59 mime_type, resource_type); |
59 summary.was_cached = true; | 60 summary.was_cached = true; |
60 predictor->RecordURLResponse(summary); | 61 auto* resource_prefetch_predictor = predictor->resource_prefetch_predictor(); |
| 62 resource_prefetch_predictor->RecordURLResponse(summary); |
61 } | 63 } |
62 | 64 |
63 } // namespace predictors | 65 } // namespace predictors |
OLD | NEW |