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