| 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_stats_collector.h" | 9 #include "chrome/browser/predictors/loading_stats_collector.h" |
| 10 #include "chrome/browser/predictors/resource_prefetch_common.h" | 10 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)), | 22 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)), |
| 23 stats_collector_(base::MakeUnique<LoadingStatsCollector>( | 23 stats_collector_(base::MakeUnique<LoadingStatsCollector>( |
| 24 resource_prefetch_predictor_.get(), | 24 resource_prefetch_predictor_.get(), |
| 25 config)) { | 25 config)) { |
| 26 resource_prefetch_predictor_->SetStatsCollector(stats_collector_.get()); | 26 resource_prefetch_predictor_->SetStatsCollector(stats_collector_.get()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 LoadingPredictor::~LoadingPredictor() = default; | 29 LoadingPredictor::~LoadingPredictor() = default; |
| 30 | 30 |
| 31 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) { | 31 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) { |
| 32 if (active_hints_.find(url) != active_hints_.end() || | 32 if (active_hints_.find(url) != active_hints_.end()) |
| 33 !resource_prefetch_predictor_->IsUrlPrefetchable(url)) | 33 return; |
| 34 ResourcePrefetchPredictor::Prediction prediction; |
| 35 if (!resource_prefetch_predictor_->GetPrefetchData(url, &prediction)) |
| 34 return; | 36 return; |
| 35 | 37 |
| 36 // To report hint durations. | 38 // To report hint durations. |
| 37 active_hints_.emplace(url, base::TimeTicks::Now()); | 39 active_hints_.emplace(url, base::TimeTicks::Now()); |
| 38 | 40 |
| 39 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) | 41 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) |
| 40 resource_prefetch_predictor_->StartPrefetching(url); | 42 resource_prefetch_predictor_->StartPrefetching(url, prediction); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { | 45 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { |
| 44 CancelActiveHint(active_hints_.find(url)); | 46 CancelActiveHint(active_hints_.find(url)); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void LoadingPredictor::StartInitialization() { | 49 void LoadingPredictor::StartInitialization() { |
| 48 resource_prefetch_predictor_->StartInitialization(); | 50 resource_prefetch_predictor_->StartInitialization(); |
| 49 } | 51 } |
| 50 | 52 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 const GURL& initial_url = it->second; | 136 const GURL& initial_url = it->second; |
| 135 CancelActiveHint(active_hints_.find(initial_url)); | 137 CancelActiveHint(active_hints_.find(initial_url)); |
| 136 it = active_navigations_.erase(it); | 138 it = active_navigations_.erase(it); |
| 137 } else { | 139 } else { |
| 138 ++it; | 140 ++it; |
| 139 } | 141 } |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 | 144 |
| 143 } // namespace predictors | 145 } // namespace predictors |
| OLD | NEW |