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 <limits> |
| 8 |
7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 9 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
8 | 10 |
9 namespace predictors { | 11 namespace predictors { |
10 | 12 |
11 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 13 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
12 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 14 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
13 | 15 |
14 void InitializeResourceData(ResourceData* resource, | 16 void InitializeResourceData(ResourceData* resource, |
15 const std::string& resource_url, | 17 const std::string& resource_url, |
16 content::ResourceType resource_type, | 18 content::ResourceType resource_type, |
(...skipping 20 matching lines...) Expand all Loading... |
37 const std::string& url, | 39 const std::string& url, |
38 int number_of_hits, | 40 int number_of_hits, |
39 int number_of_misses, | 41 int number_of_misses, |
40 int consecutive_misses) { | 42 int consecutive_misses) { |
41 redirect->set_url(url); | 43 redirect->set_url(url); |
42 redirect->set_number_of_hits(number_of_hits); | 44 redirect->set_number_of_hits(number_of_hits); |
43 redirect->set_number_of_misses(number_of_misses); | 45 redirect->set_number_of_misses(number_of_misses); |
44 redirect->set_consecutive_misses(consecutive_misses); | 46 redirect->set_consecutive_misses(consecutive_misses); |
45 } | 47 } |
46 | 48 |
| 49 void InitializePrecacheResource(precache::PrecacheResource* resource, |
| 50 const std::string& url, |
| 51 double weight_ratio) { |
| 52 resource->set_url(url); |
| 53 resource->set_weight_ratio(weight_ratio); |
| 54 } |
| 55 |
47 PrefetchData CreatePrefetchData(const std::string& primary_key, | 56 PrefetchData CreatePrefetchData(const std::string& primary_key, |
48 uint64_t last_visit_time) { | 57 uint64_t last_visit_time) { |
49 PrefetchData data; | 58 PrefetchData data; |
50 data.set_primary_key(primary_key); | 59 data.set_primary_key(primary_key); |
51 data.set_last_visit_time(last_visit_time); | 60 data.set_last_visit_time(last_visit_time); |
52 return data; | 61 return data; |
53 } | 62 } |
54 | 63 |
55 RedirectData CreateRedirectData(const std::string& primary_key, | 64 RedirectData CreateRedirectData(const std::string& primary_key, |
56 uint64_t last_visit_time) { | 65 uint64_t last_visit_time) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 lhs.resource_url == rhs.resource_url && | 222 lhs.resource_url == rhs.resource_url && |
214 lhs.resource_type == rhs.resource_type && | 223 lhs.resource_type == rhs.resource_type && |
215 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && | 224 lhs.priority == rhs.priority && lhs.mime_type == rhs.mime_type && |
216 lhs.was_cached == rhs.was_cached && | 225 lhs.was_cached == rhs.was_cached && |
217 lhs.redirect_url == rhs.redirect_url && | 226 lhs.redirect_url == rhs.redirect_url && |
218 lhs.has_validators == rhs.has_validators && | 227 lhs.has_validators == rhs.has_validators && |
219 lhs.always_revalidate == rhs.always_revalidate; | 228 lhs.always_revalidate == rhs.always_revalidate; |
220 } | 229 } |
221 | 230 |
222 } // namespace predictors | 231 } // namespace predictors |
| 232 |
| 233 namespace precache { |
| 234 |
| 235 std::ostream& operator<<(std::ostream& os, const PrecacheManifest& manifest) { |
| 236 os << "[" << manifest.id().id() << "]" << std::endl; |
| 237 for (const PrecacheResource& resource : manifest.resource()) |
| 238 os << "\t\t" << resource << std::endl; |
| 239 return os; |
| 240 } |
| 241 |
| 242 std::ostream& operator<<(std::ostream& os, const PrecacheResource& resource) { |
| 243 return os << "[" << resource.url() << "," << resource.top_host_name() << "," |
| 244 << resource.weight_ratio() << "," << resource.weight() << "]"; |
| 245 } |
| 246 |
| 247 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs) { |
| 248 bool equal = lhs.id().id() == rhs.id().id() && |
| 249 lhs.resource_size() == rhs.resource_size(); |
| 250 |
| 251 if (!equal) |
| 252 return false; |
| 253 |
| 254 for (int i = 0; i < lhs.resource_size(); ++i) |
| 255 equal = equal && lhs.resource(i) == rhs.resource(i); |
| 256 |
| 257 return equal; |
| 258 } |
| 259 |
| 260 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) { |
| 261 return lhs.url() == rhs.url() && |
| 262 std::fabs(lhs.weight_ratio() - rhs.weight_ratio()) < |
| 263 std::numeric_limits<double>::epsilon(); |
| 264 } |
| 265 |
| 266 } // namespace precache |
OLD | NEW |