OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/loading_predictor.h" | 5 #include "chrome/browser/predictors/loading_predictor.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "chrome/browser/predictors/loading_data_collector.h" |
9 #include "chrome/browser/predictors/loading_stats_collector.h" | 10 #include "chrome/browser/predictors/loading_stats_collector.h" |
10 #include "chrome/browser/predictors/resource_prefetch_common.h" | 11 #include "chrome/browser/predictors/resource_prefetch_common.h" |
11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 12 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
12 | 13 |
13 namespace predictors { | 14 namespace predictors { |
14 | 15 |
15 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 16 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
16 | 17 |
17 LoadingPredictor::LoadingPredictor(const LoadingPredictorConfig& config, | 18 LoadingPredictor::LoadingPredictor(const LoadingPredictorConfig& config, |
18 Profile* profile) | 19 Profile* profile) |
19 : config_(config), | 20 : config_(config), |
20 profile_(profile), | 21 profile_(profile), |
21 resource_prefetch_predictor_( | 22 resource_prefetch_predictor_( |
22 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)), | 23 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)), |
23 stats_collector_(base::MakeUnique<LoadingStatsCollector>( | 24 stats_collector_(base::MakeUnique<LoadingStatsCollector>( |
24 resource_prefetch_predictor_.get(), | 25 resource_prefetch_predictor_.get(), |
25 config)) { | 26 config)), |
| 27 loading_data_collector_(base::MakeUnique<LoadingDataCollector>( |
| 28 resource_prefetch_predictor())) { |
26 resource_prefetch_predictor_->SetStatsCollector(stats_collector_.get()); | 29 resource_prefetch_predictor_->SetStatsCollector(stats_collector_.get()); |
27 } | 30 } |
28 | 31 |
29 LoadingPredictor::~LoadingPredictor() = default; | 32 LoadingPredictor::~LoadingPredictor() = default; |
30 | 33 |
31 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) { | 34 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) { |
32 if (active_hints_.find(url) != active_hints_.end()) | 35 if (active_hints_.find(url) != active_hints_.end()) |
33 return; | 36 return; |
34 ResourcePrefetchPredictor::Prediction prediction; | 37 ResourcePrefetchPredictor::Prediction prediction; |
35 if (!resource_prefetch_predictor_->GetPrefetchData(url, &prediction)) | 38 if (!resource_prefetch_predictor_->GetPrefetchData(url, &prediction)) |
36 return; | 39 return; |
37 | 40 |
38 // To report hint durations. | 41 // To report hint durations. |
39 active_hints_.emplace(url, base::TimeTicks::Now()); | 42 active_hints_.emplace(url, base::TimeTicks::Now()); |
40 | 43 |
41 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) | 44 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) |
42 resource_prefetch_predictor_->StartPrefetching(url, prediction); | 45 resource_prefetch_predictor_->StartPrefetching(url, prediction); |
43 } | 46 } |
44 | 47 |
45 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { | 48 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { |
46 CancelActiveHint(active_hints_.find(url)); | 49 CancelActiveHint(active_hints_.find(url)); |
47 } | 50 } |
48 | 51 |
49 void LoadingPredictor::StartInitialization() { | 52 void LoadingPredictor::StartInitialization() { |
50 resource_prefetch_predictor_->StartInitialization(); | 53 resource_prefetch_predictor_->StartInitialization(); |
51 } | 54 } |
52 | 55 |
53 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor() | 56 LoadingDataCollector* LoadingPredictor::loading_data_collector() { |
54 const { | 57 return loading_data_collector_.get(); |
| 58 } |
| 59 |
| 60 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor() { |
55 return resource_prefetch_predictor_.get(); | 61 return resource_prefetch_predictor_.get(); |
56 } | 62 } |
57 | 63 |
58 void LoadingPredictor::Shutdown() { | 64 void LoadingPredictor::Shutdown() { |
59 resource_prefetch_predictor_->Shutdown(); | 65 resource_prefetch_predictor_->Shutdown(); |
60 } | 66 } |
61 | 67 |
62 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) { | 68 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) { |
63 DCHECK(summary.resource_type == content::RESOURCE_TYPE_MAIN_FRAME); | 69 DCHECK(summary.resource_type == content::RESOURCE_TYPE_MAIN_FRAME); |
64 | 70 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const GURL& initial_url = it->second; | 142 const GURL& initial_url = it->second; |
137 CancelActiveHint(active_hints_.find(initial_url)); | 143 CancelActiveHint(active_hints_.find(initial_url)); |
138 it = active_navigations_.erase(it); | 144 it = active_navigations_.erase(it); |
139 } else { | 145 } else { |
140 ++it; | 146 ++it; |
141 } | 147 } |
142 } | 148 } |
143 } | 149 } |
144 | 150 |
145 } // namespace predictors | 151 } // namespace predictors |
OLD | NEW |