Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/predictors/loading_predictor.cc

Issue 2896713003: Create LoadingDataCollector class and have observers rely on it instead of ResourcePrefetchPredictor (Closed)
Patch Set: Tests + rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/resource_prefetch_common.h" 10 #include "chrome/browser/predictors/resource_prefetch_common.h"
10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 11 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
11 12
12 namespace predictors { 13 namespace predictors {
13 14
14 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; 15 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
15 16
16 LoadingPredictor::LoadingPredictor(const LoadingPredictorConfig& config, 17 LoadingPredictor::LoadingPredictor(const LoadingPredictorConfig& config,
17 Profile* profile) 18 Profile* profile)
18 : config_(config), 19 : config_(config),
19 profile_(profile), 20 profile_(profile),
20 resource_prefetch_predictor_( 21 resource_prefetch_predictor_(
21 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)) {} 22 base::MakeUnique<ResourcePrefetchPredictor>(config, profile)),
23 loading_data_collector_(base::MakeUnique<LoadingDataCollector>(
24 resource_prefetch_predictor())) {}
22 25
23 LoadingPredictor::~LoadingPredictor() = default; 26 LoadingPredictor::~LoadingPredictor() = default;
24 27
25 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) { 28 void LoadingPredictor::PrepareForPageLoad(const GURL& url, HintOrigin origin) {
26 if (active_hints_.find(url) != active_hints_.end() || 29 if (active_hints_.find(url) != active_hints_.end() ||
27 !resource_prefetch_predictor_->IsUrlPrefetchable(url)) 30 !resource_prefetch_predictor_->IsUrlPrefetchable(url))
28 return; 31 return;
29 32
30 // To report hint durations. 33 // To report hint durations.
31 active_hints_.emplace(url, base::TimeTicks::Now()); 34 active_hints_.emplace(url, base::TimeTicks::Now());
32 35
33 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin)) 36 if (config_.IsPrefetchingEnabledForOrigin(profile_, origin))
34 resource_prefetch_predictor_->StartPrefetching(url); 37 resource_prefetch_predictor_->StartPrefetching(url);
35 } 38 }
36 39
37 void LoadingPredictor::CancelPageLoadHint(const GURL& url) { 40 void LoadingPredictor::CancelPageLoadHint(const GURL& url) {
38 CancelActiveHint(active_hints_.find(url)); 41 CancelActiveHint(active_hints_.find(url));
39 } 42 }
40 43
41 void LoadingPredictor::StartInitialization() { 44 void LoadingPredictor::StartInitialization() {
42 resource_prefetch_predictor_->StartInitialization(); 45 resource_prefetch_predictor_->StartInitialization();
43 } 46 }
44 47
48 LoadingDataCollector* LoadingPredictor::loading_data_collector() const {
49 return loading_data_collector_.get();
50 }
51
45 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor() 52 ResourcePrefetchPredictor* LoadingPredictor::resource_prefetch_predictor()
46 const { 53 const {
47 return resource_prefetch_predictor_.get(); 54 return resource_prefetch_predictor_.get();
48 } 55 }
49 56
50 void LoadingPredictor::Shutdown() { 57 void LoadingPredictor::Shutdown() {
51 resource_prefetch_predictor_->Shutdown(); 58 resource_prefetch_predictor_->Shutdown();
52 } 59 }
53 60
54 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) { 61 void LoadingPredictor::OnMainFrameRequest(const URLRequestSummary& summary) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 const GURL& initial_url = it->second; 135 const GURL& initial_url = it->second;
129 CancelActiveHint(active_hints_.find(initial_url)); 136 CancelActiveHint(active_hints_.find(initial_url));
130 it = active_navigations_.erase(it); 137 it = active_navigations_.erase(it);
131 } else { 138 } else {
132 ++it; 139 ++it;
133 } 140 }
134 } 141 }
135 } 142 }
136 143
137 } // namespace predictors 144 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698