Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor_tables.h |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables.h b/chrome/browser/predictors/resource_prefetch_predictor_tables.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e323907d338a9d60ba49b6029095c3da33d350b |
| --- /dev/null |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |
| +#define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |
| +#pragma once |
| + |
| +#include "chrome/browser/predictors/predictor_table_base.h" |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "googleurl/src/gurl.h" |
| +#include "webkit/glue/resource_type.h" |
| + |
| +namespace predictors { |
| + |
| +// Interface for database tables used by the ResourcePrefetchPredictor. |
| +// All methods except the constructor and destructor need to be called on the DB |
| +// thread. |
| +// NOTE: This class is named in plural as it will hold other tables shortly. |
| +// |
| +// TODO(shishir): Move to composition model instead of implemented inheritance. |
| +class ResourcePrefetchPredictorTables : public PredictorTableBase { |
| + public: |
| + struct UrlTableRow { |
| + UrlTableRow(); |
| + UrlTableRow(const UrlTableRow& other); |
| + UrlTableRow(const std::string& main_frame_url, |
| + const std::string& resource_url, |
| + ResourceType::Type resource_type, |
| + int number_of_hits, |
| + int number_of_misses, |
| + int consecutive_misses, |
| + double average_position); |
| + void UpdateScore(); |
| + bool operator==(const UrlTableRow& rhs) const; |
| + |
| + GURL main_frame_url; |
| + GURL resource_url; |
| + ResourceType::Type resource_type; |
| + int number_of_hits; |
| + int number_of_misses; |
| + int consecutive_misses; |
| + double average_position; |
| + |
| + // Not stored. |
| + float score; |
| + }; |
| + typedef std::vector<UrlTableRow> UrlTableRows; |
| + |
| + // Sorts the UrlTableRows by score, descending. |
| + struct UrlTableRowSorter { |
| + bool operator()(const UrlTableRow& x, const UrlTableRow& y) const; |
| + }; |
| + |
| + // |url_row_buffer| should be empty for GetAllRows. |
| + virtual void GetAllRows(UrlTableRows* url_row_buffer); |
| + virtual void UpdateRowsForUrl(const GURL& main_page_url, |
| + const UrlTableRows& row_buffer); |
| + virtual void DeleteRowsForUrls(const std::vector<GURL>& urls); |
| + virtual void DeleteAllRows(); |
| + |
| + private: |
| + 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
|
| + friend class MockResourcePrefetchPredictorTables; |
| + |
| + ResourcePrefetchPredictorTables(); |
| + virtual ~ResourcePrefetchPredictorTables(); |
| + |
| + // PredictorTableBase methods. |
| + virtual void CreateTableIfNonExistent() OVERRIDE; |
| + virtual void LogDatabaseStats() OVERRIDE; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTables); |
| +}; |
| + |
| +} // namespace predictors |
| + |
| +#endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TABLES_H_ |