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

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

Issue 2587443002: predictors: Make speculative_prefetch_predictor work with PlzNavigate (Closed)
Patch Set: Removed Frame Tree Node Id Created 4 years 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 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_common.h" 5 #include "chrome/browser/predictors/resource_prefetch_common.h"
6 6
7 #include <string> 7 #include <string>
8 #include <tuple> 8 #include <tuple>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ResourcePrefetchPredictorConfig::LEARNING | 69 ResourcePrefetchPredictorConfig::LEARNING |
70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION | 70 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION |
71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; 71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
72 return true; 72 return true;
73 } 73 }
74 } 74 }
75 75
76 return false; 76 return false;
77 } 77 }
78 78
79 NavigationID::NavigationID() 79 NavigationID::NavigationID() {
80 : render_process_id(-1), 80 session_id.set_id(-1); // Invalid.
81 render_frame_id(-1) {
82 } 81 }
83 82
84 NavigationID::NavigationID(const NavigationID& other) 83 NavigationID::NavigationID(const NavigationID& other)
85 : render_process_id(other.render_process_id), 84 : session_id(other.session_id),
86 render_frame_id(other.render_frame_id),
87 main_frame_url(other.main_frame_url), 85 main_frame_url(other.main_frame_url),
88 creation_time(other.creation_time) { 86 creation_time(other.creation_time) {}
89 }
90 87
91 NavigationID::NavigationID(content::WebContents* web_contents) 88 NavigationID::NavigationID(content::WebContents* web_contents)
92 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), 89 : main_frame_url(web_contents->GetURL()),
93 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), 90 creation_time(base::TimeTicks::Now()) {
94 main_frame_url(web_contents->GetURL()) { 91 session_id.set_id(SessionTabHelper::IdForTab(web_contents));
Benoit L 2016/12/19 16:55:55 While the intent is clear here, it is still a bit
95 } 92 }
96 93
97 NavigationID::NavigationID(content::WebContents* web_contents, 94 NavigationID::NavigationID(content::WebContents* web_contents,
98 const GURL& main_frame_url, 95 const GURL& main_frame_url,
99 const base::TimeTicks& creation_time) 96 const base::TimeTicks& creation_time)
100 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), 97 : main_frame_url(main_frame_url), creation_time(creation_time) {
101 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), 98 session_id.set_id(SessionTabHelper::IdForTab(web_contents));
102 main_frame_url(main_frame_url), 99 }
103 creation_time(creation_time) {}
104 100
105 bool NavigationID::is_valid() const { 101 bool NavigationID::is_valid() const {
106 return render_process_id != -1 && render_frame_id != -1 && 102 return session_id.id() != -1 && !main_frame_url.is_empty();
107 !main_frame_url.is_empty();
108 } 103 }
109 104
110 bool NavigationID::operator<(const NavigationID& rhs) const { 105 bool NavigationID::operator<(const NavigationID& rhs) const {
111 DCHECK(is_valid() && rhs.is_valid()); 106 DCHECK(is_valid() && rhs.is_valid());
112 return std::tie(render_process_id, render_frame_id, main_frame_url) < 107 // Quick int copy to be able to use tie.
113 std::tie(rhs.render_process_id, rhs.render_frame_id, rhs.main_frame_url); 108 int id_lhs = session_id.id();
109 int id_rhs = rhs.session_id.id();
110 return std::tie(id_lhs, main_frame_url) <
111 std::tie(id_rhs, rhs.main_frame_url);
114 } 112 }
115 113
116 bool NavigationID::operator==(const NavigationID& rhs) const { 114 bool NavigationID::operator==(const NavigationID& rhs) const {
117 DCHECK(is_valid() && rhs.is_valid()); 115 DCHECK(is_valid() && rhs.is_valid());
118 return IsSameRenderer(rhs) && main_frame_url == rhs.main_frame_url; 116 return session_id.id() == rhs.session_id.id() &&
119 } 117 main_frame_url == rhs.main_frame_url;
120
121 bool NavigationID::IsSameRenderer(const NavigationID& other) const {
122 DCHECK(is_valid() && other.is_valid());
123 return render_process_id == other.render_process_id &&
124 render_frame_id == other.render_frame_id;
125 } 118 }
126 119
127 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig() 120 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig()
128 : mode(0), 121 : mode(0),
129 max_navigation_lifetime_seconds(60), 122 max_navigation_lifetime_seconds(60),
130 max_urls_to_track(500), 123 max_urls_to_track(500),
131 max_hosts_to_track(200), 124 max_hosts_to_track(200),
132 min_url_visit_count(2), 125 min_url_visit_count(2),
133 max_resources_per_entry(50), 126 max_resources_per_entry(50),
134 max_consecutive_misses(3), 127 max_consecutive_misses(3),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 176
184 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { 177 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const {
185 return max_resources_per_entry == 100; 178 return max_resources_per_entry == 100;
186 } 179 }
187 180
188 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { 181 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const {
189 return max_urls_to_track == 200 && max_hosts_to_track == 100; 182 return max_urls_to_track == 200 && max_hosts_to_track == 100;
190 } 183 }
191 184
192 } // namespace predictors 185 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698