OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ | |
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ | |
7 #pragma once | |
8 | |
9 #include "chrome/browser/predictors/predictor_table_base.h" | |
10 | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "googleurl/src/gurl.h" | |
15 #include "webkit/glue/resource_type.h" | |
16 | |
17 namespace predictors { | |
18 | |
19 // Interface for database tables used by the ResourcePrefetchPredictor. | |
20 // All methods except the constructor and destructor need to be called on the DB | |
21 // thread. | |
22 // NOTE: This class is named in plural as it will hold other tables shortly. | |
23 // | |
24 // TODO(shishir): Move to composition model instead of implemented inheritance. | |
25 class ResourcePrefetchPredictorTables : public PredictorTableBase { | |
26 public: | |
27 struct UrlTableRow { | |
28 UrlTableRow(); | |
29 UrlTableRow(const UrlTableRow& other); | |
30 UrlTableRow(const std::string& main_frame_url, | |
31 const std::string& resource_url, | |
32 ResourceType::Type resource_type, | |
33 int number_of_hits, | |
34 int number_of_misses, | |
35 int consecutive_misses, | |
36 double average_position); | |
37 void UpdateScore(); | |
38 bool operator==(const UrlTableRow& rhs) const; | |
39 | |
40 GURL main_frame_url; | |
41 GURL resource_url; | |
42 ResourceType::Type resource_type; | |
43 int number_of_hits; | |
44 int number_of_misses; | |
45 int consecutive_misses; | |
46 double average_position; | |
47 | |
48 // Not stored. | |
49 float score; | |
50 }; | |
51 typedef std::vector<UrlTableRow> UrlTableRows; | |
52 | |
53 // Sorts the UrlTableRows by score, descending. | |
54 struct UrlTableRowSorter { | |
55 bool operator()(const UrlTableRow& x, const UrlTableRow& y) const; | |
56 }; | |
57 | |
58 // |url_row_buffer| should be empty for GetAllRows. | |
59 virtual void GetAllRows(UrlTableRows* url_row_buffer); | |
60 virtual void UpdateRowsForUrl(const GURL& main_page_url, | |
61 const UrlTableRows& row_buffer); | |
62 virtual void DeleteRowsForUrls(const std::vector<GURL>& urls); | |
63 virtual void DeleteAllRows(); | |
64 | |
65 private: | |
66 friend class PredictorDatabaseInternal; | |
willchan no longer on Chromium
2012/06/18 20:15:12
I'm surprised at this use of a friend declaration.
Shishir
2012/06/18 20:38:33
This is to give the PredictorDatabaseInternal acce
willchan no longer on Chromium
2012/06/19 00:38:26
Why the constructor? What harm will happen from so
| |
67 friend class MockResourcePrefetchPredictorTables; | |
68 | |
69 ResourcePrefetchPredictorTables(); | |
70 virtual ~ResourcePrefetchPredictorTables(); | |
71 | |
72 // PredictorTableBase methods. | |
73 virtual void CreateTableIfNonExistent() OVERRIDE; | |
74 virtual void LogDatabaseStats() OVERRIDE; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); | |
77 }; | |
78 | |
79 } // namespace predictors | |
80 | |
81 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ | |
OLD | NEW |