Chromium Code Reviews| Index: components/precache/core/precache_url_table.h |
| diff --git a/components/precache/core/precache_url_table.h b/components/precache/core/precache_url_table.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..adbce1c38eca5dca6a0d6d3aab2ca43244738d3b |
| --- /dev/null |
| +++ b/components/precache/core/precache_url_table.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2013 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 COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
| +#define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/time/time.h" |
| +#include "url/gurl.h" |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace precache { |
| + |
| +// Interface for database table that keeps track of the URLs that have been |
| +// precached but not used. Each row in this table represents a URL that was |
| +// precached over the network, and has not been fetched through user browsing |
| +// since then. Manages one table { URL (primary key), precache timestamp }. |
| +class PrecacheURLTable { |
| + public: |
| + PrecacheURLTable(); |
| + ~PrecacheURLTable(); |
| + |
| + // Initialize the precache URL table for use with the specified database |
| + // connection. The caller keeps ownership of |db|, and |db| must not be NULL. |
| + // Init must be called before any other methods. |
| + void Init(sql::Connection* db); |
| + |
| + // Adds a precached URL to the table, using the current time as the |
| + // precache timestamp. Replaces the row if one already exists. |
| + void AddURL(const GURL& url, const base::Time& precache_time); |
| + |
| + // Returns true if this URL exists in the table. |
| + bool HasURL(const GURL& url); |
| + |
| + // Deletes the row from the table that has the given URL, if it exists. |
| + void DeleteURL(const GURL& url); |
| + |
| + // Deletes all records that were precached between the specified timestamps. |
| + void DeleteAllPrecachedBetween(const base::Time& delete_begin, |
| + const base::Time& delete_end); |
|
mmenke
2013/10/31 16:45:00
Do we really need to have these between functions?
sclittle
2013/11/06 01:51:42
Done.
|
| + |
| + // Used by tests to get the contents of the table. |
| + void GetAllDataForTesting(std::map<GURL, base::Time>* map); |
| + |
| + private: |
| + // Returns the spec of the given URL. |
| + static std::string GetKey(const GURL& url); |
| + |
| + void CreateTableIfNonExistent(); |
| + |
| + // Non-owned pointer. |
| + sql::Connection* db_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); |
| +}; |
| + |
| +} // namespace precache |
| + |
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |