| 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 !resource_prefetch_predictor_->IsUrlPrefetchable(url)) | 36 !resource_prefetch_predictor_->IsUrlPrefetchable(url)) |
| 34 return; | 37 return; |
| 35 | 38 |
| 36 // To report hint durations. | 39 // To report hint durations. |
| 37 active_hints_.emplace(url, base::TimeTicks::Now()); | 40 active_hints_.emplace(url, base::TimeTicks::Now()); |
| 38 | 41 |
| 39 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) | 42 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) |
| 40 resource_prefetch_predictor_->StartPrefetching(url); | 43 resource_prefetch_predictor_->StartPrefetching(url); |
| 41 } | 44 } |
| 42 | 45 |
| 43 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { | 46 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { |
| 44 CancelActiveHint(active_hints_.find(url)); | 47 CancelActiveHint(active_hints_.find(url)); |
| 45 } | 48 } |
| 46 | 49 |
| 47 void LoadingPredictor::StartInitialization() { | 50 void LoadingPredictor::StartInitialization() { |
| 48 resource_prefetch_predictor_->StartInitialization(); | 51 resource_prefetch_predictor_->StartInitialization(); |
| 49 } | 52 } |
| 50 | 53 |
| 54 LoadingDataCollector* LoadingPredictor::loading_data_collector() const { |
| 55 return loading_data_collector_.get(); |
| 56 } |
| 57 |
| 51 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor() | 58 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor() |
| 52 const { | 59 const { |
| 53 return resource_prefetch_predictor_.get(); | 60 return resource_prefetch_predictor_.get(); |
| 54 } | 61 } |
| 55 | 62 |
| 56 void LoadingPredictor::Shutdown() { | 63 void LoadingPredictor::Shutdown() { |
| 57 resource_prefetch_predictor_->Shutdown(); | 64 resource_prefetch_predictor_->Shutdown(); |
| 58 } | 65 } |
| 59 | 66 |
| 60 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) { | 67 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 const GURL& initial_url = it->second; | 141 const GURL& initial_url = it->second; |
| 135 CancelActiveHint(active_hints_.find(initial_url)); | 142 CancelActiveHint(active_hints_.find(initial_url)); |
| 136 it = active_navigations_.erase(it); | 143 it = active_navigations_.erase(it); |
| 137 } else { | 144 } else { |
| 138 ++it; | 145 ++it; |
| 139 } | 146 } |
| 140 } | 147 } |
| 141 } | 148 } |
| 142 | 149 |
| 143 } // namespace predictors | 150 } // namespace predictors |
| OLD | NEW |