OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ | 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ | 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <map> | 10 #include <map> |
| 11 #include <vector> |
9 | 12 |
10 #include "base/macros.h" | 13 #include "base/macros.h" |
11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
12 #include "url/gurl.h" | 15 #include "url/gurl.h" |
13 | 16 |
14 namespace sql { | 17 namespace sql { |
15 class Connection; | 18 class Connection; |
16 } | 19 } |
17 | 20 |
18 namespace precache { | 21 namespace precache { |
19 | 22 |
20 // Interface for database table that keeps track of the URLs that have been | 23 // Interface for database table that keeps track of the URLs that have been |
21 // precached but not used. This table is used to count how many bytes were saved | 24 // precached but not used. This table is used to count how many bytes were saved |
22 // by precached resources. | 25 // by precached resources. |
23 // Each row in this table represents a URL that was precached over the network, | 26 // Each row in this table represents a URL that was precached over the network, |
24 // and has not been fetched through user browsing since then. | 27 // and has not been fetched through user browsing since then. |
25 // Manages one table { URL (primary key), precache timestamp }. | 28 // Manages one table { URL (primary key), precache timestamp }. |
26 class PrecacheURLTable { | 29 class PrecacheURLTable { |
27 public: | 30 public: |
28 PrecacheURLTable(); | 31 PrecacheURLTable(); |
29 ~PrecacheURLTable(); | 32 ~PrecacheURLTable(); |
30 | 33 |
31 // Initialize the precache URL table for use with the specified database | 34 // Initialize the precache URL table for use with the specified database |
32 // connection. The caller keeps ownership of |db|, and |db| must not be NULL. | 35 // connection. The caller keeps ownership of |db|, and |db| must not be NULL. |
33 // Init must be called before any other methods. | 36 // Init must be called before any other methods. |
34 bool Init(sql::Connection* db); | 37 bool Init(sql::Connection* db); |
35 | 38 |
36 // Adds a precached URL to the table, using the current time as the | 39 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host |
37 // precache timestamp. Replaces the row if one already exists. | 40 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is |
38 void AddURL(const GURL& url, const base::Time& precache_time); | 41 // precached, |time| is the timestamp. Replaces the row if one already exists. |
| 42 void AddURL(const GURL& url, |
| 43 int64_t referrer_host_id, |
| 44 bool is_precached, |
| 45 const base::Time& precache_time); |
39 | 46 |
40 // Returns true if this URL exists in the table. | 47 // Returns true if the url is precached. |
41 bool HasURL(const GURL& url); | 48 bool IsURLPrecached(const GURL& url); |
42 | 49 |
43 // Deletes the row from the table that has the given URL, if it exists. | 50 // Returns true if the url is precached, and was not used before. |
44 void DeleteURL(const GURL& url); | 51 bool IsURLPrecachedAndUnused(const GURL& url); |
| 52 |
| 53 // Sets the precached URL as used. |
| 54 void SetPrecachedURLAsUsed(const GURL& url); |
| 55 |
| 56 // Set the previously precached URL as not precached, during user browsing. |
| 57 void SetURLAsNotPrecached(const GURL& url); |
| 58 |
| 59 // Populates the used and unused resource URLs for the referrer host with id |
| 60 // |referrer_host_id|. |
| 61 void GetURLListForReferrerHost(int64_t referrer_host_id, |
| 62 std::vector<GURL>* used_urls, |
| 63 std::vector<GURL>* unused_urls); |
45 | 64 |
46 // Deletes entries that were precached before the time of |delete_end|. | 65 // Deletes entries that were precached before the time of |delete_end|. |
47 void DeleteAllPrecachedBefore(const base::Time& delete_end); | 66 void DeleteAllPrecachedBefore(const base::Time& delete_end); |
48 | 67 |
| 68 // Deletes entries for the referrer host |referrer_host_id|. |
| 69 void DeleteAllForReferrerHost(int64_t referrer_host_id); |
| 70 |
49 // Delete all entries. | 71 // Delete all entries. |
50 void DeleteAll(); | 72 void DeleteAll(); |
51 | 73 |
52 // Used by tests to get the contents of the table. | 74 // Used by tests to get the contents of the table. |
53 void GetAllDataForTesting(std::map<GURL, base::Time>* map); | 75 void GetAllDataForTesting(std::map<GURL, base::Time>* map); |
54 | 76 |
55 private: | 77 private: |
56 bool CreateTableIfNonExistent(); | 78 bool CreateTableIfNonExistent(); |
57 | 79 |
58 // Non-owned pointer. | 80 // Non-owned pointer. |
59 sql::Connection* db_; | 81 sql::Connection* db_; |
60 | 82 |
61 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); | 83 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); |
62 }; | 84 }; |
63 | 85 |
64 } // namespace precache | 86 } // namespace precache |
65 | 87 |
66 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ | 88 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
OLD | NEW |