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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_tables.h

Issue 2263243002: predictors: Store protobufs in the database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 4 years, 4 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 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/predictors/predictor_table_base.h" 16 #include "chrome/browser/predictors/predictor_table_base.h"
17 #include "chrome/browser/predictors/resource_prefetch_common.h" 17 #include "chrome/browser/predictors/resource_prefetch_common.h"
18 #include "chrome/browser/predictors/resource_prefetch_predictor.pb.h"
18 #include "content/public/common/resource_type.h" 19 #include "content/public/common/resource_type.h"
19 #include "net/base/request_priority.h" 20 #include "net/base/request_priority.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace sql { 23 namespace sql {
23 class Statement; 24 class Statement;
24 } 25 }
25 26
26 namespace predictors { 27 namespace predictors {
27 28
29 using chrome_browser_predictors::ResourceData;
30
28 // Interface for database tables used by the ResourcePrefetchPredictor. 31 // Interface for database tables used by the ResourcePrefetchPredictor.
29 // All methods except the constructor and destructor need to be called on the DB 32 // All methods except the constructor and destructor need to be called on the DB
30 // thread. 33 // thread.
31 // 34 //
32 // Currently manages: 35 // Currently manages:
33 // - UrlResourceTable - resources per Urls. 36 // - UrlResourceTable - resources per Urls.
34 // - UrlMetadataTable - misc data for Urls (like last visit time). 37 // - UrlMetadataTable - misc data for Urls (like last visit time).
35 // - HostResourceTable - resources per host. 38 // - HostResourceTable - resources per host.
36 // - HostMetadataTable - misc data for hosts. 39 // - HostMetadataTable - misc data for hosts.
37 class ResourcePrefetchPredictorTables : public PredictorTableBase { 40 class ResourcePrefetchPredictorTables : public PredictorTableBase {
38 public: 41 public:
39 // Used in the UrlResourceTable and HostResourceTable to store resources 42 // Used in the UrlResourceTable and HostResourceTable to store resources
40 // required for the page or host. 43 // required for the page or host.
41 struct ResourceRow { 44 struct ResourceRow {
42 ResourceRow(); 45 ResourceRow();
43 ResourceRow(const ResourceRow& other); 46 ResourceRow(const ResourceRow& other);
44 ResourceRow(const std::string& main_frame_url, 47 ResourceRow(const std::string& main_frame_url,
45 const std::string& resource_url, 48 const std::string& resource_url,
46 content::ResourceType resource_type, 49 content::ResourceType resource_type,
47 int number_of_hits, 50 int number_of_hits,
48 int number_of_misses, 51 int number_of_misses,
49 int consecutive_misses, 52 int consecutive_misses,
50 double average_position, 53 double average_position,
51 net::RequestPriority priority, 54 net::RequestPriority priority,
52 bool has_validators, 55 bool has_validators,
53 bool always_revalidate); 56 bool always_revalidate);
54 void UpdateScore(); 57 void UpdateScore();
55 bool operator==(const ResourceRow& rhs) const; 58 bool operator==(const ResourceRow& rhs) const;
59 static void FromProto(const ResourceData& proto, ResourceRow* row);
60 void ToProto(ResourceData* resource_data) const;
56 61
57 // Stores the host for host based data, main frame Url for the Url based 62 // Stores the host for host based data, main frame Url for the Url based
58 // data. This field is cleared for efficiency reasons and the code outside 63 // data. This field is cleared for efficiency reasons and the code outside
59 // this class should not assume it is set. 64 // this class should not assume it is set.
60 std::string primary_key; 65 std::string primary_key;
61 66
62 GURL resource_url; 67 GURL resource_url;
63 content::ResourceType resource_type; 68 content::ResourceType resource_type;
64 size_t number_of_hits; 69 size_t number_of_hits;
65 size_t number_of_misses; 70 size_t number_of_misses;
66 size_t consecutive_misses; 71 size_t consecutive_misses;
67 double average_position; 72 double average_position;
68 net::RequestPriority priority; 73 net::RequestPriority priority;
69 bool has_validators; 74 bool has_validators;
70 bool always_revalidate; 75 bool always_revalidate;
71 76
72 // Not stored. 77 // Not stored.
73 float score; 78 float score;
74 }; 79 };
75 typedef std::vector<ResourceRow> ResourceRows; 80 typedef std::vector<ResourceRow> ResourceRows;
76 81
77 // Sorts the ResourceRows by score, descending. 82 // Sorts the resource rows by score, decreasing.
78 struct ResourceRowSorter { 83 static void SortResourceRows(ResourceRows* rows);
79 bool operator()(const ResourceRow& x, const ResourceRow& y) const;
80 };
81 84
82 // Aggregated data for a Url or Host. Although the data differs slightly, we 85 // Aggregated data for a Url or Host. Although the data differs slightly, we
83 // store them in the same structure, because most of the fields are common and 86 // store them in the same structure, because most of the fields are common and
84 // it allows us to use the same functions. 87 // it allows us to use the same functions.
85 struct PrefetchData { 88 struct PrefetchData {
86 PrefetchData(PrefetchKeyType key_type, const std::string& primary_key); 89 PrefetchData(PrefetchKeyType key_type, const std::string& primary_key);
87 PrefetchData(const PrefetchData& other); 90 PrefetchData(const PrefetchData& other);
88 ~PrefetchData(); 91 ~PrefetchData();
89 bool operator==(const PrefetchData& rhs) const; 92 bool operator==(const PrefetchData& rhs) const;
90 93
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 sql::Statement* GetHostResourceUpdateStatement(); 165 sql::Statement* GetHostResourceUpdateStatement();
163 sql::Statement* GetHostMetadataDeleteStatement(); 166 sql::Statement* GetHostMetadataDeleteStatement();
164 sql::Statement* GetHostMetadataUpdateStatement(); 167 sql::Statement* GetHostMetadataUpdateStatement();
165 168
166 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); 169 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables);
167 }; 170 };
168 171
169 } // namespace predictors 172 } // namespace predictors
170 173
171 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ 174 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698