Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / precache / core / precache_url_table.h
blobedfc63179e8fc642519783d2ed364cc8cb9e6309
1 // Copyright 2013 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.
5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
12 #include "url/gurl.h"
14 namespace sql {
15 class Connection;
18 namespace precache {
20 // Interface for database table that keeps track of the URLs that have been
21 // precached but not used. Each row in this table represents a URL that was
22 // precached over the network, and has not been fetched through user browsing
23 // since then. Manages one table { URL (primary key), precache timestamp }.
24 class PrecacheURLTable {
25 public:
26 PrecacheURLTable();
27 ~PrecacheURLTable();
29 // Initialize the precache URL table for use with the specified database
30 // connection. The caller keeps ownership of |db|, and |db| must not be NULL.
31 // Init must be called before any other methods.
32 bool Init(sql::Connection* db);
34 // Adds a precached URL to the table, using the current time as the
35 // precache timestamp. Replaces the row if one already exists.
36 void AddURL(const GURL& url, const base::Time& precache_time);
38 // Returns true if this URL exists in the table.
39 bool HasURL(const GURL& url);
41 // Deletes the row from the table that has the given URL, if it exists.
42 void DeleteURL(const GURL& url);
44 // Deletes entries that were precached before the time of |delete_end|.
45 void DeleteAllPrecachedBefore(const base::Time& delete_end);
47 // Delete all entries.
48 void DeleteAll();
50 // Used by tests to get the contents of the table.
51 void GetAllDataForTesting(std::map<GURL, base::Time>* map);
53 private:
54 bool CreateTableIfNonExistent();
56 // Non-owned pointer.
57 sql::Connection* db_;
59 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable);
62 } // namespace precache
64 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_