OLD | NEW |
---|---|
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 Loading... | |
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() : frame_tree_node_id(-1) { |
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), | 85 frame_tree_node_id(other.frame_tree_node_id), |
87 main_frame_url(other.main_frame_url), | 86 main_frame_url(other.main_frame_url), |
88 creation_time(other.creation_time) { | 87 creation_time(other.creation_time) {} |
89 } | |
90 | 88 |
91 NavigationID::NavigationID(content::WebContents* web_contents) | 89 NavigationID::NavigationID(content::WebContents* web_contents) |
92 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), | 90 : frame_tree_node_id(web_contents->GetMainFrame()->GetFrameTreeNodeId()), |
93 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), | 91 main_frame_url(web_contents->GetURL()), |
94 main_frame_url(web_contents->GetURL()) { | 92 creation_time(base::TimeTicks::Now()) { |
93 session_id.set_id(SessionTabHelper::IdForTab(web_contents)); | |
95 } | 94 } |
96 | 95 |
97 NavigationID::NavigationID(content::WebContents* web_contents, | 96 NavigationID::NavigationID(content::WebContents* web_contents, |
98 const GURL& main_frame_url, | 97 const GURL& main_frame_url, |
99 const base::TimeTicks& creation_time) | 98 const base::TimeTicks& creation_time) |
100 : render_process_id(web_contents->GetRenderProcessHost()->GetID()), | 99 : frame_tree_node_id(web_contents->GetMainFrame()->GetFrameTreeNodeId()), |
101 render_frame_id(web_contents->GetMainFrame()->GetRoutingID()), | |
102 main_frame_url(main_frame_url), | 100 main_frame_url(main_frame_url), |
103 creation_time(creation_time) {} | 101 creation_time(creation_time) { |
102 session_id.set_id(SessionTabHelper::IdForTab(web_contents)); | |
103 } | |
104 | 104 |
105 bool NavigationID::is_valid() const { | 105 bool NavigationID::is_valid() const { |
106 return render_process_id != -1 && render_frame_id != -1 && | 106 return session_id.id() != -1 && !main_frame_url.is_empty(); |
ahemery
2016/12/19 14:53:41
frame_tree_node_id can be -1 and still be valid so
| |
107 !main_frame_url.is_empty(); | |
108 } | 107 } |
109 | 108 |
110 bool NavigationID::operator<(const NavigationID& rhs) const { | 109 bool NavigationID::operator<(const NavigationID& rhs) const { |
111 DCHECK(is_valid() && rhs.is_valid()); | 110 DCHECK(is_valid() && rhs.is_valid()); |
112 return std::tie(render_process_id, render_frame_id, main_frame_url) < | 111 // Quick int copy to be able to use tie. |
ahemery
2016/12/19 14:53:41
Tie uses lvalues
| |
113 std::tie(rhs.render_process_id, rhs.render_frame_id, rhs.main_frame_url); | 112 int id_lhs = session_id.id(); |
113 int id_rhs = rhs.session_id.id(); | |
114 return std::tie(id_lhs, frame_tree_node_id, main_frame_url) < | |
115 std::tie(id_rhs, rhs.frame_tree_node_id, rhs.main_frame_url); | |
114 } | 116 } |
115 | 117 |
116 bool NavigationID::operator==(const NavigationID& rhs) const { | 118 bool NavigationID::operator==(const NavigationID& rhs) const { |
117 DCHECK(is_valid() && rhs.is_valid()); | 119 DCHECK(is_valid() && rhs.is_valid()); |
118 return IsSameRenderer(rhs) && main_frame_url == rhs.main_frame_url; | 120 return IsSameLocation(rhs) && main_frame_url == rhs.main_frame_url; |
119 } | 121 } |
120 | 122 |
121 bool NavigationID::IsSameRenderer(const NavigationID& other) const { | 123 bool NavigationID::IsSameLocation(const NavigationID& other) const { |
122 DCHECK(is_valid() && other.is_valid()); | 124 DCHECK(is_valid() && other.is_valid()); |
123 return render_process_id == other.render_process_id && | 125 return session_id.id() == other.session_id.id() && |
124 render_frame_id == other.render_frame_id; | 126 frame_tree_node_id == other.frame_tree_node_id; |
125 } | 127 } |
126 | 128 |
127 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig() | 129 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig() |
128 : mode(0), | 130 : mode(0), |
129 max_navigation_lifetime_seconds(60), | 131 max_navigation_lifetime_seconds(60), |
130 max_urls_to_track(500), | 132 max_urls_to_track(500), |
131 max_hosts_to_track(200), | 133 max_hosts_to_track(200), |
132 min_url_visit_count(2), | 134 min_url_visit_count(2), |
133 max_resources_per_entry(50), | 135 max_resources_per_entry(50), |
134 max_consecutive_misses(3), | 136 max_consecutive_misses(3), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 | 185 |
184 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 186 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
185 return max_resources_per_entry == 100; | 187 return max_resources_per_entry == 100; |
186 } | 188 } |
187 | 189 |
188 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 190 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
189 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 191 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
190 } | 192 } |
191 | 193 |
192 } // namespace predictors | 194 } // namespace predictors |
OLD | NEW |