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> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace sql { | 17 namespace sql { |
18 class Connection; | 18 class Connection; |
19 } | 19 } |
20 | 20 |
21 namespace precache { | 21 namespace precache { |
22 | 22 |
| 23 // Information about a given URL with respect to the PrecacheURLTable. |
| 24 struct PrecacheURLInfo { |
| 25 // The url has been prefetched in the past 60 days. (This number comes from |
| 26 // kPrecacheHistoryExpiryPeriodDays in precache_database.cc.) |
| 27 bool was_precached; |
| 28 |
| 29 // True if the cache entry is the one fetched by PrecacheFetcher. False if a |
| 30 // new network fetch overwrote the cache entry since the prefetch. |
| 31 bool is_precached; |
| 32 |
| 33 // The prefetched copy of the URL was used in browsing (i.e. while |
| 34 // is_precached was true). |
| 35 bool was_used; |
| 36 |
| 37 bool operator==(const PrecacheURLInfo& other) const; |
| 38 }; |
| 39 |
23 // Interface for database table that keeps track of the URLs that have been | 40 // Interface for database table that keeps track of the URLs that have been |
24 // precached but not used. This table is used to count how many bytes were saved | 41 // precached but not used. This table is used to count how many bytes were saved |
25 // by precached resources. | 42 // by precached resources. |
26 // Each row in this table represents a URL that was precached over the network, | 43 // Each row in this table represents a URL that was precached over the network, |
27 // and has not been fetched through user browsing since then. | 44 // and has not been fetched through user browsing since then. |
28 // Manages one table { URL (primary key), precache timestamp }. | 45 // Manages one table { URL (primary key), precache timestamp }. |
29 class PrecacheURLTable { | 46 class PrecacheURLTable { |
30 public: | 47 public: |
31 PrecacheURLTable(); | 48 PrecacheURLTable(); |
32 ~PrecacheURLTable(); | 49 ~PrecacheURLTable(); |
33 | 50 |
34 // Initialize the precache URL table for use with the specified database | 51 // Initialize the precache URL table for use with the specified database |
35 // connection. The caller keeps ownership of |db|, and |db| must not be NULL. | 52 // connection. The caller keeps ownership of |db|, and |db| must not be NULL. |
36 // Init must be called before any other methods. | 53 // Init must be called before any other methods. |
37 bool Init(sql::Connection* db); | 54 bool Init(sql::Connection* db); |
38 | 55 |
39 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host | 56 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host |
40 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is | 57 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is |
41 // precached, |time| is the timestamp. Replaces the row if one already exists. | 58 // precached, |time| is the timestamp. Replaces the row if one already exists. |
42 void AddURL(const GURL& url, | 59 void AddURL(const GURL& url, |
43 int64_t referrer_host_id, | 60 int64_t referrer_host_id, |
44 bool is_precached, | 61 bool is_precached, |
45 const base::Time& precache_time); | 62 const base::Time& precache_time); |
46 | 63 |
47 // Returns true if the url is precached. | 64 // Returns information about the URL's status with respect to prefetching. |
48 bool IsURLPrecached(const GURL& url); | 65 PrecacheURLInfo GetURLInfo(const GURL& url); |
49 | |
50 // Returns true if the url is precached, and was not used before. | |
51 bool IsURLPrecachedAndUnused(const GURL& url); | |
52 | 66 |
53 // Sets the precached URL as used. | 67 // Sets the precached URL as used. |
54 void SetPrecachedURLAsUsed(const GURL& url); | 68 void SetPrecachedURLAsUsed(const GURL& url); |
55 | 69 |
56 // Set the previously precached URL as not precached, during user browsing. | 70 // Set the previously precached URL as not precached, during user browsing. |
57 void SetURLAsNotPrecached(const GURL& url); | 71 void SetURLAsNotPrecached(const GURL& url); |
58 | 72 |
59 // Populates the used and unused resource URLs for the referrer host with id | 73 // Populates the used and unused resource URLs for the referrer host with id |
60 // |referrer_host_id|. | 74 // |referrer_host_id|. |
61 void GetURLListForReferrerHost(int64_t referrer_host_id, | 75 void GetURLListForReferrerHost(int64_t referrer_host_id, |
(...skipping 17 matching lines...) Expand all Loading... |
79 | 93 |
80 // Non-owned pointer. | 94 // Non-owned pointer. |
81 sql::Connection* db_; | 95 sql::Connection* db_; |
82 | 96 |
83 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); | 97 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); |
84 }; | 98 }; |
85 | 99 |
86 } // namespace precache | 100 } // namespace precache |
87 | 101 |
88 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ | 102 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ |
OLD | NEW |