OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_predictor_test_util.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
6 | 6 |
7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
8 | 8 |
9 namespace predictors { | 9 namespace predictors { |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 RedirectData CreateRedirectData(const std::string& primary_key, | 55 RedirectData CreateRedirectData(const std::string& primary_key, |
56 uint64_t last_visit_time) { | 56 uint64_t last_visit_time) { |
57 RedirectData data; | 57 RedirectData data; |
58 data.set_primary_key(primary_key); | 58 data.set_primary_key(primary_key); |
59 data.set_last_visit_time(last_visit_time); | 59 data.set_last_visit_time(last_visit_time); |
60 return data; | 60 return data; |
61 } | 61 } |
62 | 62 |
63 NavigationID CreateNavigationID(int process_id, | 63 NavigationID CreateNavigationID(int session_id, |
64 int render_frame_id, | |
65 const std::string& main_frame_url) { | 64 const std::string& main_frame_url) { |
66 NavigationID navigation_id; | 65 NavigationID navigation_id; |
67 navigation_id.render_process_id = process_id; | 66 navigation_id.session_id.set_id(session_id); |
68 navigation_id.render_frame_id = render_frame_id; | |
69 navigation_id.main_frame_url = GURL(main_frame_url); | 67 navigation_id.main_frame_url = GURL(main_frame_url); |
70 navigation_id.creation_time = base::TimeTicks::Now(); | 68 navigation_id.creation_time = base::TimeTicks::Now(); |
71 return navigation_id; | 69 return navigation_id; |
72 } | 70 } |
73 | 71 |
74 PageRequestSummary CreatePageRequestSummary( | 72 PageRequestSummary CreatePageRequestSummary( |
75 const std::string& main_frame_url, | 73 const std::string& main_frame_url, |
76 const std::string& initial_url, | 74 const std::string& initial_url, |
77 const std::vector<URLRequestSummary>& subresource_requests) { | 75 const std::vector<URLRequestSummary>& subresource_requests) { |
78 GURL main_frame_gurl(main_frame_url); | 76 GURL main_frame_gurl(main_frame_url); |
79 PageRequestSummary summary(main_frame_gurl); | 77 PageRequestSummary summary(main_frame_gurl); |
80 summary.initial_url = GURL(initial_url); | 78 summary.initial_url = GURL(initial_url); |
81 summary.subresource_requests = subresource_requests; | 79 summary.subresource_requests = subresource_requests; |
82 return summary; | 80 return summary; |
83 } | 81 } |
84 | 82 |
85 URLRequestSummary CreateURLRequestSummary(int process_id, | 83 URLRequestSummary CreateURLRequestSummary(int tab_id, |
86 int render_frame_id, | |
87 const std::string& main_frame_url, | 84 const std::string& main_frame_url, |
88 const std::string& resource_url, | 85 const std::string& resource_url, |
89 content::ResourceType resource_type, | 86 content::ResourceType resource_type, |
90 net::RequestPriority priority, | 87 net::RequestPriority priority, |
91 const std::string& mime_type, | 88 const std::string& mime_type, |
92 bool was_cached, | 89 bool was_cached, |
93 const std::string& redirect_url, | 90 const std::string& redirect_url, |
94 bool has_validators, | 91 bool has_validators, |
95 bool always_revalidate) { | 92 bool always_revalidate) { |
96 URLRequestSummary summary; | 93 URLRequestSummary summary; |
97 summary.navigation_id = | 94 summary.navigation_id = CreateNavigationID(tab_id, main_frame_url); |
98 CreateNavigationID(process_id, render_frame_id, main_frame_url); | |
99 summary.resource_url = | 95 summary.resource_url = |
100 resource_url.empty() ? GURL(main_frame_url) : GURL(resource_url); | 96 resource_url.empty() ? GURL(main_frame_url) : GURL(resource_url); |
101 summary.resource_type = resource_type; | 97 summary.resource_type = resource_type; |
102 summary.priority = priority; | 98 summary.priority = priority; |
103 summary.mime_type = mime_type; | 99 summary.mime_type = mime_type; |
104 summary.was_cached = was_cached; | 100 summary.was_cached = was_cached; |
105 if (!redirect_url.empty()) | 101 if (!redirect_url.empty()) |
106 summary.redirect_url = GURL(redirect_url); | 102 summary.redirect_url = GURL(redirect_url); |
107 summary.has_validators = has_validators; | 103 summary.has_validators = has_validators; |
108 summary.always_revalidate = always_revalidate; | 104 summary.always_revalidate = always_revalidate; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 147 |
152 std::ostream& operator<<(std::ostream& os, const URLRequestSummary& summary) { | 148 std::ostream& operator<<(std::ostream& os, const URLRequestSummary& summary) { |
153 return os << "[" << summary.navigation_id << "," << summary.resource_url | 149 return os << "[" << summary.navigation_id << "," << summary.resource_url |
154 << "," << summary.resource_type << "," << summary.priority << "," | 150 << "," << summary.resource_type << "," << summary.priority << "," |
155 << summary.mime_type << "," << summary.was_cached << "," | 151 << summary.mime_type << "," << summary.was_cached << "," |
156 << summary.redirect_url << "," << summary.has_validators << "," | 152 << summary.redirect_url << "," << summary.has_validators << "," |
157 << summary.always_revalidate << "]"; | 153 << summary.always_revalidate << "]"; |
158 } | 154 } |
159 | 155 |
160 std::ostream& operator<<(std::ostream& os, const NavigationID& navigation_id) { | 156 std::ostream& operator<<(std::ostream& os, const NavigationID& navigation_id) { |
161 return os << navigation_id.render_process_id << "," | 157 return os << navigation_id.session_id.id() << "," |
162 << navigation_id.render_frame_id << "," | |
163 << navigation_id.main_frame_url; | 158 << navigation_id.main_frame_url; |
164 } | 159 } |
165 | 160 |
| 161 std::ostream& operator<<( |
| 162 std::ostream& os, |
| 163 const std::map<NavigationID, std::unique_ptr<PageRequestSummary>>& map) { |
| 164 os << "Navigation Map, " << map.size() << " elements" << std::endl; |
| 165 int i = 0; |
| 166 for (auto nav_it = map.begin(); nav_it != map.end(); ++nav_it, ++i) |
| 167 os << "Element " << i << ": " << nav_it->first << std::endl; |
| 168 return os; |
| 169 } |
| 170 |
166 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { | 171 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { |
167 bool equal = lhs.primary_key() == rhs.primary_key() && | 172 bool equal = lhs.primary_key() == rhs.primary_key() && |
168 lhs.resources_size() == rhs.resources_size(); | 173 lhs.resources_size() == rhs.resources_size(); |
169 | 174 |
170 if (!equal) | 175 if (!equal) |
171 return false; | 176 return false; |
172 | 177 |
173 for (int i = 0; i < lhs.resources_size(); ++i) | 178 for (int i = 0; i < lhs.resources_size(); ++i) |
174 equal = equal && lhs.resources(i) == rhs.resources(i); | 179 equal = equal && lhs.resources(i) == rhs.resources(i); |
175 | 180 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 lhs.resource_url == rhs.resource_url && | 224 lhs.resource_url == rhs.resource_url && |
220 lhs.resource_type == rhs.resource_type && | 225 lhs.resource_type == rhs.resource_type && |
221 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && | 226 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && |
222 lhs.was_cached == rhs.was_cached && | 227 lhs.was_cached == rhs.was_cached && |
223 lhs.redirect_url == rhs.redirect_url && | 228 lhs.redirect_url == rhs.redirect_url && |
224 lhs.has_validators == rhs.has_validators && | 229 lhs.has_validators == rhs.has_validators && |
225 lhs.always_revalidate == rhs.always_revalidate; | 230 lhs.always_revalidate == rhs.always_revalidate; |
226 } | 231 } |
227 | 232 |
228 } // namespace predictors | 233 } // namespace predictors |
OLD | NEW |