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

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

Issue 2355273002: Redirect handling in the resource_prefetch_predictor. (Closed)
Patch Set: Minor changes Created 4 years, 3 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 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 15 matching lines...) Expand all
26 resource.set_number_of_hits(number_of_hits); 26 resource.set_number_of_hits(number_of_hits);
27 resource.set_number_of_misses(number_of_misses); 27 resource.set_number_of_misses(number_of_misses);
28 resource.set_consecutive_misses(consecutive_misses); 28 resource.set_consecutive_misses(consecutive_misses);
29 resource.set_average_position(average_position); 29 resource.set_average_position(average_position);
30 resource.set_priority(static_cast<ResourceData::Priority>(priority)); 30 resource.set_priority(static_cast<ResourceData::Priority>(priority));
31 resource.set_has_validators(has_validators); 31 resource.set_has_validators(has_validators);
32 resource.set_always_revalidate(always_revalidate); 32 resource.set_always_revalidate(always_revalidate);
33 return resource; 33 return resource;
34 } 34 }
35 35
36 void InitializeRedirectStat(RedirectStat* redirect,
37 const std::string& url,
38 int number_of_hits,
39 int number_of_misses,
40 int consecutive_misses) {
41 redirect->set_url(url);
42 redirect->set_number_of_hits(number_of_hits);
43 redirect->set_number_of_misses(number_of_misses);
44 redirect->set_consecutive_misses(consecutive_misses);
45 }
46
47 void PrintTo(const PrefetchData& data, ::std::ostream* os) {
48 *os << "[" << data.key_type << "," << data.primary_key << ","
49 << data.last_visit.ToInternalValue() << "]\n";
50 for (const ResourceData& resource : data.resources) {
51 *os << "\t\t";
52 chrome_browser_predictors::PrintTo(resource, os);
53 *os << "\n";
54 }
55 }
56
57 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) {
58 bool equal = lhs.key_type == rhs.key_type &&
59 lhs.primary_key == rhs.primary_key &&
60 lhs.resources.size() == rhs.resources.size();
61
62 if (!equal)
63 return false;
64
65 for (size_t i = 0; i < lhs.resources.size(); ++i)
66 equal = equal && lhs.resources[i] == rhs.resources[i];
67
68 return equal;
69 }
70
71 } // namespace predictors
72
73 namespace chrome_browser_predictors {
74
36 void PrintTo(const ResourceData& resource, ::std::ostream* os) { 75 void PrintTo(const ResourceData& resource, ::std::ostream* os) {
37 *os << "[" << resource.resource_url() << "," << resource.resource_type() 76 *os << "[" << resource.resource_url() << "," << resource.resource_type()
38 << "," << resource.number_of_hits() << "," << resource.number_of_misses() 77 << "," << resource.number_of_hits() << "," << resource.number_of_misses()
39 << "," << resource.consecutive_misses() << "," 78 << "," << resource.consecutive_misses() << ","
40 << resource.average_position() << "," << resource.priority() << "," 79 << resource.average_position() << "," << resource.priority() << ","
41 << resource.has_validators() << "," << resource.always_revalidate() 80 << resource.has_validators() << "," << resource.always_revalidate()
42 << "]"; 81 << "]";
43 } 82 }
44 83
45 void PrintTo(const PrefetchData& data, ::std::ostream* os) { 84 void PrintTo(const RedirectData_RedirectStat& redirect, ::std::ostream* os) {
46 *os << "[" << data.key_type << "," << data.primary_key << "," 85 *os << "[" << redirect.url() << "," << redirect.number_of_hits() << ","
47 << data.last_visit.ToInternalValue() << "]\n"; 86 << redirect.number_of_misses() << "," << redirect.consecutive_misses()
48 for (const ResourceData& resource : data.resources) { 87 << "]";
88 }
89
90 void PrintTo(const RedirectData& data, ::std::ostream* os) {
91 *os << "[" << data.primary_key() << "," << data.last_visit_time() << "]\n";
92 for (const RedirectData_RedirectStat& redirect : data.redirects()) {
49 *os << "\t\t"; 93 *os << "\t\t";
50 PrintTo(resource, os); 94 PrintTo(redirect, os);
51 *os << "\n"; 95 *os << "\n";
52 } 96 }
53 } 97 }
54 98
55 bool operator==(const ResourceData& lhs, const ResourceData& rhs) { 99 bool operator==(const ResourceData& lhs, const ResourceData& rhs) {
56 return lhs.resource_url() == rhs.resource_url() && 100 return lhs.resource_url() == rhs.resource_url() &&
57 lhs.resource_type() == rhs.resource_type() && 101 lhs.resource_type() == rhs.resource_type() &&
58 lhs.number_of_hits() == rhs.number_of_hits() && 102 lhs.number_of_hits() == rhs.number_of_hits() &&
59 lhs.number_of_misses() == rhs.number_of_misses() && 103 lhs.number_of_misses() == rhs.number_of_misses() &&
60 lhs.consecutive_misses() == rhs.consecutive_misses() && 104 lhs.consecutive_misses() == rhs.consecutive_misses() &&
61 lhs.average_position() == rhs.average_position() && 105 lhs.average_position() == rhs.average_position() &&
62 lhs.priority() == rhs.priority() && 106 lhs.priority() == rhs.priority() &&
63 lhs.has_validators() == rhs.has_validators() && 107 lhs.has_validators() == rhs.has_validators() &&
64 lhs.always_revalidate() == rhs.always_revalidate(); 108 lhs.always_revalidate() == rhs.always_revalidate();
65 } 109 }
66 110
67 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) { 111 bool operator==(const RedirectData_RedirectStat& lhs,
68 bool equal = lhs.key_type == rhs.key_type && 112 const RedirectData_RedirectStat& rhs) {
69 lhs.primary_key == rhs.primary_key && 113 return lhs.url() == rhs.url() &&
70 lhs.resources.size() == rhs.resources.size(); 114 lhs.number_of_hits() == rhs.number_of_hits() &&
115 lhs.number_of_misses() == rhs.number_of_misses() &&
116 lhs.consecutive_misses() == rhs.consecutive_misses();
117 }
118
119 bool operator==(const RedirectData& lhs, const RedirectData& rhs) {
120 bool equal = lhs.primary_key() == rhs.primary_key() &&
121 lhs.redirects_size() == rhs.redirects_size();
71 122
72 if (!equal) 123 if (!equal)
73 return false; 124 return false;
74 125
75 for (size_t i = 0; i < lhs.resources.size(); ++i) 126 for (int i = 0; i < lhs.redirects_size(); ++i)
76 equal = equal && lhs.resources[i] == rhs.resources[i]; 127 equal = equal && lhs.redirects(i) == rhs.redirects(i);
77 128
78 return equal; 129 return equal;
79 } 130 }
80 131
81 } // namespace predictors 132 } // namespace chrome_browser_predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698