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

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

Issue 2357593002: Refactor the resource_prefetch_predictor. (Closed)
Patch Set: rebase 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
6
7 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
8
9 namespace predictors {
10
11 using PrefetchData = ResourcePrefetchPredictorTables::PrefetchData;
12
13 ResourceData CreateResourceData(const std::string& resource_url,
14 content::ResourceType resource_type,
15 int number_of_hits,
16 int number_of_misses,
17 int consecutive_misses,
18 double average_position,
19 net::RequestPriority priority,
20 bool has_validators,
21 bool always_revalidate) {
22 ResourceData resource;
23 resource.set_resource_url(resource_url);
24 resource.set_resource_type(
25 static_cast<ResourceData::ResourceType>(resource_type));
26 resource.set_number_of_hits(number_of_hits);
27 resource.set_number_of_misses(number_of_misses);
28 resource.set_consecutive_misses(consecutive_misses);
29 resource.set_average_position(average_position);
30 resource.set_priority(static_cast<ResourceData::Priority>(priority));
31 resource.set_has_validators(has_validators);
32 resource.set_always_revalidate(always_revalidate);
33 return resource;
34 }
35
36 void PrintTo(const ResourceData& resource, ::std::ostream* os) {
37 *os << "[" << resource.resource_url() << "," << resource.resource_type()
38 << "," << resource.number_of_hits() << "," << resource.number_of_misses()
39 << "," << resource.consecutive_misses() << ","
40 << resource.average_position() << "," << resource.priority() << ","
41 << resource.has_validators() << "," << resource.always_revalidate()
42 << "]";
43 }
44
45 void PrintTo(const PrefetchData& data, ::std::ostream* os) {
46 *os << "[" << data.key_type << "," << data.primary_key << ","
47 << data.last_visit.ToInternalValue() << "]\n";
48 for (const ResourceData& resource : data.resources) {
49 *os << "\t\t";
50 PrintTo(resource, os);
51 *os << "\n";
52 }
53 }
54
55 bool operator==(const ResourceData& lhs, const ResourceData& rhs) {
56 return lhs.resource_url() == rhs.resource_url() &&
57 lhs.resource_type() == rhs.resource_type() &&
58 lhs.number_of_hits() == rhs.number_of_hits() &&
59 lhs.number_of_misses() == rhs.number_of_misses() &&
60 lhs.consecutive_misses() == rhs.consecutive_misses() &&
61 lhs.average_position() == rhs.average_position() &&
62 lhs.priority() == rhs.priority() &&
63 lhs.has_validators() == rhs.has_validators() &&
64 lhs.always_revalidate() == rhs.always_revalidate();
65 }
66
67 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs) {
68 bool equal = lhs.key_type == rhs.key_type &&
69 lhs.primary_key == rhs.primary_key &&
70 lhs.resources.size() == rhs.resources.size();
71
72 if (!equal)
73 return false;
74
75 for (size_t i = 0; i < lhs.resources.size(); ++i)
76 equal = equal && lhs.resources[i] == rhs.resources[i];
77
78 return equal;
79 }
80
81 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698