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 void UpdateScore(); |
| 31 |
| 32 GURL main_frame_url_; |
| 33 GURL resource_url_; |
| 34 ResourceType::Type resource_type_; |
| 35 int number_of_hits_; |
| 36 int number_of_misses_; |
| 37 int consecutive_misses_; |
| 38 double average_position_; |
| 39 |
| 40 // Not stored. |
| 41 float score_; |
| 42 }; |
| 43 |
| 44 // Sorts the UrlTableRows by score, descending. |
| 45 struct UrlTableRowSorter { |
| 46 bool operator()(const UrlTableRow& x, const UrlTableRow& y) const; |
| 47 }; |
| 48 |
| 49 void GetAllRows(std::vector<UrlTableRow>* url_row_buffer); |
| 50 void UpdateRowsForUrl(const GURL& main_page_url, |
| 51 const std::vector<UrlTableRow>& row_buffer); |
| 52 void DeleteUrlRows(const std::vector<GURL>& urls); |
| 53 |
| 54 private: |
| 55 friend class PredictorDatabaseInternal; |
| 56 |
| 57 ResourcePrefetchPredictorTables(); |
| 58 virtual ~ResourcePrefetchPredictorTables(); |
| 59 |
| 60 // PredictorTableBase methods. |
| 61 virtual void CreateTableIfNonExistent() OVERRIDE; |
| 62 virtual void LogDatabaseStats() OVERRIDE; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); |
| 65 }; |
| 66 |
| 67 } // namespace predictors |
| 68 |
| 69 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |
OLD | NEW |